Skip to content

Commit 7ed4124

Browse files
committed
[cmake] Fix handling of BUILD_SHARED_LIBS option
BUILD_SHARED_LIBS option is declared conditionally on whether BUILD_SHARED_LIBS is defined itself. This is problematic as multiple invocations of a build runner such as ninja will cause builds to use different options. The first build will run as if BUILD_SHARED_LIBS is not defined (i.e. OFF option), the second time cmake will notice that BUILD_SHARED_LIBS was defined after all and now run build with BUILD_SHARED_LIBS set to ON. This is confusing and error prone. To fix the problem, a top-level BUILD_SHARED_LIBS option has been added and BUILD_SHARED_LIBS option in applications subdirectory was changed to become active only if the project is standalone.
1 parent 5e5cc5b commit 7ed4124

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ option(CCTAG_ENABLE_SIMD_AVX2 "Enable AVX2 optimizations" OFF)
2828
option(CCTAG_BUILD_TESTS "Build the unity tests" ON)
2929
option(CCTAG_BUILD_DOC "Build documentation" OFF)
3030
option(CCTAG_NO_THRUST_COPY_IF "Do not use thrust::copy_if() on GPU. There may be a bug on CUDA 7 with GTX 980, 980Ti and 1080" OFF)
31+
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
3132

3233
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
3334

src/applications/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ if(NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
88

99
set(CMAKE_CXX_STANDARD 14)
1010
set(CMAKE_CXX_STANDARD_REQUIRED ON)
11-
endif()
1211

13-
# if this is used as a stand-alone project we need to tell whether to use PIC
14-
if(NOT DEFINED BUILD_SHARED_LIBS)
12+
# if this is used as a stand-alone project we need to tell whether to use PIC
1513
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
1614
set(CMAKE_POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS})
1715
endif()

0 commit comments

Comments
 (0)