CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkMacroBFDCheck.cmake
Go to the documentation of this file.
1 #
2 # ctkMacroBFDCheck.cmake - After this file is included into your main CMake script,
3 # HAVE_BFD will be defined if libbfd is available.
4 #
5 
6 if(CTK_LIB_Core_WITH_BFD_STATIC AND CTK_LIB_Core_WITH_BFD_SHARED)
7  message(FATAL_ERROR "error: Options WITH_BFD_STATIC and WITH_BFD_SHARED are mutually exclusive ! "
8  "hint: Enable either WITH_BFD_STATIC or WITH_BFD_SHARED.")
9 endif()
10 
11 if(NOT CTK_BUILD_SHARED_LIBS AND CTK_LIB_Core_WITH_BFD_SHARED)
12  message(FATAL_ERROR "error: Options CTK_BUILD_SHARED_LIBS and WITH_BFD_STATIC are mutually exclusive ! "
13  "hint: Disable WITH_BFD_SHARED and enable WITH_BFD_STATIC if needed.")
14 endif()
15 
16 set(BFD_LIBRARIES)
17 unset(HAVE_BFD CACHE)
18 
19 set(TestBFD_BUILD_LOG "${CMAKE_CURRENT_BINARY_DIR}/CMake/TestBFD-build-log.txt")
20 
21 if(CTK_LIB_Core_WITH_BFD_STATIC OR CTK_LIB_Core_WITH_BFD_SHARED)
22  if(WIN32)
23  message(FATAL_ERROR "error: Options WITH_BFD_STATIC or WITH_BFD_SHARED are not support on Windows !")
24  endif()
25 
26  if(NOT WIN32)
27  include(CheckIncludeFile)
28  CHECK_INCLUDE_file(bfd.h HAVE_BFD_HEADER)
29  if(NOT HAVE_BFD_HEADER)
30  file(WRITE ${TestBFD_BUILD_LOG} "Could *NOT* find the required header file: bfd.h")
31  endif()
32 
33  set(BFD_LIBRARY_NAME libbfd.a)
34  set(TestBFD_LIBRARY_MODE STATIC)
35  if(CTK_LIB_Core_WITH_BFD_SHARED)
36  set(BFD_LIBRARY_NAME libbfd${CMAKE_SHARED_LIBRARY_SUFFIX})
37  set(TestBFD_LIBRARY_MODE SHARED)
38  endif()
39  unset(BFD_LIBRARY CACHE)
40  find_library(BFD_LIBRARY ${BFD_LIBRARY_NAME})
41  if(NOT BFD_LIBRARY)
42  file(WRITE ${TestBFD_BUILD_LOG} "Could *NOT* find the required bfd library: ${BFD_LIBRARY_NAME}")
43  endif()
44 
45  if(HAVE_BFD_HEADER AND BFD_LIBRARY)
46  # make sure we can build with libbfd
47  #message(STATUS "Checking libbfd")
48  try_compile(HAVE_BFD
49  ${CMAKE_CURRENT_BINARY_DIR}/CMake/TestBFD
50  ${CMAKE_CURRENT_SOURCE_DIR}/CMake/TestBFD
51  TestBFD
52  CMAKE_FLAGS
53  -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
54  -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
55  -DBFD_LIBRARY_NAME:STRING=${BFD_LIBRARY_NAME}
56  OUTPUT_VARIABLE OUTPUT)
57  file(WRITE ${TestBFD_BUILD_LOG} ${OUTPUT})
58  #message(${OUTPUT})
59 
60  if(HAVE_BFD)
61  set(BFD_LIBRARIES ${BFD_LIBRARY})
62  endif()
63  endif()
64  endif()
65 
66 endif()
67 
68 if(CTK_LIB_Core_WITH_BFD_SHARED AND NOT HAVE_BFD)
69  message(WARNING "warning: CTKCore: Failed to enable BFD support. Disabling CTKCore WITH_BFD_SHARED library option. "
70  "See ${TestBFD_BUILD_LOG} for more details.")
71  set(CTK_LIB_Core_WITH_BFD_SHARED OFF CACHE BOOL "Enable CTKCore Library WITH_BFD_SHARED option" FORCE)
72 endif()
73 if(CTK_LIB_Core_WITH_BFD_STATIC AND NOT HAVE_BFD)
74  message(WARNING "warning: CTKCore: Failed to enable BFD support. Disabling CTKCore WITH_BFD_STATIC library option. "
75  "See ${TestBFD_BUILD_LOG} for more details.")
76  set(CTK_LIB_Core_WITH_BFD_STATIC OFF CACHE BOOL "Enable CTKCore Library WITH_BFD_STATIC option" FORCE)
77 endif()
78 
79 if(HAVE_BFD)
80  message(STATUS "CTKCore: BFD support enabled [${BFD_LIBRARIES}]")
81 else()
82  message(STATUS "CTKCore: BFD support disabled")
83 endif()