Skip to content

Commit e8df200

Browse files
Merge pull request #635 from TimPushkin/fix-cached-cmake-vars
Set CMAKE_* cache variables only as a top-level project
2 parents aed5c08 + deaf362 commit e8df200

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

CMakeLists.txt

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,25 @@ set(LIB_PREFIX g2o_)
1212
set(g2o_C_FLAGS)
1313
set(g2o_CXX_FLAGS)
1414

15-
# default built type
16-
if(NOT CMAKE_BUILD_TYPE)
17-
set(CMAKE_BUILD_TYPE Release CACHE STRING
18-
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
19-
FORCE)
20-
endif(NOT CMAKE_BUILD_TYPE)
21-
22-
# postfix, based on type
23-
set(CMAKE_DEBUG_POSTFIX "_d" CACHE STRING "postfix applied to debug build of libraries")
24-
set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "postfix applied to release build of libraries")
25-
set(CMAKE_RELWITHDEBINFO_POSTFIX "_rd" CACHE STRING "postfix applied to release-with-debug-information libraries")
26-
set(CMAKE_MINSIZEREL_POSTFIX "_s" CACHE STRING "postfix applied to minimum-size-build libraries")
15+
# manually check for top-level project if CMake is older than 3.21
16+
if(CMAKE_VERSION VERSION_LESS 3.21)
17+
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" PROJECT_IS_TOP_LEVEL)
18+
endif()
19+
20+
if(PROJECT_IS_TOP_LEVEL)
21+
# default built type
22+
if(NOT CMAKE_BUILD_TYPE)
23+
set(CMAKE_BUILD_TYPE Release CACHE STRING
24+
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
25+
FORCE)
26+
endif()
27+
28+
# postfix, based on type
29+
set(CMAKE_DEBUG_POSTFIX "_d" CACHE STRING "postfix applied to debug build of libraries")
30+
set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "postfix applied to release build of libraries")
31+
set(CMAKE_RELWITHDEBINFO_POSTFIX "_rd" CACHE STRING "postfix applied to release-with-debug-information libraries")
32+
set(CMAKE_MINSIZEREL_POSTFIX "_s" CACHE STRING "postfix applied to minimum-size-build libraries")
33+
endif()
2734

2835
# work out the postfix; required where we use OUTPUT_NAME
2936
if(CMAKE_BUILD_TYPE MATCHES Release)

0 commit comments

Comments
 (0)