diff options
-rw-r--r-- | CMakeLists.txt | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index aa6e8d20..4293966f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,15 +156,18 @@ if(NOT MSVC OR CMAKE_VERSION VERSION_GREATER 3.59) cxx_variable_templates ) endif() +set(check_cxx_source_linkage_flags) # If on VS2019 16.3 or later, or on Apple, we require C++ 17 if((MSVC AND MSVC_VERSION VERSION_GREATER_EQUAL 1923) OR APPLE) all_compile_features(PUBLIC cxx_std_17 ) - if(MSVC) - set(check_cxx_source_linkage_flags /std:c++17) - else() - set(check_cxx_source_linkage_flags -std=c++17) + if(NOT CMAKE_CXX_STANDARD) + if(MSVC) + set(check_cxx_source_linkage_flags /std:c++17) + else() + set(check_cxx_source_linkage_flags -std=c++17) + endif() endif() endif() # Set the library dependencies this library has @@ -184,6 +187,13 @@ function(check_cxx_source_linkage prog var) if(MSVC AND CMAKE_GENERATOR MATCHES "Ninja") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} /EHsc") endif() + if(CMAKE_CXX_STANDARD) + if(MSVC) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} /std:c++${CMAKE_CXX_STANDARD}") + else() + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++${CMAKE_CXX_STANDARD}") + endif() + endif() if(CMAKE_SYSTEM_PROCESSOR STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR} AND NOT LLFIO_ASSUME_CROSS_COMPILING) check_cxx_source_runs("${prog}" ${var}) else() |