From 9a6c95fcea52bd1b5b4930fdac0a48088e55273b Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Thu, 21 Nov 2002 12:52:54 -0500 Subject: [PATCH] add checks for ansi flags and not hard code them --- Modules/CMakeBackwardCompatibilityCXX.cmake | 23 +++++++++++++++++++++ Modules/DummyCXXFile.cxx | 4 ++++ Modules/Platform/IRIX64.cmake | 1 - Modules/Platform/OSF1.cmake | 3 --- Modules/TestCXXAcceptsFlag.cmake | 20 ++++++++++++++++++ 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 Modules/DummyCXXFile.cxx create mode 100644 Modules/TestCXXAcceptsFlag.cmake diff --git a/Modules/CMakeBackwardCompatibilityCXX.cmake b/Modules/CMakeBackwardCompatibilityCXX.cmake index a8e44246d..ccc2e335f 100644 --- a/Modules/CMakeBackwardCompatibilityCXX.cmake +++ b/Modules/CMakeBackwardCompatibilityCXX.cmake @@ -1,4 +1,27 @@ # + +# check for some ANSI flags in the CXX compiler if it is not gnu +IF(NOT CMAKE_COMPILER_IS_GNUCXX) + INCLUDE(${CMAKE_ROOT}/Modules/TestCXXAcceptFlag.cmake) + SET(CMAKE_TRY_ANSI_CXX_FLAGS "") + IF(CMAKE_SYSTEM MATCHES "IRIX.*") + SET(CMAKE_TRY_ANSI_CXX_FLAGS "-LANG:std") + ENDIF(CMAKE_SYSTEM MATCHES "IRIX.*") + IF(CMAKE_SYSTEM MATCHES "OSF.*") + SET(CMAKE_TRY_ANSI_CXX_FLAGS "-std strict_ansi -nopure_cname") + ENDIF(CMAKE_SYSTEM MATCHES "OSF.*") + # if CMAKE_TRY_ANSI_CXX_FLAGS has something in it, see + # if the compiler accepts it + IF( CMAKE_TRY_ANSI_CXX_FLAGS MATCHES ".+") + CHECK_CXX_ACCEPTS_FLAG(${CMAKE_TRY_ANSI_CXX_FLAGS} CMAKE_CXX_ACCEPTS_FLAGS) + # if the compiler liked the flag then set CMAKE_ANSI_CXXFLAGS + # to the flag + IF(CMAKE_CXX_ACCEPTS_FLAGS) + SET(CMAKE_ANSI_CXXFLAGS ${CMAKE_TRY_ANSI_CXX_FLAGS}) + ENDIF(CMAKE_CXX_ACCEPTS_FLAGS) + ENDIF( CMAKE_TRY_ANSI_CXX_FLAGS MATCHES ".+") +ENDIF(NOT CMAKE_COMPILER_IS_GNUCXX) + INCLUDE(${CMAKE_ROOT}/Modules/TestForANSIStreamHeaders.cmake) INCLUDE(${CMAKE_ROOT}/Modules/CheckIncludeFileCXX.cmake) INCLUDE(${CMAKE_ROOT}/Modules/TestForSTDNamespace.cmake) diff --git a/Modules/DummyCXXFile.cxx b/Modules/DummyCXXFile.cxx new file mode 100644 index 000000000..f8b643afb --- /dev/null +++ b/Modules/DummyCXXFile.cxx @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/Modules/Platform/IRIX64.cmake b/Modules/Platform/IRIX64.cmake index 0caf9abbb..8f78f0292 100644 --- a/Modules/Platform/IRIX64.cmake +++ b/Modules/Platform/IRIX64.cmake @@ -6,7 +6,6 @@ SET(CMAKE_SHARED_LIBRARY_RUNTIME_FLAG_SEP "") # : or empty IF(NOT CMAKE_COMPILER_IS_GNUCXX) SET(CMAKE_CXX_CREATE_STATIC_LIBRARY " -ar -o ") - SET(CMAKE_ANSI_CXXFLAGS -LANG:std) SET (CMAKE_CXX_FLAGS_INIT "") SET (CMAKE_CXX_FLAGS_DEBUG_INIT "-g") SET (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-O3") diff --git a/Modules/Platform/OSF1.cmake b/Modules/Platform/OSF1.cmake index 188045e91..08be310d3 100644 --- a/Modules/Platform/OSF1.cmake +++ b/Modules/Platform/OSF1.cmake @@ -21,6 +21,3 @@ IF(CMAKE_SYSTEM MATCHES "OSF1-V.*") SET(CMAKE_SHARED_LIBRARY_RUNTIME_FLAG_SEP ":") ENDIF(CMAKE_SYSTEM MATCHES "OSF1-V.*") -IF(NOT CMAKE_COMPILER_IS_GNUCXX) - SET(CMAKE_ANSI_CXXFLAGS "-std strict_ansi -nopure_cname") -ENDIF(NOT CMAKE_COMPILER_IS_GNUCXX) diff --git a/Modules/TestCXXAcceptsFlag.cmake b/Modules/TestCXXAcceptsFlag.cmake new file mode 100644 index 000000000..1c6f35167 --- /dev/null +++ b/Modules/TestCXXAcceptsFlag.cmake @@ -0,0 +1,20 @@ +# +# Check if the CXX compiler accepts a flag +# +# CHECK_FUNCTION_EXISTS - macro which checks if the function exists +# FLAG - the flags to try +# VARIABLE - variable to store the result +# + +MACRO(CHECK_CXX_ACCEPTS_FLAG FLAGS VARIABLE) + MESSAGE(STATUS "Checking to see if CXX compiler acepts flag ${FLAGS}") + TRY_COMPILE(${VARIABLE} + ${PROJECT_BINARY_DIR} + ${CMAKE_ROOT}/Modules/DummyCXXFile.cxx + CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${FLAGS} + OUTPUT_VARIABLE OUTPUT) + IF(NOT ${VARIABLE}) + WRITE_FILE(${PROJECT_BINARY_DIR}/CMakeError.log + "Determining if the CXX compiler accepts the flag ${FLAGS} failed with the following output:\n" "${OUTPUT}\n" APPEND) + ENDIF(NOT ${VARIABLE}) +ENDMACRO(CHECK_CXX_ACCEPTS_FLAG)