summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeDetermineCompilerId.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-09-30 17:42:50 (GMT)
committerBrad King <brad.king@kitware.com>2015-09-30 19:01:23 (GMT)
commit8b4873a1b025d7f47c90f3cafc93ca152b9e4652 (patch)
treebfbccc8785c7852687be5a6fafcde4dd9707805b /Modules/CMakeDetermineCompilerId.cmake
parente90f463a312e18fd6498799de1522b96d84fd012 (diff)
downloadCMake-8b4873a1b025d7f47c90f3cafc93ca152b9e4652.zip
CMake-8b4873a1b025d7f47c90f3cafc93ca152b9e4652.tar.gz
CMake-8b4873a1b025d7f47c90f3cafc93ca152b9e4652.tar.bz2
Disable shared library support when compiler links statically
When a user or a compiler wrapper adds '-static' to the compiler flags then it will always link static binaries. Detect this from the compiler id binary and disable TARGET_SUPPORTS_SHARED_LIBS. This will prevent projects from accidentally adding shared libraries when the toolchain does not support them. It also helps CMake avoid linking with flags that require shared libraries to be supported.
Diffstat (limited to 'Modules/CMakeDetermineCompilerId.cmake')
-rw-r--r--Modules/CMakeDetermineCompilerId.cmake8
1 files changed, 8 insertions, 0 deletions
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
index df6daf3..591ecb8 100644
--- a/Modules/CMakeDetermineCompilerId.cmake
+++ b/Modules/CMakeDetermineCompilerId.cmake
@@ -106,6 +106,7 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
set(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}"
PARENT_SCOPE)
set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "${CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX}" PARENT_SCOPE)
+ set(CMAKE_${lang}_COMPILER_LINKS_STATICALLY "${CMAKE_${lang}_COMPILER_LINKS_STATICALLY}" PARENT_SCOPE)
set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE)
set(CMAKE_${lang}_SIMULATE_ID "${CMAKE_${lang}_SIMULATE_ID}" PARENT_SCOPE)
set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
@@ -529,6 +530,13 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
endif()
endif()
+ if(UNIX)
+ execute_process(COMMAND file "${file}" OUTPUT_VARIABLE out ERROR_VARIABLE out)
+ if(out MATCHES "statically linked")
+ set(CMAKE_${lang}_COMPILER_LINKS_STATICALLY 1 PARENT_SCOPE)
+ endif()
+ endif()
+
# Check if a valid compiler and platform were found.
if(COMPILER_ID AND NOT COMPILER_ID_TWICE)
set(CMAKE_${lang}_COMPILER_ID "${COMPILER_ID}")