@@ -20,6 +20,7 @@ option(LSL_FORCE_FANCY_LIBNAME "Add library name decorations (32/64/-debug)" OFF
2020option (LSL_BUILD_EXAMPLES "Build example programs in examples/" OFF )
2121option (LSL_BUILD_STATIC "Build LSL as static library." OFF )
2222option (LSL_LEGACY_CPP_ABI "Build legacy C++ ABI into lsl-static" OFF )
23+ option (LSL_OPTIMIZATIONS "Enable some more compiler optimizations" ON )
2324option (LSL_UNITTESTS "Build LSL library unit tests" OFF )
2425option (LSL_BUNDLED_PUGIXML "Use the bundled pugixml by default" ON )
2526
@@ -156,7 +157,6 @@ find_package(Threads REQUIRED)
156157
157158# create the lslboost target
158159add_library (lslboost OBJECT
159- lslboost/asio_objects.cpp
160160 lslboost/serialization_objects.cpp
161161)
162162target_link_libraries (lslboost PUBLIC Threads::Threads)
@@ -166,7 +166,6 @@ target_compile_definitions(lslboost
166166 PUBLIC
167167 BOOST_ALL_NO_LIB
168168 BOOST_ASIO_STANDALONE
169- BOOST_ASIO_SEPARATE_COMPILATION
170169 BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS
171170)
172171target_include_directories (lslboost SYSTEM PUBLIC
@@ -228,6 +227,19 @@ set_target_properties(lsl PROPERTIES
228227 VERSION ${liblsl_VERSION_MAJOR} .${liblsl_VERSION_MINOR} .${liblsl_VERSION_PATCH}
229228)
230229
230+ # enable some additional expensive compiler optimizations
231+ if (LSL_OPTIMIZATIONS)
232+ # enable LTO (https://en.wikipedia.org/wiki/Interprocedural_optimization
233+ set (CMAKE_INTERPROCEDURAL_OPTIMIZATION ON )
234+ else ()
235+ # build one object file for Asio instead of once every time an Asio function is called. See
236+ # https://think-async.com/Asio/asio-1.18.2/doc/asio/using.html#asio.using.optional_separate_compilation
237+ target_sources (lslboost PRIVATE lslboost/asio_objects.cpp)
238+ target_compile_definitions (lslboost PUBLIC BOOST_ASIO_SEPARATE_COMPILATION)
239+ endif ()
240+
241+
242+
231243if (LSL_FORCE_FANCY_LIBNAME)
232244 math (EXPR lslplatform "8 * ${CMAKE_SIZEOF_VOID_P} " )
233245 set_target_properties (lsl PROPERTIES
0 commit comments