diff --git a/CMakeLists.txt b/CMakeLists.txt index 0538293cad..6228383400 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -266,6 +266,38 @@ target_compile_definitions(geos_cxx_flags INTERFACE USE_UNSTABLE_GEOS_CPP_API) +# Deal with Intel Compiler +if (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM") + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag(-fno-fast-math HAVE_FLAG_NO_FAST_MATH) + if (HAVE_FLAG_NO_FAST_MATH) + # Intel CXX compiler, based on clang, defaults to -ffast-math, which breaks a lot of things + target_compile_options(geos_cxx_flags INTERFACE "-fno-fast-math") + endif () + + set(TEST_LINK_STDCPP_SOURCE_CODE + "#include + int main(){ + std::string s; + s += \"x\"; + return 0; + }") + check_cxx_source_compiles("${TEST_LINK_STDCPP_SOURCE_CODE}" _TEST_LINK_STDCPP) + if( NOT _TEST_LINK_STDCPP ) + message(WARNING "Cannot link code using standard C++ library. Automatically adding -lstdc++ to CMAKE_EXE_LINKER_FLAGS, CMAKE_SHARED_LINKER_FLAGS and CMAKE_MODULE_LINKER_FLAGS") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lstdc++") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -lstdc++") + + include(CheckCXXSourceCompiles) + check_cxx_source_compiles("${TEST_LINK_STDCPP_SOURCE_CODE}" _TEST_LINK_STDCPP_AGAIN) + if( NOT _TEST_LINK_STDCPP_AGAIN ) + message(FATAL_ERROR "Cannot link C++ program") + endif() + endif() +endif () + + target_compile_definitions(geos_developer_cxx_flags INTERFACE $<$:_CRT_NONSTDC_NO_DEPRECATE>