Skip to content

Commit ec436eb

Browse files
committed
Keep original order of cmake invocations as much as possible
1 parent 5b6bcc9 commit ec436eb

File tree

4 files changed

+62
-61
lines changed

4 files changed

+62
-61
lines changed

cmake/CompilerSettings.cmake

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
55
# generate a compilation database (compile_commands.json) for clang tooling
66
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
77

8-
# Enable position independent code for shared libraries
9-
if(NOT LSL_BUILD_STATIC OR UNIX)
10-
# shared libraries require relocatable symbols so we enable them by default
11-
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
12-
endif()
8+
set(LSL_WINVER "0x0601" CACHE STRING
9+
"Windows version (_WIN32_WINNT) to target (defaults to 0x0601 for Windows 7)")
1310

1411
# Determine library type
1512
if(LSL_BUILD_STATIC)
@@ -18,6 +15,12 @@ else()
1815
set(LSL_LIB_TYPE SHARED)
1916
endif()
2017

18+
# Enable position independent code for shared libraries
19+
if(NOT LSL_BUILD_STATIC OR UNIX)
20+
# shared libraries require relocatable symbols so we enable them by default
21+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
22+
endif()
23+
2124
# Enable optimizations if requested
2225
if(LSL_OPTIMIZATIONS)
2326
# enable LTO (https://en.wikipedia.org/wiki/Interprocedural_optimization
@@ -27,9 +30,6 @@ endif()
2730
# Platform-specific settings
2831
if(WIN32)
2932
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
30-
31-
set(LSL_WINVER "0x0601" CACHE STRING
32-
"Windows version (_WIN32_WINNT) to target (defaults to 0x0601 for Windows 7)")
3333
elseif(APPLE)
3434
set(CMAKE_MACOSX_RPATH ON)
3535
endif()

cmake/SourceFiles.cmake

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,4 @@ set(lslheaders
7272
include/lsl/streaminfo.h
7373
include/lsl/types.h
7474
include/lsl/xml.h
75-
)
76-
# LSL_LIB_TYPE set by ProjectOptions.cmake
77-
# LSL_VERSION_INFO set by GitVersion.cmake < Dependencies.cmake
78-
# These are used to set the version information in the buildinfo.cpp file
79-
set_source_files_properties("src/buildinfo.cpp"
80-
PROPERTIES COMPILE_DEFINITIONS
81-
LSL_LIBRARY_INFO_STR="${LSL_VERSION_INFO}/link:${LSL_LIB_TYPE}"
82-
)
75+
)

cmake/TargetLib.cmake

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Create main library
22
# It contains one source with the version info string because some generators require it.
33
# The remaining source code is built in the lslobj target and later linked into this library.
4+
set_source_files_properties("src/buildinfo.cpp"
5+
PROPERTIES COMPILE_DEFINITIONS
6+
LSL_LIBRARY_INFO_STR="${LSL_VERSION_INFO}/link:${LSL_LIB_TYPE}"
7+
)
48
add_library(lsl ${LSL_LIB_TYPE} src/buildinfo.cpp)
59

610
# Configure main library
@@ -12,8 +16,13 @@ target_compile_definitions(lsl
1216
$<IF:$<BOOL:${LSL_BUILD_STATIC}>,LIBLSL_STATIC,LIBLSL_EXPORTS>
1317
# don't use #pragma(lib) in MSVC builds. TODO: Maybe this can be inherited from lslobj or removed on lslobj?
1418
$<$<CXX_COMPILER_ID:MSVC>:LSLNOAUTOLINK>
15-
PRIVATE
16-
$<$<BOOL:${LSL_DEBUGLOG}>:DEBUGLOG>
19+
)
20+
21+
target_link_libraries(lsl
22+
PRIVATE
23+
lslobj # TODO: If this is public, does that improve inheritance of includes and compile definitions?
24+
lslboost # TODO: Shouldn't be needed -- lslobj already links it
25+
${PUGIXML_LIBRARIES}
1726
)
1827

1928
# Includes. TODO: Can we not inherit these from lslobj?
@@ -23,14 +32,6 @@ target_include_directories(lsl
2332
$<INSTALL_INTERFACE:include>
2433
)
2534

