1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
#
# Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
#
# This file is part of Orfeo Toolbox
#
# https://www.orfeo-toolbox.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This script sorts out the module dependencies, provides user options for customizing
# the list of modules to be built, and enables modules accordingly.
# Load the module DAG.
set(OTB_MODULES_ALL)
file(GLOB meta RELATIVE "${OTB_SOURCE_DIR}"
"${OTB_SOURCE_DIR}/*/*/*/otb-module.cmake" # grouped modules
)
foreach(f ${meta})
include(${OTB_SOURCE_DIR}/${f})
list(APPEND OTB_MODULES_ALL ${otb-module})
get_filename_component(${otb-module}_BASE ${f} PATH)
set(${otb-module}_SOURCE_DIR ${OTB_SOURCE_DIR}/${${otb-module}_BASE})
set(${otb-module}_BINARY_DIR ${OTB_BINARY_DIR}/${${otb-module}_BASE})
if(BUILD_TESTING AND EXISTS ${${otb-module}_SOURCE_DIR}/test)
list(APPEND OTB_MODULES_ALL ${otb-module-test})
set(${otb-module-test}_SOURCE_DIR ${${otb-module}_SOURCE_DIR}/test)
set(${otb-module-test}_BINARY_DIR ${${otb-module}_BINARY_DIR}/test)
set(${otb-module-test}_IS_TEST 1)
set(${otb-module}_TESTED_BY ${otb-module-test})
set(${otb-module-test}_TESTS_FOR ${otb-module})
endif()
# Exclude remote modules from default modules so that they are
# enabled/disabled using their variable Module_XXXX
get_filename_component(_group ${${otb-module}_BASE} PATH)
get_filename_component(_group ${_group} NAME)
if("${_group}" STREQUAL "Remote")
set(OTB_MODULE_${otb-module}_EXCLUDE_FROM_DEFAULT 1)
endif()
# Reject bad dependencies.
string(REGEX MATCHALL ";(OTBDeprecated|OTBReview|OTBIntegratedTest);"
_bad_deps ";${OTB_MODULE_${otb-module}_DEPENDS};${OTB_MODULE_${otb-module-test}_DEPENDS};")
foreach(dep ${_bad_deps})
if(NOT "${otb-module}" MATCHES "^(${dep}|OTBIntegratedTest)$")
message(FATAL_ERROR
"Module \"${otb-module}\" loaded from\n"
" ${${otb-module}_BASE}/otb-module.cmake\n"
"may not depend on module \"${dep}\".")
endif()
endforeach()
endforeach()
# Clear variables set later in each module.
unset(otb-module)
unset(otb-module-test)
# Validate the module DAG.
macro(otb_module_check otb-module _needed_by stack)
if(NOT OTB_MODULE_${otb-module}_DECLARED)
message(FATAL_ERROR "No such module \"${otb-module}\" needed by \"${_needed_by}\"")
endif()
if(check_started_${otb-module} AND NOT check_finished_${otb-module})
# We reached a module while traversing its own dependencies recursively.
set(msg "")
foreach(entry ${stack})
set(msg " ${entry} =>${msg}")
if("${entry}" STREQUAL "${otb-module}")
break()
endif()
endforeach()
message(FATAL_ERROR "Module dependency cycle detected:\n ${msg} ${otb-module}")
elseif(NOT check_started_${otb-module})
# Traverse dependencies of this module. Mark the start and finish.
set(check_started_${otb-module} 1)
foreach(dep IN LISTS OTB_MODULE_${otb-module}_DEPENDS)
otb_module_check(${dep} ${otb-module} "${otb-module};${stack}")
endforeach()
foreach(dep IN LISTS OTB_MODULE_${otb-module}_OPTIONAL_DEPENDS)
otb_module_check(${dep} ${otb-module} "${otb-module};${stack}")
endforeach()
set(check_finished_${otb-module} 1)
endif()
endmacro()
foreach(otb-module ${OTB_MODULES_ALL})
otb_module_check("${otb-module}" "" "")
endforeach()
#----------------------------------------------------------------------
# Construct direct dependees (first-level) of each module
foreach(otb-module1 ${OTB_MODULES_ALL})
foreach(otb-module2 ${OTB_MODULES_ALL})
list(FIND OTB_MODULE_${otb-module2}_DEPENDS ${otb-module1} _find_output)
if( NOT ${_find_output} EQUAL -1 )
list(APPEND OTB_MODULE_${otb-module1}_DEPENDEES ${otb-module2})
endif()
endforeach()
endforeach()
#----------------------------------------------------------------------
# Provide an option to build the default set of OTB modules. Only a small
# set of modules are excluded and they have the "EXCLUDE_FROM_DEFAULT" tags in
# their module definition file (otb-module.cmake).
#
# However, if you choose to customize which modules will be built, OTB also
# allows you to manually enable modules by using either individual Module_*
# options or OTBGroup_* options.
option(OTB_BUILD_DEFAULT_MODULES "Build the default OTB modules." ON)
#----------------------------------------------------------------------
# Provide an option to build the tests of dependencies of a module when
# BUILD_TESTING is ON.
option(OTB_BUILD_ALL_MODULES_FOR_TESTS "Build the tests of module dependencies." OFF)
mark_as_advanced(OTB_BUILD_ALL_MODULES_FOR_TESTS)
# Provide module selections by groups
include(${OTB_SOURCE_DIR}/CMake/OTBGroups.cmake)
# Provide an option for each module.
foreach(otb-module ${OTB_MODULES_ALL})
if(NOT ${otb-module}_IS_TEST)
option(Module_${otb-module} "Request building ${otb-module}" OFF)
mark_as_advanced(Module_${otb-module})
if(OTB_MODULE_${otb-module}_EXCLUDE_FROM_DEFAULT)
set(OTB_MODULE_${otb-module}_IN_DEFAULT 0)
else()
set(OTB_MODULE_${otb-module}_IN_DEFAULT ${OTB_BUILD_DEFAULT_MODULES})
endif()
endif()
endforeach()
# Follow dependencies.
macro(otb_module_enable otb-module _needed_by)
if(NOT Module_${otb-module})
if(NOT ${otb-module}_TESTED_BY OR
NOT "x${_needed_by}" STREQUAL "x${${otb-module}_TESTED_BY}")
list(APPEND OTB_MODULE_${otb-module}_NEEDED_BY ${_needed_by})
endif()
endif()
if(NOT ${otb-module}_ENABLED)
set(${otb-module}_ENABLED 1)
# if this module has an ACTIVATION_OPTION=OFF, don't bother enable its dependencies
if(NOT (OTB_MODULE_${otb-module}_ACTIVATION_OPTION
AND NOT ${OTB_MODULE_${otb-module}_ACTIVATION_OPTION}))
foreach(dep IN LISTS OTB_MODULE_${otb-module}_DEPENDS)
otb_module_enable(${dep} ${otb-module})
endforeach()
foreach(dep IN LISTS OTB_MODULE_${otb-module}_OPTIONAL_DEPENDS)
otb_module_enable(${dep} ${otb-module})
endforeach()
if(${otb-module}_TESTED_BY AND (OTB_BUILD_DEFAULT_MODULES OR OTB_BUILD_ALL_MODULES_FOR_TESTS OR Module_${otb-module}))
otb_module_enable(${${otb-module}_TESTED_BY} "")
endif()
endif()
endif()
endmacro()
foreach(otb-module ${OTB_MODULES_ALL})
if(Module_${otb-module} OR OTB_MODULE_${otb-module}_IN_DEFAULT)
otb_module_enable("${otb-module}" "")
elseif(OTB_MODULE_${otb-module}_REQUEST_BY)
otb_module_enable("${otb-module}" "${OTB_MODULE_${otb-module}_REQUEST_BY}")
endif()
endforeach()
# Filter out the ENABLED modules using the OTB_USE_XXX options
macro(otb_module_disable otb-module _disabled_by)
if(NOT ${otb-module}_IS_TEST AND ${otb-module}_ENABLED)
message(STATUS "Disabled ${otb-module} because ${_disabled_by} is OFF")
endif()
set(${otb-module}_ENABLED 0)
foreach(otb-module-dependee ${OTB_MODULE_${otb-module}_DEPENDEES})
otb_module_disable(${otb-module-dependee} ${_disabled_by})
endforeach()
endmacro()
foreach(otb-module ${OTB_MODULES_ALL})
if(OTB_MODULE_${otb-module}_ACTIVATION_OPTION
AND NOT ${OTB_MODULE_${otb-module}_ACTIVATION_OPTION})
otb_module_disable("${otb-module}" "${OTB_MODULE_${otb-module}_ACTIVATION_OPTION}")
endif()
endforeach()
# Build final list of enabled modules.
set(OTB_MODULES_ENABLED "")
set(OTB_MODULES_DISABLED "")
foreach(otb-module ${OTB_MODULES_ALL})
if(${otb-module}_ENABLED)
list(APPEND OTB_MODULES_ENABLED ${otb-module})
# We will sort modules according to their dependency graph,
# to enable them in order. To solve the modules dependency graph,
# we join both DEPENDS and OPTIONAL_DEPENDS (if enabled)
set(OTB_MODULE_${otb-module}_DEPENDS_FOR_SORT "")
list(APPEND OTB_MODULE_${otb-module}_DEPENDS_FOR_SORT ${OTB_MODULE_${otb-module}_DEPENDS})
foreach(opt-dep ${OTB_MODULE_${otb-module}_OPTIONAL_DEPENDS})
if(${opt-dep}_ENABLED)
list(APPEND OTB_MODULE_${otb-module}_DEPENDS_FOR_SORT ${opt-dep})
endif()
endforeach()
else()
list(APPEND OTB_MODULES_DISABLED ${otb-module})
endif()
endforeach()
list(SORT OTB_MODULES_ENABLED) # Deterministic order.
list(SORT OTB_MODULES_DISABLED) # Deterministic order.
# Order list to satisfy dependencies.
include(CMake/TopologicalSort.cmake)
topological_sort(OTB_MODULES_ENABLED OTB_MODULE_ _DEPENDS_FOR_SORT)
# Report what will be built.
set(_enabled_modules "${OTB_MODULES_ENABLED}")
list(SORT _enabled_modules)
foreach(otb-module ${_enabled_modules})
if(NOT ${otb-module}_IS_TEST)
if(Module_${otb-module})
set(_reason ", requested by Module_${otb-module}")
elseif(OTB_MODULE_${otb-module}_IN_DEFAULT)
set(_reason ", requested by OTB_BUILD_DEFAULT_MODULES")
else()
set(_reason ", needed by [${OTB_MODULE_${otb-module}_NEEDED_BY}]")
endif()
message(STATUS "Enabled ${otb-module}${_reason}.")
endif()
endforeach()
# Hide options for modules that will build anyway.
foreach(otb-module ${OTB_MODULES_ALL})
if(NOT ${otb-module}_IS_TEST)
if(OTB_MODULE_${otb-module}_IN_DEFAULT OR OTB_MODULE_${otb-module}_NEEDED_BY)
set_property(CACHE Module_${otb-module} PROPERTY TYPE INTERNAL)
else()
set_property(CACHE Module_${otb-module} PROPERTY TYPE BOOL)
endif()
endif()
endforeach()
if(NOT OTB_MODULES_ENABLED)
message(WARNING "No modules enabled!")
file(REMOVE "${OTB_BINARY_DIR}/OTBTargets.cmake")
return()
endif()
file(WRITE "${OTB_BINARY_DIR}/OTBTargets.cmake"
"# Generated by CMake, do not edit!")
macro(init_module_vars)
if( "${otb-module}" STREQUAL "" )
message(FATAL_ERROR "CMake variable otb-module is not set")
endif()
set(${otb-module}-targets OTBTargets)
set(${otb-module}-targets-install "${OTB_INSTALL_PACKAGE_DIR}/OTBTargets.cmake")
set(${otb-module}-targets-build "${OTB_BINARY_DIR}/OTBTargets.cmake")
endmacro()
# Build all modules.
foreach(otb-module ${OTB_MODULES_ENABLED})
if(NOT ${otb-module}_IS_TEST)
init_module_vars()
endif()
include("${${otb-module}_SOURCE_DIR}/otb-module-init.cmake" OPTIONAL)
add_subdirectory("${${otb-module}_SOURCE_DIR}" "${${otb-module}_BINARY_DIR}")
endforeach()
#----------------------------------------------------------------------------
get_property(CTEST_CUSTOM_MEMCHECK_IGNORE GLOBAL PROPERTY CTEST_CUSTOM_MEMCHECK_IGNORE)
get_property(CTEST_CUSTOM_TESTS_IGNORE GLOBAL PROPERTY CTEST_CUSTOM_TESTS_IGNORE)
configure_file(CMake/CTestCustom.cmake.in CTestCustom.cmake @ONLY)
#-----------------------------------------------------------------------------
# Create list of available modules and libraries.
set(OTB_CONFIG_MODULES_ENABLED "")
foreach(otb-module ${OTB_MODULES_ENABLED})
if(NOT ${otb-module}_IS_TEST)
list(APPEND OTB_CONFIG_MODULES_ENABLED ${otb-module})
endif()
endforeach()
|