SuperBuildTools.cmake
Go to the documentation of this file.
1 # ============================================================================
2 # Copyright (c) 2014 Carnegie Mellon University
3 # All rights reserved.
4 #
5 # See COPYING file for license information or visit
6 # https://cmake-basis.github.io/download.html#license
7 # ============================================================================
8 
10  return ()
11 else ()
13 endif ()
14 
15 include(ExternalProject)
16 
17 ##
18 # @brief When enabled CMake will always reconfigure super build modules. Slows performance but won't ignore changes in external projects.
19 #
20 # @note The global variable BASIS_SUPER_BUILD_ARGS is passed to the CMAKE_ARGS
21 # parameter of ExternalProject_Add in case custom variables need to be supplied.
22 #
23 option(BASIS_ALWAYS_RECONFIGURE_SUPER_BUILD "Enable to always reconfigure super build modules. Slows performance but won't ignore changes." OFF)
25 
26 ##
27 # @brief super build for BASIS modules
28 #
29 function(basis_super_build PACKAGE_NAME)
30  set(options )
31  set(singleValueArgs DIR CMAKE_MODULE_PATH BINARY_DIR CMAKE_INSTALL_PREFIX)
32  set(multiValueArgs DEPENDS)
33 
34  cmake_parse_arguments(${PACKAGE_NAME} ${options} ${singleValueArgs} ${multiValueArgs} ${ARGN})
35 
36  # TODO: consider combining this variable with MODULE_${PACKAGE_NAME} variable
37  #option (USE_SYSTEM_${PACKAGE_NAME} "Skip build of ${PACKAGE_NAME} if already installed." OFF)
38 
39  if(NOT ${PACKAGE_NAME}_CMAKE_MODULE_PATH)
40  set(${PACKAGE_NAME}_CMAKE_MODULE_PATH "-DCMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}")
41  endif()
42 
43  # TODO: make sure default install prefix does not typically trample the installation
44  if(NOT ${PACKAGE_NAME}_CMAKE_INSTALL_PREFIX)
45  set(${PACKAGE_NAME}_CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
46  endif()
47 
48  # set directory where binaries will build if it was not already set by the arguments
49  if(NOT ${PACKAGE_NAME}_BINARY_DIR)
50  if(MODULE_${PACKAGE_NAME}_BINARY_DIR)
51  set(${PACKAGE_NAME}_BINARY_DIR ${MODULE_${PACKAGE_NAME}_BINARY_DIR})
52  elseif(NOT MODULE_${PACKAGE_NAME}_BINARY_DIR)
53  set(MODULE_${PACKAGE_NAME}_BINARY_DIR ${PROJECT_BINARY_DIR})
54  endif()
55  endif()
56 
57  if(NOT ${PACKAGE_NAME}_DIR AND MODULE_${MODULE}_SOURCE_DIR)
58  set(${PACKAGE_NAME}_DIR "${MODULE_${MODULE}_SOURCE_DIR}")
59  endif()
60 
61  # TODO: Fix DEPENDS parameter. May need to separate basis module and regular dependencies so they can specified separately for the super build.
62  # TODO: Consider using the EP_BASE path with SET(ep_base ${${PACKAGE_NAME}_BINARY_DIR}) instead. (ep stands for external project)
63  # TODO: Figure out why a few intermediate files are still being put in the ${CMAKE_BINARY_DIR}/${PACKAGE_NAME}-prefix/ directory
64  # TODO: Check for additional useful -D parameters.
65 
66  # passing semicolons has odd side effects because they may be automatically
67  # dereferenced, so substitute another character, in this case pipe |
68  string(REPLACE ";" "|" CMAKE_PREFIX_PATH_PIPE "${CMAKE_PREFIX_PATH}")
69 
70  # only specifiy dependencies that are actual targets
71  # otherwise there would be an error
72  set(SUPER_BUILD_TARGET_DEPENDENCIES)
73  foreach(DEPENDENCY IN ${DEPENDS})
74  if(TARGET DEPENDENCY)
75  list(APPEND SUPER_BUILD_TARGET_DEPENDENCIES ${DEPENDENCY})
76  endif()
77  endforeach()
78 
79  string(REPLACE ";" " " SUPER_BUILD_TARGET_DEPENDENCIES "${SUPER_BUILD_TARGET_DEPENDENCIES}")
80 
81  if(BASIS_DEBUG)
82  message(STATUS
83  "basis_super_build() Module:
84  ExternalProject_Add(${PACKAGE_NAME}
85  DEPENDS ${SUPER_BUILD_TARGET_DEPENDENCIES}
86  SOURCE_DIR ${${PACKAGE_NAME}_DIR}
87  CMAKE_ARGS
88  -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
89  -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
90  -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
91  -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
92  ${${PACKAGE_NAME}_CMAKE_MODULE_PATH}
93  ${BASIS_SUPER_BUILD_ARGS}
94  CMAKE_CHACHE_ARGS
95  -DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH_PIPE}
96  CMAKE_GENERATOR
97  ${CMAKE_GENERATOR}
98  CMAKE_TOOLSET
99  ${CMAKE_TOOLSET}
100  BINARY_DIR
101  ${${PACKAGE_NAME}_BINARY_DIR}
102  INSTALL_DIR
103  ${${PACKAGE_NAME}_CMAKE_INSTALL_PREFIX}
104  )
105  " )
106  endif()
107 
108  #if(USE_SYSTEM_${PACKAGE_NAME})
109  # find_package(${PACKAGE_NAME})
110  #elseif()
111 
112  ExternalProject_Add(${PACKAGE_NAME}
113  DEPENDS ${SUPER_BUILD_TARGET_DEPENDENCIES}
114  SOURCE_DIR ${${PACKAGE_NAME}_DIR}
115  LIST_SEPARATOR "|"
116  CMAKE_ARGS
117  -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
118  -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
119  -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
120  -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
121  ${${PACKAGE_NAME}_CMAKE_MODULE_PATH}
122  ${BASIS_SUPER_BUILD_ARGS}
123  CMAKE_CHACHE_ARGS
124  -DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH_PIPE}
125  CMAKE_GENERATOR
126  ${CMAKE_GENERATOR}
127  CMAKE_TOOLSET
128  ${CMAKE_TOOLSET}
129  BINARY_DIR
130  ${${PACKAGE_NAME}_BINARY_DIR}
131  INSTALL_DIR
132  ${${PACKAGE_NAME}_CMAKE_INSTALL_PREFIX}
133  )
134 
135 
137  ExternalProject_Add_Step(${PACKAGE_NAME} reconfigure
138  COMMAND ${CMAKE_COMMAND} -E echo "Force configure of ${PACKAGE_NAME}"
139  DEPENDEES update
140  DEPENDERS configure
141  ALWAYS 1)
142  endif()
143 
144  #endif()
145 endfunction()
cmake CMAKE_INSTALL_PREFIX
Installation prefix, i.e., root directory of installation.
string CMAKE_BUILD_TYPE
cmake __BASIS_SUPER_BUILD_INCLUDED
cmake COMMAND
cmake DIR
option BASIS_DEBUG
Request debugging messages from BASIS functions.
function basis_super_build(in PACKAGE_NAME)
super build for BASIS modules
option BASIS_ALWAYS_RECONFIGURE_SUPER_BUILD
When enabled CMake will always reconfigure super build modules. Slows performance but won&#39;t ignore ch...