@@ -12,18 +12,25 @@ set(LIB_PREFIX g2o_)
1212set (g2o_C_FLAGS)
1313set (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
2936if (CMAKE_BUILD_TYPE MATCHES Release)
0 commit comments