@@ -4,349 +4,33 @@ project (liblsl
44 LANGUAGES C CXX
55 DESCRIPTION "Labstreaminglayer C/C++ library"
66 HOMEPAGE_URL "https://github.com/sccn/liblsl"
7- )
7+ )
88
99# API version, to be incremented on backwards-incompatible ABI changes
1010set (LSL_ABI_VERSION 2)
1111
12- set (CMAKE_CXX_VISIBILITY_PRESET hidden)
13- set (CMAKE_VISIBILITY_INLINES_HIDDEN ON )
14- set (CMAKE_CXX_STANDARD 17)
15- # generate a compilation database (compile_commands.json) for clang tooling
16- set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
17-
18- option (LSL_DEBUGLOG "Enable (lots of) additional debug messages" OFF )
19- option (LSL_UNIXFOLDERS "Use the unix folder layout for install targets" On )
20- option (LSL_FORCE_FANCY_LIBNAME "Add library name decorations (32/64/-debug)" OFF )
21- option (LSL_BUILD_EXAMPLES "Build example programs in examples/" OFF )
22- option (LSL_BUILD_STATIC "Build LSL as static library." OFF )
23- option (LSL_LEGACY_CPP_ABI "Build legacy C++ ABI into lsl-static" OFF )
24- option (LSL_OPTIMIZATIONS "Enable some more compiler optimizations" ON )
25- option (LSL_UNITTESTS "Build LSL library unit tests" OFF )
26- option (LSL_BUNDLED_BOOST "Use the bundled Boost by default" ON )
27- option (LSL_BUNDLED_PUGIXML "Use the bundled pugixml by default" ON )
28- option (LSL_TOOLS "Build some experimental tools for in-depth tests" OFF )
29-
30- mark_as_advanced (LSL_FORCE_FANCY_LIBNAME)
31-
32- set (LSL_WINVER "0x0601" CACHE STRING
33- "Windows version (_WIN32_WINNT) to target (defaults to 0x0601 for Windows 7)" )
34-
35- if (LSL_BUILD_STATIC)
36- set (LSL_LIB_TYPE STATIC )
37- else ()
38- set (LSL_LIB_TYPE SHARED)
39- # shared libraries require relocatable symbols so we enable them by default
40- set (CMAKE_POSITION_INDEPENDENT_CODE ON )
41- endif ()
42-
43- # Add an object library so all files are only compiled once
44- add_library (lslobj OBJECT
45- src/api_config.cpp
46- src/api_config.h
47- src/api_types.hpp
48- src/cancellable_streambuf.h
49- src/cancellation.h
50- src/cancellation.cpp
51- src/common.cpp
52- src/common.h
53- src/consumer_queue.cpp
54- src/consumer_queue.h
55- src/data_receiver.cpp
56- src/data_receiver.h
57- src/forward.h
58- src/info_receiver.cpp
59- src/info_receiver.h
60- src/inlet_connection.cpp
61- src/inlet_connection.h
62- src/lsl_resolver_c.cpp
63- src/lsl_inlet_c.cpp
64- src/lsl_outlet_c.cpp
65- src/lsl_streaminfo_c.cpp
66- src/lsl_xml_element_c.cpp
67- src/netinterfaces.h
68- src/netinterfaces.cpp
69- src/portable_archive/portable_archive_exception.hpp
70- src/portable_archive/portable_archive_includes.hpp
71- src/portable_archive/portable_iarchive.hpp
72- src/portable_archive/portable_oarchive.hpp
73- src/resolver_impl.cpp
74- src/resolver_impl.h
75- src/resolve_attempt_udp.cpp
76- src/resolve_attempt_udp.h
77- src/sample.cpp
78- src/sample.h
79- src/send_buffer.cpp
80- src/send_buffer.h
81- src/socket_utils.cpp
82- src/socket_utils.h
83- src/stream_info_impl.cpp
84- src/stream_info_impl.h
85- src/stream_inlet_impl.h
86- src/stream_outlet_impl.cpp
87- src/stream_outlet_impl.h
88- src/tcp_server.cpp
89- src/tcp_server.h
90- src/time_postprocessor.cpp
91- src/time_postprocessor.h
92- src/time_receiver.cpp
93- src/time_receiver.h
94- src/udp_server.cpp
95- src/udp_server.h
96- src/util/cast.hpp
97- src/util/cast.cpp
98- src/util/endian.cpp
99- src/util/endian.hpp
100- src/util/inireader.hpp
101- src/util/inireader.cpp
102- src/util/strfuns.hpp
103- src/util/strfuns.cpp
104- src/util/uuid.hpp
105- thirdparty/loguru/loguru.cpp
106- $<$<BOOL :${LSL_LEGACY_CPP_ABI} >:src/legacy/legacy_abi.cpp src/legacy/legacy_abi.h>
107- # headers
108- include /lsl_c.h
109- include /lsl_cpp.h
110- include /lsl/common.h
111- include /lsl/inlet.h
112- include /lsl/outlet.h
113- include /lsl/resolver.h
114- include /lsl/streaminfo.h
115- include /lsl/types.h
116- include /lsl/xml.h
117- )
118-
119- if (LSL_BUNDLED_PUGIXML)
120- message (STATUS "Using bundled pugixml" )
121- target_sources (lslobj PRIVATE thirdparty/pugixml/pugixml.cpp)
122- target_include_directories (lslobj SYSTEM PUBLIC
123- $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /thirdparty/pugixml>)
124- else ()
125- message (STATUS "Using system pugixml" )
126- find_package (pugixml REQUIRED)
127- if (NOT TARGET pugixml::pugixml)
128- add_library (pugixml::pugixml ALIAS pugixml)
129- endif ()
130- target_link_libraries (lslobj PUBLIC pugixml::pugixml)
131- endif ()
132-
133- # try to find out which revision is currently checked out
134- find_package (Git)
135- if (lslgitrevision AND lslgitbranch)
136- message (STATUS "Got git information ${lslgitrevision} /${lslgitbranch} from the command line" )
137- elseif (GIT_FOUND)
138- execute_process (
139- COMMAND ${GIT_EXECUTABLE} describe --tags HEAD
140- WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR} "
141- OUTPUT_VARIABLE lslgitrevision
142- OUTPUT_STRIP_TRAILING_WHITESPACE
143- )
144- execute_process (
145- COMMAND ${GIT_EXECUTABLE} rev-parse --symbolic -full-name --abbrev-ref @
146- WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR} "
147- OUTPUT_VARIABLE lslgitbranch
148- OUTPUT_STRIP_TRAILING_WHITESPACE
149- )
150- message (STATUS "Git version information: ${lslgitbranch} /${lslgitrevision} " )
151- else ()
152- set (lslgitrevision "unknown" )
153- set (lslgitbranch "unknown" )
154- endif ()
155-
156- # generate a version information string that can be retrieved with the exported
157- # lsl_library_info() function
158- set (LSL_VERSION_INFO "git:${lslgitrevision} /branch:${lslgitbranch} /build:${CMAKE_BUILD_TYPE} /compiler:${CMAKE_CXX_COMPILER_ID} -${CMAKE_CXX_COMPILER_VERSION} " )
159- set_source_files_properties ("src/buildinfo.cpp"
160- PROPERTIES COMPILE_DEFINITIONS
161- LSL_LIBRARY_INFO_STR="${LSL_VERSION_INFO} /link:${LSL_LIB_TYPE} "
162- )
163- set_source_files_properties ("thirdparty/loguru/loguru.cpp"
164- PROPERTIES COMPILE_DEFINITIONS LOGURU_STACKTRACES=$<BOOL :${LSL_DEBUGLOG} >)
165-
166- find_package (Threads REQUIRED)
167-
168- # create the lslboost target
169- add_library (lslboost INTERFACE )
170- if (LSL_BUNDLED_BOOST)
171- message (STATUS "Using bundled Boost" )
172- target_include_directories (lslboost SYSTEM INTERFACE
173- $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /lslboost>)
174- else ()
175- message (STATUS "Using system Boost" )
176- find_package (Boost REQUIRED)
177- target_compile_definitions (lslboost
178- INTERFACE
179- lslboost=boost # allows the LSL code base to work with the original Boost namespace/headers
180- )
181- target_link_libraries (lslboost INTERFACE Boost::boost Boost::disable_autolinking)
182- endif ()
183-
184- target_compile_definitions (lslboost INTERFACE BOOST_ALL_NO_LIB)
185-
186- # target configuration for the internal lslobj target
187- target_link_libraries (lslobj PRIVATE lslboost Threads::Threads)
188- target_compile_features (lslobj PUBLIC cxx_std_17)
189- target_include_directories (lslobj
190- PUBLIC
191- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} /include >
192- $<INSTALL_INTERFACE:include >
193- INTERFACE # for unit tests
194- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} /src>
195- )
196- target_include_directories (lslobj
197- SYSTEM PUBLIC
198- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} /thirdparty/loguru>
199- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} /thirdparty/asio>
200- )
201- target_compile_definitions (lslobj PRIVATE
202- LIBLSL_EXPORTS
203- LOGURU_DEBUG_LOGGING=$<BOOL :${LSL_DEBUGLOG} >
204- PUBLIC ASIO_NO_DEPRECATED
205- )
206- if (MINGW)
207- target_link_libraries (lslobj PRIVATE bcrypt)
208- endif ()
209-
210- # platform specific configuration
211- if (UNIX AND NOT APPLE )
212- include (CheckSymbolExists)
213- # check that clock_gettime is present in the stdlib, link against librt otherwise
214- check_symbol_exists(clock_gettime time.h HAS_GETTIME)
215- if (NOT HAS_GETTIME)
216- target_link_libraries (lslobj PRIVATE rt)
217- endif ()
218- if (LSL_DEBUGLOG)
219- target_link_libraries (lslobj PRIVATE dl)
220- endif ()
221- elseif (WIN32 )
222- target_link_libraries (lslobj PRIVATE iphlpapi winmm mswsock ws2_32)
223- target_compile_definitions (lslobj
224- PRIVATE _CRT_SECURE_NO_WARNINGS
225- PUBLIC LSLNOAUTOLINK # don't use #pragma(lib) in CMake builds
226- _WIN32_WINNT=${LSL_WINVER}
227- )
228- endif ()
229-
230- # the "real" liblsl library. It contains one source with the version info
231- # string because some generators require it. The remaining source code is
232- # built in the lslobj target and later linked into this library
233- add_library (lsl ${LSL_LIB_TYPE} src/buildinfo.cpp)
234-
235- # defines for LSL_CPP_API export header (shared: dllimport/dllexport)
236- target_compile_definitions (lsl PUBLIC
237- $<IF:$<BOOL :${LSL_BUILD_STATIC} >,LIBLSL_STATIC,LIBLSL_EXPORTS>
238- $<$<CXX_COMPILER_ID:MSVC >:LSLNOAUTOLINK> # don't use #pragma(lib) in CMake builds
239- )
240- target_link_libraries (lsl PRIVATE lslobj lslboost)
241- target_include_directories (lsl INTERFACE
242- $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include >
243- $<INSTALL_INTERFACE:include >
244- )
245- set_target_properties (lsl PROPERTIES
246- VERSION ${liblsl_VERSION_MAJOR} .${liblsl_VERSION_MINOR} .${liblsl_VERSION_PATCH}
247- SOVERSION ${LSL_ABI_VERSION}
248- )
249-
250- # enable some additional expensive compiler optimizations
251- if (LSL_OPTIMIZATIONS)
252- # enable LTO (https://en.wikipedia.org/wiki/Interprocedural_optimization
253- set (CMAKE_INTERPROCEDURAL_OPTIMIZATION ON )
254- else ()
255- # build one object file for Asio instead of once every time an Asio function is called. See
256- # https://think-async.com/Asio/asio-1.18.2/doc/asio/using.html#asio.using.optional_separate_compilation
257- target_sources (lslobj PRIVATE thirdparty/asio_objects.cpp)
258- target_compile_definitions (lslobj PUBLIC ASIO_SEPARATE_COMPILATION ASIO_DISABLE_VISIBILITY)
259- endif ()
260-
261-
262-
263- if (LSL_FORCE_FANCY_LIBNAME)
264- math (EXPR lslplatform "8 * ${CMAKE_SIZEOF_VOID_P} " )
265- set_target_properties (lsl PROPERTIES
266- PREFIX ""
267- OUTPUT_NAME "liblsl${lslplatform} "
268- DEBUG_POSTFIX "-debug"
269- )
270- endif ()
271-
272- if (LSL_UNIXFOLDERS)
273- include (GNUInstallDirs)
274- else ()
275- set (CMAKE_INSTALL_BINDIR LSL)
276- set (CMAKE_INSTALL_LIBDIR LSL)
277- set (CMAKE_INSTALL_INCLUDEDIR LSL/include )
278- endif ()
279-
280- include (CMakePackageConfigHelpers)
281- write_basic_package_version_file(
282- "${CMAKE_CURRENT_BINARY_DIR} /LSLConfigVersion.cmake"
283- VERSION "${liblsl_VERSION_MAJOR} .${liblsl_VERSION_MINOR} .${liblsl_VERSION_PATCH} "
284- COMPATIBILITY AnyNewerVersion
285- )
286-
287- set (LSLTargets lsl)
288- if (LSL_BUILD_STATIC)
289- list (APPEND LSLTargets lslobj lslboost)
290- endif ()
291-
292- install (TARGETS ${LSLTargets}
293- EXPORT LSLTargets
294- COMPONENT liblsl
295- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
296- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
297- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
298- INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
299- )
300-
301- export (EXPORT LSLTargets
302- FILE "${CMAKE_CURRENT_BINARY_DIR} /LSLTargets.cmake"
303- NAMESPACE LSL::
304- )
305-
306- install (EXPORT LSLTargets
307- FILE LSLTargets.cmake
308- COMPONENT liblsl
309- NAMESPACE "LSL::"
310- DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/LSL
311- )
312- configure_file (cmake/LSLConfig.cmake "${CMAKE_CURRENT_BINARY_DIR} /LSLConfig.cmake" COPYONLY )
313- configure_file (cmake/LSLCMake.cmake "${CMAKE_CURRENT_BINARY_DIR} /LSLCMake.cmake" COPYONLY )
314-
315-
316- # install headers
317- install (DIRECTORY include /
318- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
319- COMPONENT liblsl
320- )
321-
322- install (FILES
323- cmake/LSLCMake.cmake
324- ${CMAKE_CURRENT_BINARY_DIR} /LSLConfig.cmake
325- ${CMAKE_CURRENT_BINARY_DIR} /LSLConfigVersion.cmake
326- COMPONENT liblsl
327- DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/LSL
328- )
329-
12+ # Include modular configuration files
13+ include (cmake/ProjectOptions.cmake) #
14+ include (cmake/CompilerSettings.cmake) #
15+ include (cmake/Dependencies.cmake) #
16+ include (cmake/SourceFiles.cmake) #
17+ include (cmake/TargetObjLib.cmake) #
18+ include (cmake/TargetLib.cmake) #
19+ include (cmake/Installation.cmake) #
33020include (cmake/LSLCMake.cmake)
21+ include (cmake/TargetOther.cmake)
33122
332- add_executable (lslver testing/lslver.c)
333- target_link_libraries (lslver PRIVATE lsl)
334- installLSLApp(lslver)
335-
336- if (NOT WIN32 AND LSL_TOOLS)
337- add_executable (blackhole testing/blackhole.cpp)
338- target_link_libraries (blackhole PRIVATE Threads::Threads)
339- target_include_directories (blackhole PRIVATE "thirdparty/asio/" )
340- installLSLApp(blackhole)
341- endif ()
342-
343- set (LSL_INSTALL_ROOT ${CMAKE_CURRENT_BINARY_DIR} )
34423if (LSL_UNITTESTS)
34524 add_subdirectory (testing)
34625endif ()
34726
34827if (LSL_BUILD_EXAMPLES)
28+ set (LSL_INSTALL_ROOT ${CMAKE_CURRENT_BINARY_DIR} )
34929 add_subdirectory (examples)
35030endif ()
35131
32+ # Config for packaging
33+ # TODO: Config for packaging for the library itself is likely to diverge from config for packing applications. e.g.,
34+ # -> Optionally install to system directories
35+ # -> Apple Framework -- different installer type; uses entitlements
35236LSLGenerateCPackConfig()
0 commit comments