Skip to content

Commit f3ab7c8

Browse files
Static link library build and linkage (#268)
* Ignore CMakeSettings.json * Static build CMake configuration * Source file variable name change * Header-only version of spdlog (Resolved linker issues, WIN32) * RGL_VISIBLE disabled for static * Corrected spdlog variant --------- Co-authored-by: Piotr Rybicki <[email protected]>
1 parent 990a09d commit f3ab7c8

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ cmake-build-release
4141
build
4242
external/*
4343
!external/CMakeLists.txt
44-
!external/CMakeLists.txt
4544
extensions/udp
4645
extensions/snow
46+
CMakeSettings.json

CMakeLists.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ set(RGL_LOG_FILE "" CACHE STRING # STRING prevents from expanding relative path
2626
set(RGL_AUTO_TAPE_PATH "" CACHE STRING # STRING prevents from expanding relative paths
2727
"If non-empty, defines a path for the automatic tape (started on the first API call)")
2828

29+
# Library configuration
30+
set(RGL_BUILD_STATIC OFF CACHE BOOL
31+
"Builds RobotecGPULidar as a statically linkable library instead of a shared one")
32+
2933
# Test configuration
3034
set(RGL_BUILD_TESTS ON CACHE BOOL
3135
"Enables building test. GTest will be automatically downloaded")
@@ -89,7 +93,7 @@ add_custom_command(
8993
VERBATIM)
9094
add_library(optixPrograms optixProgramsPtx.c)
9195

92-
add_library(RobotecGPULidar SHARED
96+
set(RGL_SOURCE_FILES
9397
src/api/apiCommon.cpp
9498
src/api/apiCore.cpp
9599
src/tape/TapePlayer.cpp
@@ -127,6 +131,15 @@ add_library(RobotecGPULidar SHARED
127131
src/graph/YieldPointsNode.cpp
128132
)
129133

134+
if (RGL_BUILD_STATIC)
135+
add_library(RobotecGPULidar STATIC ${RGL_SOURCE_FILES})
136+
target_compile_definitions(RobotecGPULidar PUBLIC RGL_STATIC)
137+
set(RGL_SPDLOG_VARIANT spdlog_header_only)
138+
else ()
139+
add_library(RobotecGPULidar SHARED ${RGL_SOURCE_FILES})
140+
set(RGL_SPDLOG_VARIANT spdlog)
141+
endif ()
142+
130143
set_property(TARGET RobotecGPULidar PROPERTY POSITION_INDEPENDENT_CODE ON)
131144

132145
target_compile_definitions(RobotecGPULidar PUBLIC RGL_BUILD_PCL_EXTENSION=$<BOOL:${RGL_BUILD_PCL_EXTENSION}>)
@@ -156,7 +169,7 @@ target_include_directories(RobotecGPULidar
156169
)
157170

158171
target_link_libraries(RobotecGPULidar PRIVATE
159-
spdlog
172+
${RGL_SPDLOG_VARIANT}
160173
yaml-cpp
161174
optixPrograms
162175
cmake_git_version_tracking

include/rgl/api/core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#define NO_MANGLING
2929
#endif
3030

31+
#if defined RGL_STATIC
32+
#define RGL_VISIBLE
33+
#else
3134
#if defined _WIN32 || defined __CYGWIN__
3235
#ifdef __GNUC__
3336
#define RGL_VISIBLE __attribute__((dllexport))
@@ -42,6 +45,7 @@
4245
#define RGL_VISIBLE
4346
#endif
4447
#endif // _WIN32 || __CYGWIN__
48+
#endif // RGL_STATIC
4549

4650
#define RGL_API NO_MANGLING RGL_VISIBLE
4751

0 commit comments

Comments
 (0)