Skip to content

Commit

Permalink
Fix CMake on Windows with Visual Studio (#945)
Browse files Browse the repository at this point in the history
Avoid setting CMAKE_BUILD_TYPE default when multi-config generators are
used.

Avoid setting CMAKE_BUILD_TYPE STRINGS property if it is not a cache
variable. This avoids CMake errors if CMAKE_BUILD_TYPE isn't set on the
command-line.

Closes #932
  • Loading branch information
here-abarany authored and mwtoews committed Aug 17, 2023
1 parent feaa331 commit 40da3a6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions CMakeLists.txt
Expand Up @@ -114,8 +114,12 @@ endif()

# Make sure we know our build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE})
message(STATUS "GEOS: Using default build type: ${CMAKE_BUILD_TYPE}")
get_property(_is_multi_config_generator GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (NOT _is_multi_config_generator)
set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE})
message(STATUS "GEOS: Using default build type: ${CMAKE_BUILD_TYPE}")
endif()
unset(_is_multi_config_generator)
else()
message(STATUS "GEOS: Build type: ${CMAKE_BUILD_TYPE}")
endif()
Expand Down Expand Up @@ -186,7 +190,11 @@ set(CMAKE_CXX_FLAGS_ASAN "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-
set(CMAKE_EXE_LINKER_FLAGS_ASAN "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS_ASAN "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address")

set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" "ASAN")
get_property(_cmake_build_type_is_cache CACHE CMAKE_BUILD_TYPE PROPERTY TYPE)
if (_cmake_build_type_is_cache)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" "ASAN")
endif()
unset(_cmake_build_type_is_cache)

#-----------------------------------------------------------------------------
# Install directories
Expand Down

0 comments on commit 40da3a6

Please sign in to comment.