From 1b2f2889ad06c215e9bcf21bad547c951c568f6d Mon Sep 17 00:00:00 2001 From: Nicolas Hake Date: Mon, 31 Dec 2018 16:17:37 +0100 Subject: [PATCH] Old CMake: Correctly handle try_compile with language standard flags CMake before 3.7 didn't properly pass the standard selection flags to try_compile. Wrap try_compile on old CMake versions so that the flag gets passed. --- CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index db1bb0c78..6b906036b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,37 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE RelWithDebInfo) endif() +if(POLICY CMP0067) + cmake_policy(SET CMP0067 NEW) +else() + # Wrap try_compile such that it correctly passes the standard flags to the + # compiler on CMake versions below 3.8. Remove when you update the minimum + # required version to 3.8 or later. + macro(try_compile) + set(_tc_langs) + foreach(_tc_lang CXX C) + if(DEFINED CMAKE_${_tc_lang}_STANDARD) + list(APPEND _tc_langs ${_tc_lang}) + endif() + endforeach() + foreach(_tc_lang ${_tc_langs}) + if (${CMAKE_${_tc_lang}_EXTENSIONS}) + set(_tc_ext EXTENSION) + else() + set(_tc_ext STANDARD) + endif() + set(_backup_${_tc_lang}_flags "${CMAKE_${_tc_lang}_FLAGS}") + set(CMAKE_${_tc_lang}_FLAGS "${CMAKE_${_tc_lang}_FLAGS} ${CMAKE_${_tc_lang}${CMAKE_${_tc_lang}_STANDARD}_${_tc_ext}_COMPILE_OPTION}") + endforeach() + + _try_compile(${ARGN}) + + foreach(_tc_lang ${_tc_langs}) + set(CMAKE_${_tc_lang}_FLAGS "${_backup_${_tc_lang}_flags}") + endforeach() + endmacro() +endif() + project (openclonk CXX C) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")