Skip to content

Commit a1719cc

Browse files
committed
Add option for building shared libraries
1 parent 713de5b commit a1719cc

File tree

4 files changed

+56
-13
lines changed

4 files changed

+56
-13
lines changed

CMakeLists.txt

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ cmake_minimum_required(VERSION 2.8.11)
33
project(pqp)
44

55
include(CMakePackageConfigHelpers)
6+
include(GenerateExportHeader)
67
include(GNUInstallDirs)
78

89
set(VERSION_MAJOR 1)
910
set(VERSION_MINOR 3)
1011
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR})
1112

13+
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
14+
1215
set(
1316
HDRS
1417
src/BV.h
@@ -26,23 +29,42 @@ set(
2629
src/TriDist.cpp
2730
)
2831

29-
add_library(PQP STATIC ${HDRS} ${SRCS})
32+
add_library(PQP ${HDRS} ${SRCS})
3033

3134
target_include_directories(
3235
PQP
33-
INTERFACE
36+
PUBLIC
37+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
3438
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
3539
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>
3640
)
3741

3842
set_target_properties(
3943
PQP
4044
PROPERTIES
41-
DEBUG_POSTFIX d
4245
POSITION_INDEPENDENT_CODE ON
4346
VERSION ${VERSION}
4447
)
4548

49+
if(MSVC)
50+
if(BUILD_SHARED_LIBS)
51+
set_target_properties(
52+
PQP
53+
PROPERTIES
54+
DEBUG_POSTFIX d
55+
)
56+
else()
57+
set_target_properties(
58+
PQP
59+
PROPERTIES
60+
DEBUG_POSTFIX sd
61+
MINSIZEREL_POSTFIX s
62+
RELEASE_POSTFIX s
63+
RELWITHDEBINFO_POSTFIX s
64+
)
65+
endif()
66+
endif()
67+
4668
install(FILES ${HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT development)
4769

4870
install(
@@ -53,6 +75,22 @@ install(
5375
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime
5476
)
5577

78+
if(BUILD_SHARED_LIBS)
79+
install(
80+
TARGETS PQP
81+
EXPORT PQP
82+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT development NAMELINK_ONLY
83+
)
84+
endif()
85+
86+
if(MSVC AND BUILD_SHARED_LIBS AND ${CMAKE_MAJOR_VERSION} GREATER 2 AND ${CMAKE_MINOR_VERSION} GREATER 0)
87+
install(FILES $<TARGET_PDB_FILE:PQP> DESTINATION ${CMAKE_INSTALL_BINDIR} CONFIGURATIONS Debug RelWithDebInfo COMPONENT debug)
88+
endif()
89+
90+
generate_export_header(PQP EXPORT_FILE_NAME PQP_Export.h)
91+
92+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/PQP_Export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT development)
93+
5694
option(BUILD_SAMPLES "Build samples" OFF)
5795

5896
if(BUILD_SAMPLES)

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CC = g++
22

3-
CFLAGS = -O2 -I.
3+
CFLAGS = -O2 -I. -Iinclude
44

55
.SUFFIXES: .C .cpp
66

@@ -20,11 +20,14 @@ library: $(OBJECTS)
2020
cp src/BV.h include/
2121
cp src/Tri.h include/
2222

23+
include/PQP_Export.h:
24+
echo "#ifndef PQP_EXPORT_H\n#define PQP_EXPORT_H\n\n#define PQP_EXPORT\n\n#endif" > include/PQP_Export.h
25+
2326
lib/BV.o: src/BV.cpp
2427
$(CC) $(CFLAGS) -c src/BV.cpp -o lib/BV.o
25-
lib/PQP.o: src/PQP.cpp
28+
lib/PQP.o: src/PQP.cpp include/PQP_Export.h
2629
$(CC) $(CFLAGS) -c src/PQP.cpp -o lib/PQP.o
27-
lib/Build.o: src/Build.cpp
30+
lib/Build.o: src/Build.cpp include/PQP_Export.h
2831
$(CC) $(CFLAGS) -c src/Build.cpp -o lib/Build.o
2932
lib/TriDist.o: src/TriDist.cpp
3033
$(CC) $(CFLAGS) -c src/TriDist.cpp -o lib/TriDist.o

src/PQP.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
#include "PQP_Compile.h"
4545
#include "PQP_Internal.h"
46+
#include "PQP_Export.h"
4647

4748
//----------------------------------------------------------------------------
4849
//
@@ -203,7 +204,7 @@ const int PQP_ERR_BUILD_EMPTY_MODEL = -5;
203204
const int PQP_ALL_CONTACTS = 1; // find all pairwise intersecting triangles
204205
const int PQP_FIRST_CONTACT = 2; // report first intersecting tri pair found
205206

206-
int
207+
PQP_EXPORT int
207208
PQP_Collide(PQP_CollideResult *result,
208209
PQP_REAL R1[3][3], PQP_REAL T1[3], PQP_Model *o1,
209210
PQP_REAL R2[3][3], PQP_REAL T2[3], PQP_Model *o2,
@@ -264,7 +265,7 @@ PQP_Collide(PQP_CollideResult *result,
264265
//
265266
//----------------------------------------------------------------------------
266267

267-
int
268+
PQP_EXPORT int
268269
PQP_Distance(PQP_DistanceResult *result,
269270
PQP_REAL R1[3][3], PQP_REAL T1[3], PQP_Model *o1,
270271
PQP_REAL R2[3][3], PQP_REAL T2[3], PQP_Model *o2,
@@ -321,7 +322,7 @@ PQP_Distance(PQP_DistanceResult *result,
321322
//
322323
//----------------------------------------------------------------------------
323324

324-
int
325+
PQP_EXPORT int
325326
PQP_Tolerance(PQP_ToleranceResult *res,
326327
PQP_REAL R1[3][3], PQP_REAL T1[3], PQP_Model *o1,
327328
PQP_REAL R2[3][3], PQP_REAL T2[3], PQP_Model *o2,

src/PQP_Internal.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@
4040

4141
#include "Tri.h"
4242
#include "BV.h"
43+
#include "PQP_Export.h"
4344

44-
class PQP_Model
45+
class PQP_EXPORT PQP_Model
4546
{
4647

4748
public:
@@ -79,7 +80,7 @@ struct CollisionPair
7980
int id2;
8081
};
8182

82-
struct PQP_CollideResult
83+
struct PQP_EXPORT PQP_CollideResult
8384
{
8485
// stats
8586

@@ -123,7 +124,7 @@ struct PQP_CollideResult
123124

124125
#if PQP_BV_TYPE & RSS_TYPE // distance/tolerance are only available with RSS
125126

126-
struct PQP_DistanceResult
127+
struct PQP_EXPORT PQP_DistanceResult
127128
{
128129
// stats
129130

@@ -160,7 +161,7 @@ struct PQP_DistanceResult
160161
const PQP_REAL *P2() { return p2; }
161162
};
162163

163-
struct PQP_ToleranceResult
164+
struct PQP_EXPORT PQP_ToleranceResult
164165
{
165166
// stats
166167

0 commit comments

Comments
 (0)