@@ -10,8 +10,8 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden)
1010if (NOT MSVC_VERSION VERSION_LESS 1700)
1111 set (CMAKE_CXX_STANDARD 14)
1212endif ()
13+ # generate a compilation database (compile_commands.json) for clang tooling
1314set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
14- set (LSL_LIB_TYPE SHARED)
1515
1616option (LSL_DEBUGLOG "Enable (lots of) additional debug messages" OFF )
1717option (LSL_UNIXFOLDERS "Use the unix folder layout for install targets" On )
@@ -28,6 +28,8 @@ set(LSL_WINVER "0x0601" CACHE STRING
2828if (LSL_BUILD_STATIC)
2929 set (LSL_LIB_TYPE STATIC )
3030else ()
31+ set (LSL_LIB_TYPE SHARED)
32+ # shared libraries require relocatable symbols so we enable them by default
3133 set (CMAKE_POSITION_INDEPENDENT_CODE ON )
3234endif ()
3335
@@ -106,7 +108,7 @@ if(LSL_BUNDLED_PUGIXML)
106108 message (STATUS "Using bundled pugixml" )
107109 target_sources (lslobj PRIVATE thirdparty/pugixml/pugixml.cpp)
108110 target_include_directories (lslobj SYSTEM PUBLIC
109- $<BUILD_INTERFACE: $ {CMAKE_CURRENT_SOURCE_DIR} /thirdparty/pugixml> )
111+ ${CMAKE_CURRENT_SOURCE_DIR} /thirdparty/pugixml)
110112else ()
111113 message (STATUS "Using system pugixml" )
112114 find_package (pugixml REQUIRED)
@@ -138,34 +140,25 @@ else()
138140 set (lslgitrevision "unknown" )
139141 set (lslgitbranch "unknown" )
140142endif ()
143+
144+ # generate a version information string that can be retrieved with the exported
145+ # lsl_library_info() function
141146set (LSL_VERSION_INFO "git:${lslgitrevision} /branch:${lslgitbranch} /build:${CMAKE_BUILD_TYPE} /compiler:${CMAKE_CXX_COMPILER_ID} -${CMAKE_CXX_COMPILER_VERSION} " )
147+ set_source_files_properties ("src/buildinfo.cpp"
148+ PROPERTIES COMPILE_DEFINITIONS
149+ LSL_LIBRARY_INFO_STR="${LSL_VERSION_INFO} /link:${LSL_LIB_TYPE} "
150+ )
142151set_source_files_properties ("thirdparty/loguru/loguru.cpp"
143152 PROPERTIES COMPILE_DEFINITIONS LOGURU_STACKTRACES=$<BOOL :${LSL_DEBUGLOG} >)
144153
145- ## create the lslboost target
154+ find_package (Threads REQUIRED)
155+
156+ # create the lslboost target
146157add_library (lslboost OBJECT
147158 lslboost/asio_objects.cpp
148159 lslboost/serialization_objects.cpp
149160)
150-
151- if (UNIX )
152- include (CheckSymbolExists)
153- # look for clock_gettime, if not we need to link against librt
154- check_symbol_exists(clock_gettime time.h HAS_GETTIME)
155- if (NOT HAS_GETTIME)
156- set (NEEDS_LIBRT ON CACHE INTERNAL "Link to librt" )
157- endif ()
158- endif ()
159-
160- find_package (Threads REQUIRED)
161- target_link_libraries (lslboost
162- PUBLIC
163- Threads::Threads
164- PRIVATE
165- $<$<PLATFORM_ID:Windows>:bcrypt>
166- $<$<PLATFORM_ID:Windows>:mswsock>
167- $<$<PLATFORM_ID:Windows>:ws2_32>
168- )
161+ target_link_libraries (lslboost PUBLIC Threads::Threads)
169162target_compile_features (lslboost PUBLIC cxx_std_11 cxx_lambda_init_captures)
170163
171164target_compile_definitions (lslboost
@@ -174,50 +167,62 @@ target_compile_definitions(lslboost
174167 BOOST_ASIO_STANDALONE
175168 BOOST_ASIO_SEPARATE_COMPILATION
176169 BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS
177- $<$<PLATFORM_ID:Windows>:_WIN32_WINNT=${LSL_WINVER} >
178- PRIVATE
179- $<$<PLATFORM_ID:Windows>:BOOST_THREAD_BUILD_DLL>
180170)
181171target_include_directories (lslboost SYSTEM PUBLIC
182- $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /lslboost>)
183-
172+ ${CMAKE_CURRENT_SOURCE_DIR} /lslboost)
184173
185- target_link_libraries (lslobj
186- PRIVATE
187- lslboost
188- $<$<PLATFORM_ID:Windows>:iphlpapi>
189- $<$<PLATFORM_ID:Windows>:winmm>
190- PUBLIC
191- $<$<AND :$<BOOL :${LSL_DEBUGLOG} >,$<PLATFORM_ID:Linux>>:dl>
192- $<$<BOOL :${NEEDS_LIBRT} >:rt>
193- )
174+ # target configuration for the internal lslobj target
175+ target_link_libraries (lslobj PRIVATE lslboost)
194176target_include_directories (lslobj
195177 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} /include >
196178 )
197179target_include_directories (lslobj SYSTEM PUBLIC
198180 $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} /thirdparty/loguru>
199181)
200- target_compile_definitions (lslobj
201- PRIVATE LIBLSL_EXPORTS $<$<PLATFORM_ID:Windows>:_CRT_SECURE_NO_WARNINGS>
202- LOGURU_DEBUG_LOGGING=$<BOOL :${LSL_DEBUGLOG} >
203- INTERFACE LSLNOAUTOLINK # don't use #pragma(lib) in CMake builds
182+ target_compile_definitions (lslobj PRIVATE
183+ LIBLSL_EXPORTS
184+ LOGURU_DEBUG_LOGGING=$<BOOL :${LSL_DEBUGLOG} >
204185)
205186
187+ # platform specific configuration
188+ if (UNIX )
189+ include (CheckSymbolExists)
190+ # check that clock_gettime is present in the stdlib, link against librt otherwise
191+ check_symbol_exists(clock_gettime time.h HAS_GETTIME)
192+ if (NOT HAS_GETTIME)
193+ target_link_libraries (lslobj PRIVATE rt)
194+ endif ()
195+ if (LSL_DEBUGLOG AND NOT APPLE )
196+ target_link_libraries (lslobj PRIVATE dl)
197+ endif ()
198+ elseif (WIN32 )
199+ target_link_libraries (lslobj PRIVATE iphlpapi winmm)
200+ target_link_libraries (lslboost PRIVATE bcrypt mswsock ws2_32)
201+ target_compile_definitions (lslobj
202+ PRIVATE _CRT_SECURE_NO_WARNINGS
203+ PUBLIC LSLNOAUTOLINK # don't use #pragma(lib) in CMake builds
204+ )
205+ target_compile_definitions (lslboost
206+ PUBLIC _WIN32_WINNT=${LSL_WINVER}
207+ PRIVATE BOOST_THREAD_BUILD_DLL
208+ )
209+ endif ()
210+
211+ # the "real" liblsl library. It contains one source with the version info
212+ # string because some generators require it. The remaining source code is
213+ # built in the lslobj target and later linked into this library
206214add_library (lsl ${LSL_LIB_TYPE} src/buildinfo.cpp)
207215
208216# defines for LSL_CPP_API export header (shared: dllimport/dllexport)
209217target_compile_definitions (lsl PUBLIC
210218 $<IF:$<BOOL :${LSL_BUILD_STATIC} >,LIBLSL_STATIC,LIBLSL_EXPORTS>
219+ $<$<CXX_COMPILER_ID:MSVC >:LSLNOAUTOLINK> # don't use #pragma(lib) in CMake builds
211220)
212-
213- set_source_files_properties ( "src/buildinfo.cpp"
214- PROPERTIES COMPILE_DEFINITIONS
215- LSL_LIBRARY_INFO_STR= " ${LSL_VERSION_INFO} /link: ${LSL_LIB_TYPE} "
221+ target_link_libraries (lsl PRIVATE lslobj lslboost)
222+ target_include_directories (lsl INTERFACE
223+ $<BUILD_INTERFACE: ${CMAKE_CURRENT_SOURCE_DIR} / include >
224+ $<INSTALL_INTERFACE: include >
216225)
217-
218- target_link_libraries (lsl
219- PUBLIC lslobj
220- PRIVATE lslboost)
221226set_target_properties (lsl PROPERTIES
222227 VERSION ${liblsl_VERSION_MAJOR} .${liblsl_VERSION_MINOR} .${liblsl_VERSION_PATCH}
223228)
@@ -246,7 +251,7 @@ write_basic_package_version_file(
246251 COMPATIBILITY AnyNewerVersion
247252)
248253
249- install (TARGETS lsl lslobj lslboost
254+ install (TARGETS lsl
250255 EXPORT LSLTargets
251256 COMPONENT liblsl
252257 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
0 commit comments