26-
# Link dependencies
27-
target_link_libraries(lsl
28-
PRIVATE
29-
lslobj # TODO: If this is public, does that improve inheritance of includes and compile definitions?
30-
lslboost # TODO: Shouldn't be needed -- lslobj already links it
31-
${PUGIXML_LIBRARIES}
32-
)
33-
3435
set_target_properties(lsl PROPERTIES
3536
VERSION ${liblsl_VERSION_MAJOR}.${liblsl_VERSION_MINOR}.${liblsl_VERSION_PATCH}
3637
SOVERSION ${LSL_ABI_VERSION}

cmake/TargetObjLib.cmake

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,9 @@ add_library(lslobj OBJECT
44
${lslheaders}
55
)
66

7-
target_compile_features(lslobj PUBLIC cxx_std_17) # Note: Redundant with project-wide setting in CompilerSettings.cmake
7+
target_link_libraries(lslobj PRIVATE lslboost Threads::Threads) # TODO: Seems out of order here
88

9-
target_compile_definitions(lslobj
10-
PRIVATE
11-
LIBLSL_EXPORTS
12-
LOGURU_DEBUG_LOGGING=$<BOOL:${LSL_DEBUGLOG}>
13-
PUBLIC
14-
ASIO_NO_DEPRECATED
15-
$<$<CXX_COMPILER_ID:MSVC>:LSLNOAUTOLINK> # don't use #pragma(lib) in CMake builds
16-
)
17-
if(WIN32)
18-
if(BUILD_SHARED_LIBS)
19-
set_target_properties(lslobj
20-
PROPERTIES
21-
WINDOWS_EXPORT_ALL_SYMBOLS ON
22-
)
23-
endif(BUILD_SHARED_LIBS)
24-
target_compile_definitions(lslobj
25-
PRIVATE
26-
_CRT_SECURE_NO_WARNINGS
27-
PUBLIC
28-
_WIN32_WINNT=${LSL_WINVER}
29-
)
30-
endif(WIN32)
9+
target_compile_features(lslobj PUBLIC cxx_std_17) # TODO: Redundant with project-wide setting in CompilerSettings.cmake
3110

3211
# Set the includes/headers for the lslobj target.
3312
# Note: We cannot use the PUBLIC_HEADER property of the target, because
@@ -44,14 +23,32 @@ endif(WIN32)
4423
# If we used the FILET_SET approach then we would remove the PUBLIC includes below.
4524
target_include_directories(lslobj
4625
PUBLIC
47-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
26+
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
4827
$<INSTALL_INTERFACE:include>
4928
INTERFACE
5029
# Propagate include directories to consumers
5130
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src> # for unit tests
5231
)
5332

54-
# Link in dependencies -- some of which are header-only libraries
33+
target_include_directories(lslobj
34+
SYSTEM PUBLIC
35+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/loguru>
36+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/asio>
37+
)
38+
39+
target_compile_definitions(lslobj
40+
PRIVATE
41+
LIBLSL_EXPORTS
42+
LOGURU_DEBUG_LOGGING=$<BOOL:${LSL_DEBUGLOG}>
43+
PUBLIC
44+
ASIO_NO_DEPRECATED
45+
$<$<CXX_COMPILER_ID:MSVC>:LSLNOAUTOLINK> # don't use #pragma(lib) in CMake builds
46+
)
47+
48+
if(MINGW)
49+
target_link_libraries(lslobj PRIVATE bcrypt)
50+
endif()
51+
5552
# - System libs
5653
if(UNIX AND NOT APPLE)
5754
# check that clock_gettime is present in the stdlib, link against librt otherwise
@@ -65,23 +62,33 @@ if(UNIX AND NOT APPLE)
6562
endif()
6663
elseif(WIN32)
6764
target_link_libraries(lslobj PRIVATE iphlpapi winmm mswsock ws2_32)
65+
target_compile_definitions(lslobj
66+
PRIVATE
67+
_CRT_SECURE_NO_WARNINGS
68+
PUBLIC
69+
_WIN32_WINNT=${LSL_WINVER}
70+
)
71+
if(BUILD_SHARED_LIBS)
72+
# set_target_properties(lslobj
73+
# PROPERTIES
74+
# WINDOWS_EXPORT_ALL_SYMBOLS ON
75+
# )
76+
endif(BUILD_SHARED_LIBS)
6877
endif()
69-
if(MINGW)
70-
target_link_libraries(lslobj PRIVATE bcrypt)
71-
endif()
72-
target_link_libraries(lslobj PRIVATE lslboost Threads::Threads)
78+
79+
# Link in dependencies -- some of which are header-only libraries
80+
7381
# - loguru and asio header-only
7482
if(NOT LSL_OPTIMIZATIONS)
7583
# build one object file for Asio instead of once every time an Asio function is called. See
7684
# https://think-async.com/Asio/asio-1.18.2/doc/asio/using.html#asio.using.optional_separate_compilation
7785
target_sources(lslobj PRIVATE thirdparty/asio_objects.cpp)
78-
target_compile_definitions(lslobj PUBLIC ASIO_SEPARATE_COMPILATION ASIO_DISABLE_VISIBILITY)
86+
target_compile_definitions(lslobj
87+
PUBLIC
88+
ASIO_SEPARATE_COMPILATION
89+
ASIO_DISABLE_VISIBILITY
90+
)
7991
endif()
80-
target_include_directories(lslobj
81-
SYSTEM PUBLIC
82-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/loguru>
83-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/asio>
84-
)
8592
# - pugixml
8693
if(LSL_BUNDLED_PUGIXML)
8794
target_sources(lslobj PRIVATE thirdparty/pugixml/pugixml.cpp)

0 commit comments

Comments
 (0)