Skip to content

Commit 3773381

Browse files
committed
CMake: add LSL_OPTIMIZATIONS option; enables LTO & disables pre-building all of Asio
1 parent 2a2daef commit 3773381

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ option(LSL_FORCE_FANCY_LIBNAME "Add library name decorations (32/64/-debug)" OFF
2020
option(LSL_BUILD_EXAMPLES "Build example programs in examples/" OFF)
2121
option(LSL_BUILD_STATIC "Build LSL as static library." OFF)
2222
option(LSL_LEGACY_CPP_ABI "Build legacy C++ ABI into lsl-static" OFF)
23+
option(LSL_OPTIMIZATIONS "Enable some more compiler optimizations" ON)
2324
option(LSL_UNITTESTS "Build LSL library unit tests" OFF)
2425
option(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
158159
add_library(lslboost OBJECT
159-
lslboost/asio_objects.cpp
160160
lslboost/serialization_objects.cpp
161161
)
162162
target_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
)
172171
target_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+
231243
if(LSL_FORCE_FANCY_LIBNAME)
232244
math(EXPR lslplatform "8 * ${CMAKE_SIZEOF_VOID_P}")
233245
set_target_properties(lsl PROPERTIES

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.5)
1+
cmake_minimum_required(VERSION 3.12)
22
project(lslexamples
33
LANGUAGES C CXX
44
VERSION 0.2.0)

0 commit comments

Comments
 (0)