1 ###########################################################################
5 # Copyright (c) Kitware Inc.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0.txt
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 ###########################################################################
22 # Linker --as-needed flag check
24 # Check if the linker will resolve symbols of underlinked libraries
26 # This script set the variable CTK_LINKER_NO_AS_NEEDED_FLAG_REQUIRED
27 # to either TRUE or FALSE.
30 if(NOT DEFINED CTK_LINKER_NO_AS_NEEDED_FLAG_REQUIRED)
31 message(STATUS "Checking if --no-as-needed linker flag is required")
32 set(LINK_TEST_SOURCE_DIR ${CTK_CMAKE_DIR}/ctkLinkerAsNeededFlagCheck)
33 set(LINK_TEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ctkLinkerAsNeededFlagCheck)
34 execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ${LINK_TEST_BINARY_DIR})
35 try_compile(CTK_LINKER_LINKS_UNDERLINKED_LIBS
36 ${LINK_TEST_BINARY_DIR}
37 ${LINK_TEST_SOURCE_DIR}
40 if(CTK_LINKER_LINKS_UNDERLINKED_LIBS)
41 set(CTK_LINKER_NO_AS_NEEDED_FLAG_REQUIRED FALSE CACHE INTERNAL "Test CTK_LINKER_NO_AS_NEEDED_FLAG_REQUIRED")
42 message(STATUS "Checking if --no-as-needed linker flag is required - no")
44 try_compile(CTK_LINKER_NO_AS_NEEDED_LINKS_UNDERLINKED_LIBS
45 ${LINK_TEST_BINARY_DIR}
46 ${LINK_TEST_SOURCE_DIR}
48 CMAKE_FLAGS -DCMAKE_EXE_LINKER_FLAGS=-Wl,--no-as-needed
50 if(CTK_LINKER_NO_AS_NEEDED_LINKS_UNDERLINKED_LIBS)
51 set(CTK_LINKER_NO_AS_NEEDED_FLAG_REQUIRED TRUE CACHE INTERNAL "Test CTK_LINKER_NO_AS_NEEDED_FLAG_REQUIRED")
52 message(STATUS "Checking if --no-as-needed linker flag is required - yes")
54 message(STATUS "Checking if --no-as-needed linker flag is required - failed.")
55 message(WARNING "Could not compile test code."
56 "Linker could fail trying to resolve symbols for underlinked libraries."
57 "See issue 2321 (http://na-mic.org/Mantis/view.php?id=2321) for more details.")