summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-07-23 14:07:25 (GMT)
committerBrad King <brad.king@kitware.com>2009-07-23 14:07:25 (GMT)
commit07ea19ad1f280e7a1cb07ab2b52c0081f72251dd (patch)
tree3844b6660772215cdae9420ddcfa3574be35e8db /Modules
parent797e49a1cc53fb120fad286665c875075eb18361 (diff)
downloadCMake-07ea19ad1f280e7a1cb07ab2b52c0081f72251dd.zip
CMake-07ea19ad1f280e7a1cb07ab2b52c0081f72251dd.tar.gz
CMake-07ea19ad1f280e7a1cb07ab2b52c0081f72251dd.tar.bz2
ENH: Implicit link info for C, CXX, and Fortran
This teaches CMake to detect implicit link information for C, C++, and Fortran compilers. We detect the implicit linker search directories and implicit linker options for UNIX-like environments using verbose output from compiler front-ends. We store results in new variables called CMAKE_<LANG>_IMPLICIT_LINK_LIBRARIES CMAKE_<LANG>_IMPLICIT_LINK_DIRECTORIES The implicit libraries can contain linker flags as well as library names.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CMakeCCompiler.cmake.in3
-rw-r--r--Modules/CMakeCXXCompiler.cmake.in3
-rw-r--r--Modules/CMakeDetermineCompilerABI.cmake13
-rw-r--r--Modules/CMakeFortranCompiler.cmake.in3
-rw-r--r--Modules/CMakeParseImplicitLinkInfo.cmake71
-rw-r--r--Modules/Compiler/GNU-C.cmake1
-rw-r--r--Modules/Compiler/GNU-CXX.cmake1
-rw-r--r--Modules/Compiler/GNU-Fortran.cmake1
-rw-r--r--Modules/Compiler/HP-C.cmake1
-rw-r--r--Modules/Compiler/HP-CXX.cmake1
-rw-r--r--Modules/Compiler/HP-Fortran.cmake1
-rw-r--r--Modules/Compiler/MIPSpro-C.cmake1
-rw-r--r--Modules/Compiler/MIPSpro-CXX.cmake1
-rw-r--r--Modules/Compiler/MIPSpro-Fortran.cmake1
-rw-r--r--Modules/Compiler/SunPro-C.cmake1
-rw-r--r--Modules/Compiler/SunPro-CXX.cmake1
-rw-r--r--Modules/Compiler/SunPro-Fortran.cmake1
-rw-r--r--Modules/Compiler/VisualAge-C.cmake1
-rw-r--r--Modules/Compiler/VisualAge-CXX.cmake1
-rw-r--r--Modules/Compiler/VisualAge-Fortran.cmake1
20 files changed, 108 insertions, 0 deletions
diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in
index e334c47..209a33f 100644
--- a/Modules/CMakeCCompiler.cmake.in
+++ b/Modules/CMakeCCompiler.cmake.in
@@ -34,3 +34,6 @@ ENDIF(CMAKE_C_SIZEOF_DATA_PTR)
IF(CMAKE_C_COMPILER_ABI)
SET(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}")
ENDIF(CMAKE_C_COMPILER_ABI)
+
+SET(CMAKE_C_IMPLICIT_LINK_LIBRARIES "@CMAKE_C_IMPLICIT_LINK_LIBRARIES@")
+SET(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "@CMAKE_C_IMPLICIT_LINK_DIRECTORIES@")
diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in
index 81380c9..d87c788 100644
--- a/Modules/CMakeCXXCompiler.cmake.in
+++ b/Modules/CMakeCXXCompiler.cmake.in
@@ -34,3 +34,6 @@ ENDIF(CMAKE_CXX_SIZEOF_DATA_PTR)
IF(CMAKE_CXX_COMPILER_ABI)
SET(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_CXX_COMPILER_ABI}")
ENDIF(CMAKE_CXX_COMPILER_ABI)
+
+SET(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "@CMAKE_CXX_IMPLICIT_LINK_LIBRARIES@")
+SET(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "@CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES@")
diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake
index 3fd06a9..d519237 100644
--- a/Modules/CMakeDetermineCompilerABI.cmake
+++ b/Modules/CMakeDetermineCompilerABI.cmake
@@ -3,6 +3,8 @@
# This is used internally by CMake and should not be included by user
# code.
+INCLUDE(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
+
FUNCTION(CMAKE_DETERMINE_COMPILER_ABI lang src)
IF(NOT DEFINED CMAKE_DETERMINE_${lang}_ABI_COMPILED)
MESSAGE(STATUS "Detecting ${lang} compiler ABI info")
@@ -11,6 +13,8 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ABI lang src)
SET(BIN "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeDetermineCompilerABI_${lang}.bin")
TRY_COMPILE(CMAKE_DETERMINE_${lang}_ABI_COMPILED
${CMAKE_BINARY_DIR} ${src}
+ CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_${lang}_VERBOSE_FLAG}"
+ "-DCMAKE_${lang}_STANDARD_LIBRARIES="
OUTPUT_VARIABLE OUTPUT
COPY_FILE "${BIN}"
)
@@ -40,6 +44,15 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ABI lang src)
SET(CMAKE_INTERNAL_PLATFORM_ABI "${ABI_NAME}" PARENT_SCOPE)
ENDIF(ABI_NAME)
+ # Parse implicit linker information for this language, if available.
+ SET(implicit_dirs "")
+ SET(implicit_libs "")
+ IF(CMAKE_${lang}_VERBOSE_FLAG)
+ CMAKE_PARSE_IMPLICIT_LINK_INFO("${OUTPUT}" implicit_libs implicit_dirs)
+ ENDIF()
+ SET(CMAKE_${lang}_IMPLICIT_LINK_LIBRARIES "${implicit_libs}" PARENT_SCOPE)
+ SET(CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES "${implicit_dirs}" PARENT_SCOPE)
+
ELSE(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
MESSAGE(STATUS "Detecting ${lang} compiler ABI info - failed")
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in
index 65cfda7..afd9ce0 100644
--- a/Modules/CMakeFortranCompiler.cmake.in
+++ b/Modules/CMakeFortranCompiler.cmake.in
@@ -27,3 +27,6 @@ IF(UNIX)
ELSE(UNIX)
SET(CMAKE_Fortran_OUTPUT_EXTENSION .obj)
ENDIF(UNIX)
+
+SET(CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "@CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES@")
+SET(CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES "@CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES@")
diff --git a/Modules/CMakeParseImplicitLinkInfo.cmake b/Modules/CMakeParseImplicitLinkInfo.cmake
new file mode 100644
index 0000000..b56781f
--- /dev/null
+++ b/Modules/CMakeParseImplicitLinkInfo.cmake
@@ -0,0 +1,71 @@
+
+# Function parse implicit linker options.
+# This is used internally by CMake and should not be included by user
+# code.
+
+function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var)
+ set(implicit_libs "")
+ set(implicit_dirs_tmp)
+
+ # Parse implicit linker arguments.
+ set(linker "CMAKE_LINKER-NOTFOUND")
+ if(CMAKE_LINKER)
+ get_filename_component(linker ${CMAKE_LINKER} NAME)
+ endif()
+ set(linker_regex "/(${linker}|ld|collect2)")
+ string(REGEX REPLACE "\r?\n" ";" output_lines "${text}")
+ foreach(line IN LISTS output_lines)
+ set(cmd)
+ if("${line}" MATCHES "${linker_regex}")
+ if(UNIX)
+ separate_arguments(args UNIX_COMMAND "${line}")
+ else()
+ separate_arguments(args WINDOWS_COMMAND "${line}")
+ endif()
+ list(GET args 0 cmd)
+ endif()
+ if("${cmd}" MATCHES "${linker_regex}")
+ string(REGEX REPLACE ";-([LY]);" ";-\\1" args "${args}")
+ foreach(arg IN LISTS args)
+ if("${arg}" MATCHES "^-L(.:)?[/\\]")
+ # Unix search path.
+ string(REGEX REPLACE "^-L" "" dir "${arg}")
+ list(APPEND implicit_dirs_tmp ${dir})
+ elseif("${arg}" MATCHES "^-l[^:]")
+ # Unix library.
+ string(REGEX REPLACE "^-l" "" lib "${arg}")
+ list(APPEND implicit_libs ${lib})
+ elseif("${arg}" MATCHES "^(.:)?[/\\].*\\.a$")
+ # Unix library full path.
+ list(APPEND implicit_libs ${arg})
+ elseif("${arg}" MATCHES "^-Y(P,)?")
+ # Sun search path.
+ string(REGEX REPLACE "^-Y(P,)?" "" dirs "${arg}")
+ string(REPLACE ":" ";" dirs "${dirs}")
+ list(APPEND implicit_dirs_tmp ${dirs})
+ elseif("${arg}" MATCHES "^-l:")
+ # HP named library.
+ list(APPEND implicit_libs ${arg})
+ endif()
+ endforeach()
+ break()
+ elseif("${line}" MATCHES "LPATH(=| is:? )")
+ # HP search path.
+ string(REGEX REPLACE ".*LPATH(=| is:? *)" "" paths "${line}")
+ string(REPLACE ":" ";" paths "${paths}")
+ list(APPEND implicit_dirs_tmp ${paths})
+ endif()
+ endforeach()
+
+ # Cleanup list of directories.
+ set(implicit_dirs "")
+ foreach(d IN LISTS implicit_dirs_tmp)
+ get_filename_component(dir "${d}" ABSOLUTE)
+ list(APPEND implicit_dirs "${dir}")
+ endforeach()
+ list(REMOVE_DUPLICATES implicit_dirs)
+
+ # Return results.
+ set(${lib_var} "${implicit_libs}" PARENT_SCOPE)
+ set(${dir_var} "${implicit_dirs}" PARENT_SCOPE)
+endfunction()
diff --git a/Modules/Compiler/GNU-C.cmake b/Modules/Compiler/GNU-C.cmake
new file mode 100644
index 0000000..abf384a
--- /dev/null
+++ b/Modules/Compiler/GNU-C.cmake
@@ -0,0 +1 @@
+SET(CMAKE_C_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/GNU-CXX.cmake b/Modules/Compiler/GNU-CXX.cmake
new file mode 100644
index 0000000..f3c6b5f
--- /dev/null
+++ b/Modules/Compiler/GNU-CXX.cmake
@@ -0,0 +1 @@
+SET(CMAKE_CXX_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/GNU-Fortran.cmake b/Modules/Compiler/GNU-Fortran.cmake
new file mode 100644
index 0000000..7f7c128
--- /dev/null
+++ b/Modules/Compiler/GNU-Fortran.cmake
@@ -0,0 +1 @@
+SET(CMAKE_Fortran_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/HP-C.cmake b/Modules/Compiler/HP-C.cmake
new file mode 100644
index 0000000..abf384a
--- /dev/null
+++ b/Modules/Compiler/HP-C.cmake
@@ -0,0 +1 @@
+SET(CMAKE_C_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/HP-CXX.cmake b/Modules/Compiler/HP-CXX.cmake
new file mode 100644
index 0000000..f3c6b5f
--- /dev/null
+++ b/Modules/Compiler/HP-CXX.cmake
@@ -0,0 +1 @@
+SET(CMAKE_CXX_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/HP-Fortran.cmake b/Modules/Compiler/HP-Fortran.cmake
new file mode 100644
index 0000000..7f7c128
--- /dev/null
+++ b/Modules/Compiler/HP-Fortran.cmake
@@ -0,0 +1 @@
+SET(CMAKE_Fortran_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/MIPSpro-C.cmake b/Modules/Compiler/MIPSpro-C.cmake
new file mode 100644
index 0000000..abf384a
--- /dev/null
+++ b/Modules/Compiler/MIPSpro-C.cmake
@@ -0,0 +1 @@
+SET(CMAKE_C_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/MIPSpro-CXX.cmake b/Modules/Compiler/MIPSpro-CXX.cmake
new file mode 100644
index 0000000..f3c6b5f
--- /dev/null
+++ b/Modules/Compiler/MIPSpro-CXX.cmake
@@ -0,0 +1 @@
+SET(CMAKE_CXX_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/MIPSpro-Fortran.cmake b/Modules/Compiler/MIPSpro-Fortran.cmake
new file mode 100644
index 0000000..7f7c128
--- /dev/null
+++ b/Modules/Compiler/MIPSpro-Fortran.cmake
@@ -0,0 +1 @@
+SET(CMAKE_Fortran_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/SunPro-C.cmake b/Modules/Compiler/SunPro-C.cmake
new file mode 100644
index 0000000..2c60b89
--- /dev/null
+++ b/Modules/Compiler/SunPro-C.cmake
@@ -0,0 +1 @@
+SET(CMAKE_C_VERBOSE_FLAG "-#")
diff --git a/Modules/Compiler/SunPro-CXX.cmake b/Modules/Compiler/SunPro-CXX.cmake
new file mode 100644
index 0000000..f3c6b5f
--- /dev/null
+++ b/Modules/Compiler/SunPro-CXX.cmake
@@ -0,0 +1 @@
+SET(CMAKE_CXX_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/SunPro-Fortran.cmake b/Modules/Compiler/SunPro-Fortran.cmake
new file mode 100644
index 0000000..7f7c128
--- /dev/null
+++ b/Modules/Compiler/SunPro-Fortran.cmake
@@ -0,0 +1 @@
+SET(CMAKE_Fortran_VERBOSE_FLAG "-v")
diff --git a/Modules/Compiler/VisualAge-C.cmake b/Modules/Compiler/VisualAge-C.cmake
new file mode 100644
index 0000000..3120478
--- /dev/null
+++ b/Modules/Compiler/VisualAge-C.cmake
@@ -0,0 +1 @@
+SET(CMAKE_C_VERBOSE_FLAG "-V")
diff --git a/Modules/Compiler/VisualAge-CXX.cmake b/Modules/Compiler/VisualAge-CXX.cmake
new file mode 100644
index 0000000..618ff5a
--- /dev/null
+++ b/Modules/Compiler/VisualAge-CXX.cmake
@@ -0,0 +1 @@
+SET(CMAKE_CXX_VERBOSE_FLAG "-V")
diff --git a/Modules/Compiler/VisualAge-Fortran.cmake b/Modules/Compiler/VisualAge-Fortran.cmake
new file mode 100644
index 0000000..5ae3895
--- /dev/null
+++ b/Modules/Compiler/VisualAge-Fortran.cmake
@@ -0,0 +1 @@
+SET(CMAKE_Fortran_VERBOSE_FLAG "-V")