From b8b298104b18486e65fd40ae410a327d9e6fe8f3 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Wed, 20 Jul 2005 15:44:55 -0400 Subject: ENH: make sure flags set in CC or CXX environment variables stay with the compiler --- Modules/CMakeCCompiler.cmake.in | 1 + Modules/CMakeCInformation.cmake | 2 +- Modules/CMakeCXXCompiler.cmake.in | 1 + Modules/CMakeCXXInformation.cmake | 2 +- Modules/CMakeDetermineCCompiler.cmake | 3 +++ Modules/CMakeDetermineCXXCompiler.cmake | 3 +++ Modules/CMakeDetermineFortranCompiler.cmake | 3 +++ Modules/CMakeDetermineJavaCompiler.cmake | 3 +++ Modules/CMakeDetermineRCCompiler.cmake | 3 +++ Modules/CMakeFortranCompiler.cmake.in | 1 + Modules/CMakeFortranInformation.cmake | 2 +- Modules/CMakeJavaCompiler.cmake.in | 1 + Modules/CMakeRCCompiler.cmake.in | 1 + Modules/CMakeRCInformation.cmake | 2 +- Source/cmLocalGenerator.cxx | 18 +++++++++++++++++- 15 files changed, 41 insertions(+), 5 deletions(-) diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in index a767e8f..9dc9737 100644 --- a/Modules/CMakeCCompiler.cmake.in +++ b/Modules/CMakeCCompiler.cmake.in @@ -1,4 +1,5 @@ SET(CMAKE_C_COMPILER "@CMAKE_C_COMPILER@") +SET(CMAKE_C_COMPILER_ARG1 @CMAKE_C_COMPILER_ARG1@) SET(CMAKE_AR "@CMAKE_AR@") SET(CMAKE_RANLIB "@CMAKE_RANLIB@") SET(CMAKE_COMPILER_IS_GNUCC @CMAKE_COMPILER_IS_GNUCC@) diff --git a/Modules/CMakeCInformation.cmake b/Modules/CMakeCInformation.cmake index c8d8e06..cca45b7 100644 --- a/Modules/CMakeCInformation.cmake +++ b/Modules/CMakeCInformation.cmake @@ -18,7 +18,7 @@ IF(NOT CMAKE_MODULE_EXISTS) SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}) ENDIF(NOT CMAKE_MODULE_EXISTS) -SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_ENV_INIT} $ENV{CFLAGS} ${CMAKE_C_FLAGS_INIT}" CACHE STRING +SET (CMAKE_C_FLAGS "$ENV{CFLAGS} ${CMAKE_C_FLAGS_INIT}" CACHE STRING "Flags for C compiler.") IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS) diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in index e87ae14..b2463a1 100644 --- a/Modules/CMakeCXXCompiler.cmake.in +++ b/Modules/CMakeCXXCompiler.cmake.in @@ -1,4 +1,5 @@ SET(CMAKE_CXX_COMPILER "@CMAKE_CXX_COMPILER@") +SET(CMAKE_CXX_COMPILER_ARG1 @CMAKE_CXX_COMPILER_ARG1@) SET(CMAKE_COMPILER_IS_GNUCXX @CMAKE_COMPILER_IS_GNUCXX@) SET(CMAKE_CXX_COMPILER_LOADED 1) SET(CMAKE_COMPILER_IS_GNUCXX_RUN 1) diff --git a/Modules/CMakeCXXInformation.cmake b/Modules/CMakeCXXInformation.cmake index eefc5f8..384e6be 100644 --- a/Modules/CMakeCXXInformation.cmake +++ b/Modules/CMakeCXXInformation.cmake @@ -74,7 +74,7 @@ ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG_SEP) # on the initial values computed in the platform/*.cmake files # use _INIT variables so that this only happens the first time # and you can set these flags in the cmake cache -SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_ENV_INIT} $ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_INIT}" CACHE STRING +SET (CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_INIT}" CACHE STRING "Flags used by the compiler during all build types.") diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake index 4317ecf..c4dfa11 100644 --- a/Modules/CMakeDetermineCCompiler.cmake +++ b/Modules/CMakeDetermineCCompiler.cmake @@ -11,6 +11,9 @@ IF(NOT CMAKE_C_COMPILER) # prefer the environment variable CC IF($ENV{CC} MATCHES ".+") GET_FILENAME_COMPONENT(CMAKE_C_COMPILER_INIT $ENV{CC} PROGRAM PROGRAM_ARGS CMAKE_C_FLAGS_ENV_INIT) + IF(CMAKE_C_FLAGS_ENV_INIT) + SET(CMAKE_C_COMPILER_ARG1 ${CMAKE_C_FLAGS_ENV_INIT} CACHE STRING "First argument to C compiler") + ENDIF(CMAKE_C_FLAGS_ENV_INIT) IF(EXISTS ${CMAKE_C_COMPILER_INIT}) ELSE(EXISTS ${CMAKE_C_COMPILER_INIT}) MESSAGE(FATAL_ERROR "Could not find compiler set in environment variable CC:\n$ENV{CC}.") diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake index 4658229..60cf283 100644 --- a/Modules/CMakeDetermineCXXCompiler.cmake +++ b/Modules/CMakeDetermineCXXCompiler.cmake @@ -11,6 +11,9 @@ IF(NOT CMAKE_CXX_COMPILER) # prefer the environment variable CXX IF($ENV{CXX} MATCHES ".+") GET_FILENAME_COMPONENT(CMAKE_CXX_COMPILER_INIT $ENV{CXX} PROGRAM PROGRAM_ARGS CMAKE_CXX_FLAGS_ENV_INIT) + IF(CMAKE_CXX_FLAGS_ENV_INIT) + SET(CMAKE_CXX_COMPILER_ARG1 ${CMAKE_CXX_FLAGS_ENV_INIT} CACHE STRING "First argument to CXX compiler") + ENDIF(CMAKE_CXX_FLAGS_ENV_INIT) IF(EXISTS ${CMAKE_CXX_COMPILER_INIT}) ELSE(EXISTS ${CMAKE_CXX_COMPILER_INIT}) MESSAGE(FATAL_ERROR "Could not find compiler set in environment variable CXX:\n$ENV{CXX}.\n${CMAKE_CXX_COMPILER_INIT}") diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake index 53a1c75..33dfce6 100644 --- a/Modules/CMakeDetermineFortranCompiler.cmake +++ b/Modules/CMakeDetermineFortranCompiler.cmake @@ -8,6 +8,9 @@ IF(NOT CMAKE_Fortran_COMPILER) # prefer the environment variable CC IF($ENV{FC} MATCHES ".+") GET_FILENAME_COMPONENT(CMAKE_Fortran_COMPILER_INIT $ENV{FC} PROGRAM PROGRAM_ARGS CMAKE_Fortran_FLAGS_ENV_INIT) + IF(CMAKE_Fortran_FLAGS_ENV_INIT) + SET(CMAKE_Fortran_COMPILER_ARG1 ${CMAKE_Fortran_FLAGS_ENV_INIT} CACHE STRING "First argument to Fortran compiler") + ENDIF(CMAKE_Fortran_FLAGS_ENV_INIT) IF(EXISTS ${CMAKE_Fortran_COMPILER_INIT}) ELSE(EXISTS ${CMAKE_Fortran_COMPILER_INIT}) MESSAGE(FATAL_ERROR "Could not find compiler set in environment variable FC:\n$ENV{FC}.") diff --git a/Modules/CMakeDetermineJavaCompiler.cmake b/Modules/CMakeDetermineJavaCompiler.cmake index 03e7719..3b787a9 100644 --- a/Modules/CMakeDetermineJavaCompiler.cmake +++ b/Modules/CMakeDetermineJavaCompiler.cmake @@ -6,6 +6,9 @@ IF(NOT CMAKE_Java_COMPILER) # prefer the environment variable CC IF($ENV{JAVA_COMPILER} MATCHES ".+") GET_FILENAME_COMPONENT(CMAKE_Java_COMPILER_INIT $ENV{JAVA_COMPILER} PROGRAM PROGRAM_ARGS CMAKE_Java_FLAGS_ENV_INIT) + IF(CMAKE_Java_FLAGS_ENV_INIT) + SET(CMAKE_Java_COMPILER_ARG1 ${CMAKE_Java_FLAGS_ENV_INIT} CACHE STRING "First argument to Java compiler") + ENDIF(CMAKE_Java_FLAGS_ENV_INIT) IF(EXISTS ${CMAKE_Java_COMPILER_INIT}) ELSE(EXISTS ${CMAKE_Java_COMPILER_INIT}) MESSAGE(SEND_ERROR "Could not find compiler set in environment variable JAVA_COMPILER:\n$ENV{JAVA_COMPILER}.") diff --git a/Modules/CMakeDetermineRCCompiler.cmake b/Modules/CMakeDetermineRCCompiler.cmake index 7db2ec2..8150b30 100644 --- a/Modules/CMakeDetermineRCCompiler.cmake +++ b/Modules/CMakeDetermineRCCompiler.cmake @@ -8,6 +8,9 @@ IF(NOT CMAKE_RC_COMPILER) # prefer the environment variable CC IF($ENV{RC} MATCHES ".+") GET_FILENAME_COMPONENT(CMAKE_RC_COMPILER_INIT $ENV{RC} PROGRAM PROGRAM_ARGS CMAKE_RC_FLAGS_ENV_INIT) + IF(CMAKE_RC_FLAGS_ENV_INIT) + SET(CMAKE_RC_COMPILER_ARG1 ${CMAKE_RC_FLAGS_ENV_INIT} CACHE STRING "First argument to RC compiler") + ENDIF(CMAKE_RC_FLAGS_ENV_INIT) IF(EXISTS ${CMAKE_RC_COMPILER_INIT}) ELSE(EXISTS ${CMAKE_RC_COMPILER_INIT}) MESSAGE(FATAL_ERROR "Could not find compiler set in environment variable RC:\n$ENV{RC}.") diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in index f526776..b2432e4 100644 --- a/Modules/CMakeFortranCompiler.cmake.in +++ b/Modules/CMakeFortranCompiler.cmake.in @@ -1,4 +1,5 @@ SET(CMAKE_Fortran_COMPILER "@CMAKE_Fortran_COMPILER@") +SET(CMAKE_Fortran_COMPILER_ARG1 "@CMAKE_Fortran_COMPILER_ARG1@") SET(CMAKE_AR "@CMAKE_AR@") SET(CMAKE_RANLIB "@CMAKE_RANLIB@") SET(CMAKE_COMPILER_IS_GNUG77 @CMAKE_COMPILER_IS_GNUG77@) diff --git a/Modules/CMakeFortranInformation.cmake b/Modules/CMakeFortranInformation.cmake index 4fbe4c2..2680db0 100644 --- a/Modules/CMakeFortranInformation.cmake +++ b/Modules/CMakeFortranInformation.cmake @@ -69,7 +69,7 @@ ENDIF(NOT CMAKE_INCLUDE_FLAG_SEP_Fortran) SET(CMAKE_VERBOSE_MAKEFILE FALSE CACHE BOOL "If this value is on, makefiles will be generated without the .SILENT directive, and all commands will be echoed to the console during the make. This is useful for debugging only. With Visual Studio IDE projects all commands are done without /nologo.") -SET (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_ENV_INIT} $ENV{FFLAGS} ${CMAKE_Fortran_FLAGS_INIT}" CACHE STRING +SET (CMAKE_Fortran_FLAGS "$ENV{FFLAGS} ${CMAKE_Fortran_FLAGS_INIT}" CACHE STRING "Flags for Fortran compiler.") diff --git a/Modules/CMakeJavaCompiler.cmake.in b/Modules/CMakeJavaCompiler.cmake.in index 5742652..c9eeb14 100644 --- a/Modules/CMakeJavaCompiler.cmake.in +++ b/Modules/CMakeJavaCompiler.cmake.in @@ -1,4 +1,5 @@ SET(CMAKE_Java_COMPILER "@CMAKE_Java_COMPILER@") +SET(CMAKE_Java_COMPILER_ARG1 "@CMAKE_Java_COMPILER_ARG1@") SET(CMAKE_Java_RUNTIME "@CMAKE_Java_RUNTIME@") SET(CMAKE_Java_ARCHIVE "@CMAKE_Java_ARCHIVE@") SET(CMAKE_Java_COMPILER_LOADED 1) diff --git a/Modules/CMakeRCCompiler.cmake.in b/Modules/CMakeRCCompiler.cmake.in index 33f6d90..93bc850 100644 --- a/Modules/CMakeRCCompiler.cmake.in +++ b/Modules/CMakeRCCompiler.cmake.in @@ -1,4 +1,5 @@ SET(CMAKE_RC_COMPILER "@CMAKE_RC_COMPILER@") +SET(CMAKE_RC_COMPILER_ARG1 "@CMAKE_RC_COMPILER_ARG1@") SET(CMAKE_RC_COMPILER_LOADED 1) SET(CMAKE_RC_SOURCE_FILE_EXTENSIONS rc) SET(CMAKE_RC_OUTPUT_EXTENSION .res) diff --git a/Modules/CMakeRCInformation.cmake b/Modules/CMakeRCInformation.cmake index ceb5cfd..1dc1000 100644 --- a/Modules/CMakeRCInformation.cmake +++ b/Modules/CMakeRCInformation.cmake @@ -8,7 +8,7 @@ SET(CMAKE_SYSTEM_AND_RC_COMPILER_INFO_FILE INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL) -SET (CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS_ENV_INIT} $ENV{RCFLAGS} ${CMAKE_RC_FLAGS_INIT}" CACHE STRING +SET (CMAKE_RC_FLAGS "$ENV{RCFLAGS} ${CMAKE_RC_FLAGS_INIT}" CACHE STRING "Flags for Fortran compiler.") diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index b71e53f..eb36a4f 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -833,6 +833,15 @@ cmLocalGenerator::ExpandRuleVariable(std::string const& variable, { lang = i->c_str(); std::string actualReplace = ruleReplaceVars[pos]; + // If this is the compiler then look for the extra variable + // _COMPILER_ARG1 which must be the first argument to the compiler + const char* compilerArg1 = 0; + if(actualReplace == "CMAKE_${LANG}_COMPILER") + { + std::string arg1 = actualReplace + "_ARG1"; + cmSystemTools::ReplaceString(arg1, "${LANG}", lang); + compilerArg1 = m_Makefile->GetDefinition(arg1.c_str()); + } if(actualReplace.find("${LANG}") != actualReplace.npos) { cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang); @@ -843,7 +852,14 @@ cmLocalGenerator::ExpandRuleVariable(std::string const& variable, // if the variable is not a FLAG then treat it like a path if(variable.find("_FLAG") == variable.npos) { - return this->ConvertToOutputForExisting(replace.c_str()); + std::string ret = this->ConvertToOutputForExisting(replace.c_str()); + // if there is a required first argument to the compiler add it to the compiler string + if(compilerArg1) + { + ret += " "; + ret += compilerArg1; + } + return ret; } return replace; } -- cgit v0.12