From 08289893b8590be41d0541af7644e737035aee54 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 11 Apr 2006 16:55:49 -0400 Subject: ENH: Split CMAKE_STANDARD_LIBRARIES into per-language variables CMAKE__STANDARD_LIBRARIES. This is needed to get programmable language support working with Visual Studio generators. It makes sense anyway. --- Modules/CMakeCInformation.cmake | 6 ++++ Modules/CMakeCXXInformation.cmake | 5 ++++ Modules/CMakeFortranInformation.cmake | 5 ++++ Modules/Platform/Windows-bcc32.cmake | 8 ++---- Modules/Platform/Windows-cl.cmake | 16 +++-------- Modules/Platform/Windows-icl.cmake | 5 ++-- Modules/Platform/Windows-ifort.cmake | 7 +---- Modules/Platform/Windows-wcl386.cmake | 4 +-- Source/cmLocalGenerator.cxx | 10 +++++-- Source/cmLocalVisualStudio6Generator.cxx | 41 ++++++++++++++++++++------- Source/cmLocalVisualStudio7Generator.cxx | 48 +++++++++++++++++++++----------- 11 files changed, 98 insertions(+), 57 deletions(-) diff --git a/Modules/CMakeCInformation.cmake b/Modules/CMakeCInformation.cmake index 242d796..230d49e 100644 --- a/Modules/CMakeCInformation.cmake +++ b/Modules/CMakeCInformation.cmake @@ -53,6 +53,12 @@ IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS) "Flags used by the compiler during Release with Debug Info builds.") ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS) +IF(CMAKE_C_STANDARD_LIBRARIES_INIT) + SET(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES_INIT}" + CACHE STRING "Libraries linked by defalut with all C applications.") + MARK_AS_ADVANCED(CMAKE_C_STANDARD_LIBRARIES) +ENDIF(CMAKE_C_STANDARD_LIBRARIES_INIT) + INCLUDE(CMakeCommonLanguageInclude) # now define the following rule variables diff --git a/Modules/CMakeCXXInformation.cmake b/Modules/CMakeCXXInformation.cmake index 6e16e4a..8d05933 100644 --- a/Modules/CMakeCXXInformation.cmake +++ b/Modules/CMakeCXXInformation.cmake @@ -104,6 +104,11 @@ IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS) ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS) +IF(CMAKE_CXX_STANDARD_LIBRARIES_INIT) + SET(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES_INIT}" + CACHE STRING "Libraries linked by defalut with all C++ applications.") + MARK_AS_ADVANCED(CMAKE_CXX_STANDARD_LIBRARIES) +ENDIF(CMAKE_CXX_STANDARD_LIBRARIES_INIT) INCLUDE(CMakeCommonLanguageInclude) diff --git a/Modules/CMakeFortranInformation.cmake b/Modules/CMakeFortranInformation.cmake index 9dd0649..80a8e7a 100644 --- a/Modules/CMakeFortranInformation.cmake +++ b/Modules/CMakeFortranInformation.cmake @@ -129,6 +129,11 @@ IF(NOT CMAKE_Fortran_LINK_EXECUTABLE) " -o ") ENDIF(NOT CMAKE_Fortran_LINK_EXECUTABLE) +IF(CMAKE_Fortran_STANDARD_LIBRARIES_INIT) + SET(CMAKE_Fortran_STANDARD_LIBRARIES "${CMAKE_Fortran_STANDARD_LIBRARIES_INIT}" + CACHE STRING "Libraries linked by defalut with all Fortran applications.") + MARK_AS_ADVANCED(CMAKE_Fortran_STANDARD_LIBRARIES) +ENDIF(CMAKE_Fortran_STANDARD_LIBRARIES_INIT) IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS) SET (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG_INIT}" CACHE STRING diff --git a/Modules/Platform/Windows-bcc32.cmake b/Modules/Platform/Windows-bcc32.cmake index 2f334e0..3bc4f01 100644 --- a/Modules/Platform/Windows-bcc32.cmake +++ b/Modules/Platform/Windows-bcc32.cmake @@ -95,9 +95,5 @@ SET (CMAKE_MODULE_LINKER_FLAGS_INIT ${CMAKE_SHARED_LINKER_FLAGS_INIT}) SET (CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT ${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT}) SET (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT}) - -SET (CMAKE_STANDARD_LIBRARIES "import32.lib" CACHE STRING - "Libraries linked by defalut with all applications.") - -MARK_AS_ADVANCED(CMAKE_STANDARD_LIBRARIES) - +SET (CMAKE_C_STANDARD_LIBRARIES_INIT "import32.lib") +SET (CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}") diff --git a/Modules/Platform/Windows-cl.cmake b/Modules/Platform/Windows-cl.cmake index fceb68a..1021f78 100644 --- a/Modules/Platform/Windows-cl.cmake +++ b/Modules/Platform/Windows-cl.cmake @@ -211,8 +211,7 @@ IF(MSVC80) SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "/MD /O1 /Ob1 /D NDEBUG") SET (CMAKE_C_FLAGS_RELEASE_INIT "/MD /O2 /Ob2 /D NDEBUG") SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MD /Zi /O2 /Ob1 /D NDEBUG") - SET (CMAKE_STANDARD_LIBRARIES "kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib " CACHE STRING - "Libraries linked by defalut with all applications.") + SET (CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib ") ELSE(MSVC80) IF(CMAKE_USING_VC_FREE_TOOLS) MESSAGE(STATUS "Using FREE VC TOOLS, NO DEBUG available") @@ -227,10 +226,7 @@ ELSE(MSVC80) SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1") SET (CMAKE_C_FLAGS_RELEASE_INIT "/MT /O2 /Ob2") SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1") - SET (CMAKE_STANDARD_LIBRARIES "kernel32.lib user32.lib gdi32.lib advapi32.lib rpcrt4.lib" CACHE STRING - "Libraries linked by defalut with all applications.") - SET (CMAKE_STANDARD_LIBRARIES "kernel32.lib user32.lib gdi32.lib advapi32.lib rpcrt4.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib" CACHE STRING - "Libraries linked by defalut with all applications.") + SET (CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib advapi32.lib rpcrt4.lib") ELSE(CMAKE_USING_VC_FREE_TOOLS) SET(CMAKE_BUILD_TYPE_INIT Debug) SET (CMAKE_CXX_FLAGS_INIT "/DWIN32 /D_WINDOWS /W3 /Zm1000 /GX /GR") @@ -243,15 +239,11 @@ ELSE(MSVC80) SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "/MD /O1 /Ob1 /D NDEBUG") SET (CMAKE_C_FLAGS_RELEASE_INIT "/MD /O2 /Ob2 /D NDEBUG") SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MD /Zi /O2 /Ob1 /D NDEBUG") - SET (CMAKE_STANDARD_LIBRARIES "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib" CACHE STRING - "Libraries linked by defalut with all applications.") + SET (CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib") ENDIF(CMAKE_USING_VC_FREE_TOOLS) ENDIF(MSVC80) - -MARK_AS_ADVANCED(CMAKE_STANDARD_LIBRARIES) - - +SET(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}") # executable linker flags SET (CMAKE_LINK_DEF_FILE_FLAG "/DEF:") diff --git a/Modules/Platform/Windows-icl.cmake b/Modules/Platform/Windows-icl.cmake index bad8949..d09eb1c 100644 --- a/Modules/Platform/Windows-icl.cmake +++ b/Modules/Platform/Windows-icl.cmake @@ -60,9 +60,8 @@ SET (CMAKE_C_FLAGS_RELEASE_INIT "/MD /O2") SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MD /Zi /O2") -SET (CMAKE_STANDARD_LIBRARIES "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib" CACHE STRING - "Libraries linked by defalut with all applications.") -MARK_AS_ADVANCED(CMAKE_STANDARD_LIBRARIES) +SET(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib") +SET(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}") # executable linker flags SET (CMAKE_LINK_DEF_FILE_FLAG "/DEF:") diff --git a/Modules/Platform/Windows-ifort.cmake b/Modules/Platform/Windows-ifort.cmake index a152864..1b3459d 100644 --- a/Modules/Platform/Windows-ifort.cmake +++ b/Modules/Platform/Windows-ifort.cmake @@ -43,13 +43,8 @@ SET (CMAKE_Fortran_FLAGS_DEBUG_INIT "/debug:full") SET (CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "/O2 /D NDEBUG") SET (CMAKE_Fortran_FLAGS_RELEASE_INIT "/MD /O1 /D NDEBUG") SET (CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "/O1 /debug:full /D NDEBUG") -SET (CMAKE_STANDARD_LIBRARIES "user32.lib" CACHE STRING - "Libraries linked by defalut with all applications.") - - -MARK_AS_ADVANCED(CMAKE_STANDARD_LIBRARIES) - +SET (CMAKE_Fortran_STANDARD_LIBRARIES_INIT "user32.lib") # executable linker flags SET (CMAKE_LINK_DEF_FILE_FLAG "/DEF:") diff --git a/Modules/Platform/Windows-wcl386.cmake b/Modules/Platform/Windows-wcl386.cmake index afc32dd..89c2697 100644 --- a/Modules/Platform/Windows-wcl386.cmake +++ b/Modules/Platform/Windows-wcl386.cmake @@ -22,8 +22,8 @@ SET (CMAKE_C_FLAGS_DEBUG_INIT "-br -bm -od") SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "-br -bm -os -dNDEBUG") SET (CMAKE_C_FLAGS_RELEASE_INIT "-br -bm -ot -dNDEBUG") SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-br -bm -ot -dNDEBUG") -SET (CMAKE_STANDARD_LIBRARIES "library clbrdll.lib library plbrdll.lib library kernel32.lib library user32.lib library gdi32.lib library winspool.lib library comdlg32.lib library advapi32.lib library shell32.lib library ole32.lib library oleaut32.lib library uuid.lib library odbc32.lib library odbccp32.lib" CACHE STRING - "Libraries linked by defalut with all applications.") +SET (CMAKE_C_STANDARD_LIBRARIES_INIT "library clbrdll.lib library plbrdll.lib library kernel32.lib library user32.lib library gdi32.lib library winspool.lib library comdlg32.lib library advapi32.lib library shell32.lib library ole32.lib library oleaut32.lib library uuid.lib library odbc32.lib library odbccp32.lib") +SET (CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}") SET(CMAKE_C_LINK_EXECUTABLE "wlink ${CMAKE_START_TEMP_FILE} ${CMAKE_WLINK_QUIET} name option caseexact file {} ${CMAKE_END_TEMP_FILE}") diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 6952338..e802066 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1349,9 +1349,15 @@ void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout, } fout << " "; } - if(this->Makefile->GetDefinition("CMAKE_STANDARD_LIBRARIES")) + + // Add standard libraries for this language. + std::string standardLibsVar = "CMAKE_"; + standardLibsVar += linkLanguage; + standardLibsVar += "_STANDARD_LIBRARIES"; + if(const char* stdLibs = + this->Makefile->GetDefinition(standardLibsVar.c_str())) { - fout << this->Makefile->GetDefinition("CMAKE_STANDARD_LIBRARIES") << " "; + fout << stdLibs << " "; } } diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx index b6fd4f8..6fa2a9a 100644 --- a/Source/cmLocalVisualStudio6Generator.cxx +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -1059,17 +1059,38 @@ void cmLocalVisualStudio6Generator libMultiLineOptionsForDebug += extraLinkOptions; libMultiLineOptionsForDebug += " \n"; } - if(const char* stdLibs = this->Makefile->GetDefinition("CMAKE_STANDARD_LIBRARIES")) + if(target.GetType() >= cmTarget::EXECUTABLE && + target.GetType() <= cmTarget::MODULE_LIBRARY) { - libOptions += " "; - libOptions += stdLibs; - libOptions += " "; - libMultiLineOptions += "# ADD LINK32 "; - libMultiLineOptions += stdLibs; - libMultiLineOptions += " \n"; - libMultiLineOptionsForDebug += "# ADD LINK32 "; - libMultiLineOptionsForDebug += stdLibs; - libMultiLineOptionsForDebug += " \n"; + // Get the language to use for linking. + const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator()); + if(!linkLanguage) + { + cmSystemTools::Error("CMake can not determine linker language for target:", + target.GetName()); + return; + } + + // Compute the variable name to lookup standard libraries for this + // language. + std::string standardLibsVar = "CMAKE_"; + standardLibsVar += linkLanguage; + standardLibsVar += "_STANDARD_LIBRARIES"; + + // Add standard libraries. + if(const char* stdLibs = + this->Makefile->GetDefinition(standardLibsVar.c_str())) + { + libOptions += " "; + libOptions += stdLibs; + libOptions += " "; + libMultiLineOptions += "# ADD LINK32 "; + libMultiLineOptions += stdLibs; + libMultiLineOptions += " \n"; + libMultiLineOptionsForDebug += "# ADD LINK32 "; + libMultiLineOptionsForDebug += stdLibs; + libMultiLineOptionsForDebug += " \n"; + } } if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS")) { diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index c619660..dd47fa2 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -667,6 +667,21 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, std::vector linkDirs; this->ComputeLinkInformation(target, configName, linkLibs, linkDirs); + // Get the language to use for linking. + const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator()); + if(!linkLanguage) + { + cmSystemTools::Error("CMake can not determine linker language for target:", + target.GetName()); + return; + } + + // Compute the variable name to lookup standard libraries for this + // language. + std::string standardLibsVar = "CMAKE_"; + standardLibsVar += linkLanguage; + standardLibsVar += "_STANDARD_LIBRARIES"; + fout << "\t\t\tMakefile->GetRequiredDefinition("CMAKE_STANDARD_LIBRARIES") + << this->Makefile->GetSafeDefinition(standardLibsVar.c_str()) << " "; this->OutputLibraries(fout, linkLibs); fout << "\"\n"; @@ -709,13 +724,6 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, { fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n"; } - const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator()); - if(!linkLanguage) - { - cmSystemTools::Error("CMake can not determine linker language for target:", - target.GetName()); - return; - } std::string stackVar = "CMAKE_"; stackVar += linkLanguage; stackVar += "_STACK_SIZE"; @@ -739,6 +747,21 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, std::vector linkDirs; this->ComputeLinkInformation(target, configName, linkLibs, linkDirs); + // Get the language to use for linking. + const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator()); + if(!linkLanguage) + { + cmSystemTools::Error("CMake can not determine linker language for target:", + target.GetName()); + return; + } + + // Compute the variable name to lookup standard libraries for this + // language. + std::string standardLibsVar = "CMAKE_"; + standardLibsVar += linkLanguage; + standardLibsVar += "_STANDARD_LIBRARIES"; + fout << "\t\t\tMakefile->GetRequiredDefinition("CMAKE_STANDARD_LIBRARIES") + << this->Makefile->GetSafeDefinition(standardLibsVar.c_str()) << " "; this->OutputLibraries(fout, linkLibs); fout << "\"\n"; @@ -783,13 +806,6 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, { fout << "\t\t\t\tSubSystem=\"1\"\n"; } - const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator()); - if(!linkLanguage) - { - cmSystemTools::Error("CMake can not determine linker language for target:", - target.GetName()); - return; - } std::string stackVar = "CMAKE_"; stackVar += linkLanguage; stackVar += "_STACK_SIZE"; -- cgit v0.12