CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkLinkerAsNeededFlagCheck.cmake
Go to the documentation of this file.
1 ###########################################################################
2 #
3 # Library: CTK
4 #
5 # Copyright (c) Kitware Inc.
6 #
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
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0.txt
12 #
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.
18 #
19 ###########################################################################
20 
21 #
22 # Linker --as-needed flag check
23 #
24 # Check if the linker will resolve symbols of underlinked libraries
25 #
26 # This script set the variable CTK_LINKER_NO_AS_NEEDED_FLAG_REQUIRED
27 # to either TRUE or FALSE.
28 #
29 
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}
38  LINK_TEST
39  )
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")
43  else()
44  try_compile(CTK_LINKER_NO_AS_NEEDED_LINKS_UNDERLINKED_LIBS
45  ${LINK_TEST_BINARY_DIR}
46  ${LINK_TEST_SOURCE_DIR}
47  LINK_TEST_FLAGS
48  CMAKE_FLAGS -DCMAKE_EXE_LINKER_FLAGS=-Wl,--no-as-needed
49  )
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")
53  else()
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.")
58  endif()
59  endif()
60 endif()