Depends.cmake
1 # ==============================================================================
2 # Medical Image Registration ToolKit (MIRTK)
3 #
4 # Copyright 2013-2016 Imperial College London
5 # Copyright 2013-2016 Andreas Schuh
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
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 # @file Depends.cmake
22 # @brief Find additional dependencies.
23 #
24 # This file is included by basis_project_impl() after it included the
25 # BasisProject.cmake file of the project and collected information about its
26 # modules. Furthermore, it is included before it looks for the packages
27 # specified as arguments to the basis_project() command. At this point, the
28 # CMake project is not initialized yet and most BASIS variables are not set.
29 #
30 # Use this file to find additional dependencies or dependencies which are
31 # only required by a project if certain modules are enabled.
32 #
33 # Use case: If this project has a module which is a Slicer Extension
34 # and the project itself shall be build as Slicer Extension only if the
35 # module is enabled, the Slicer package configuration file has to be
36 # included here such that the Slicer settings are imported before any
37 # module is configured. This is done by using the command
38 #
39 # Another use case would be that you want to specify advanced options to
40 # the basis_find_package() function which you cannot specify as part of
41 # the dependencies arguments of the basis_project() function.
42 #
43 # Example:
44 # @code
45 # if (SlicerExtension_ENABLED)
46 # # requires Slicer if the SlicerExtension module is enabled
47 # basis_find_package (Slicer REQUIRED)
48 # basis_use_package (Slicer)
49 # endif ()
50 # @endcode
51 #
52 # @ingroup BasisSettings
53 ##############################################################################
54 
55 # Directory with source files of third-party libraries
56 set(MIRTK_THIRDPARTY_DIR "${MIRTK_SOURCE_DIR}/ThirdParty")
57 
58 
59 # ------------------------------------------------------------------------------
60 # libLBFGS (optional)
61 set(LBFGS_SOURCE_DIR "${MIRTK_THIRDPARTY_DIR}/LBFGS")
62 
63 # Set default for WITH_LibLBFGS option
64 if (NOT DEFINED WITH_LBFGS_DEFAULT AND EXISTS "${LBFGS_SOURCE_DIR}/CMakeLists.txt")
65  set(WITH_LBFGS_DEFAULT ON)
66 endif ()
67 
68 # When third-party submodule is available and library is needed
69 if ((DEFINED WITH_LBFGS AND WITH_LBFGS) OR (NOT DEFINED WITH_LBFGS AND WITH_LBFGS_DEFAULT))
70  basis_check_if_package_is_needed_by_modules(is_needed LBFGS)
71  if (is_needed AND EXISTS "${LBFGS_SOURCE_DIR}/CMakeLists.txt")
72  message(STATUS "Configuring module ThirdParty/LBFGS...")
73  set(LBFGS_INSTALL_HEADERS FALSE)
74  set(LBFGS_INSTALL_STATIC_LIBS TRUE) # needed because of CMake install(EXPORT)
75  set(LBFGS_INSTALL_LIBRARY_DIR ${INSTALL_LIBRARY_DIR})
76  set(LBFGS_lib_TARGET_NAME LibLBFGS)
77  basis_add_export_target(export_args ${LBFGS_lib_TARGET_NAME} FALSE ${LBFGS_INSTALL_STATIC_LIBS})
78  if (export_args)
79  list(GET export_args 1 LBFGS_EXPORT_NAME)
80  else ()
81  set(LBFGS_EXPORT_NAME)
82  endif ()
83  add_subdirectory("${LBFGS_SOURCE_DIR}" "${MIRTK_BINARY_DIR}/ThirdParty/LBFGS")
84  set_target_properties(${LBFGS_lib_TARGET_NAME} PROPERTIES OUTPUT_NAME MIRTKlbfgs)
85  set(LBFGS_FOUND TRUE)
86  set(LBFGS_LIBRARIES ${LBFGS_lib_TARGET_NAME})
87  set(LBFGS_INCLUDE_DIR "${LBFGS_SOURCE_DIR}/include")
88  set(LBFGS_DIR "${MIRTK_BINARY_DIR}/ThirdParty/LBFGS")
89  message(STATUS "Configuring module ThirdParty/LBFGS... - done")
90  endif ()
91  unset(is_needed)
92 endif ()