From c4c6c9cbce44442e241231cfbe7e0a6373e54d69 Mon Sep 17 00:00:00 2001 From: Matthias Volk Date: Thu, 26 Oct 2017 22:22:08 +0200 Subject: [PATCH] Test compiler configurations within cmake --- CMakeLists.txt | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b6c56e03c..c0d958476 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/resources/cmak include(ExternalProject) include(RegisterSourceGroup) include(imported) - +include(CheckCXXSourceCompiles) +include(CheckCSourceCompiles) ############################################################# ## @@ -292,6 +293,31 @@ else() set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer") endif() +# Test compiler by compiling small program. +CHECK_C_SOURCE_COMPILES(" + #include + int main() { + const char* text = \"A Storm is coming.\"; + return 0; + }" + COMPILER_C_WORKS +) +CHECK_CXX_SOURCE_COMPILES(" + #include + int main() { + const std::string text = \"A Storm is coming.\"; + return 0; + }" + COMPILER_CXX_WORKS +) +if ((NOT COMPILER_CXX_WORKS) OR (NOT COMPILER_C_WORKS)) + if (MACOSX) + message(FATAL_ERROR "The C/C++ compiler is not configured correctly.\nTry running 'xcode-select --install'.") + else() + message(FATAL_ERROR "The C/C++ compiler is not configured correctly.") + endif() +endif() + ############################################################# ## ## RPATH settings