1 # ============================================================================ 2 # Copyright (c) <copyright> 6 # ============================================================================ 8 ############################################################################## 9 # @file BasisBootstrapping.cmake 10 # @brief Auxiliary function to bootstrap the build of CMake BASIS. 11 ############################################################################## 13 include (CMakeParseArguments)
15 # ---------------------------------------------------------------------------- 16 ## @brief Boostrap build of CMake BASIS during configuration of project. 18 # This function downloads, configures, and builds CMake BASIS. If the (cached) 19 # variable @c BASIS_INSTALL_PREFIX is set, it also installs BASIS into the 20 # specified directory. This is only required if the project uses the 21 # BASIS Utilities. Otherwise, the BASIS build tree can be used directly to 22 # build the software project which bootstrapped BASIS. It is not required 23 # during runtime of the software. 25 # @param[in] ARGN The list of arguments is parsed as follows: 29 # @tp @b VERSION major.minor.patch @endtp 30 # <td>Version of CMake BASIS to download.</td> 33 # @tp @b DOWNLOAD_URL url @endtp 34 # <td>URL from which to download the CMake BASIS source distribution package. 35 # The given URL can be either a complete download URL which includes the 36 # package name (which must end with .tar.gz or .zip) or the path of 37 # a remote directory which contains the CMake BASIS packages named 38 # cmake-basis-version.zip (for Windows) and cmake-basis-version.tar.gz (for Unix). 39 # (default: http://opensource.andreasschuh.com/cmake-basis/_downloads)</td> 42 # @tp @b INFORM_USER @endtp 43 # <td>This option causes this function to abort the initial configure step 44 # of CMake. It informs the user that this project required BASIS for 45 # the build configuration and that it upon the next configure run it 46 # will attempt to download and build BASIS automatically. It further 47 # notes that the user can set the @c BASIS_DIR variable prior to the 48 # next configure run in order to use an existing BASIS installation. 52 # @tp @b BASIS_VARIABLE_NAME value @endtp 53 # <td>Adds a build configuration to the CMake command used to configure 54 # the build of CMake BASIS using the -D option of @c cmake. The 55 # @c BASIS_VARIABLE_NAME can be any CMake option or variable that 56 # is normally used to configure a BASIS build using CMake. For example, 57 # USE_PythonInterp, USE_BASH, USE_DOXYGEN.</td> 61 # @returns Sets the @c BASIS_DIR variable to the bootstrapped BASIS build. 63 # parse arguments -- unparsed arguments are passed on to CMake
using -D
64 CMAKE_PARSE_ARGUMENTS (BASIS
"INFORM_USER" "VERSION;DOWNLOAD_URL" "" ${ARGN})
65 if (NOT BASIS_VERSION)
66 message (FATAL_ERROR
"No CMake BASIS version specified! Use 'VERSION 3.0.0', for example.")
68 # abort the first time to give users a chance to specify where their 69 # CMake BASIS installation is located by setting BASIS_DIR in the GUI 70 if (BASIS_INFORM_USER)
71 if (DEFINED
BASIS_DIR AND NOT DEFINED BASIS_INSTALL_PREFIX)
72 set (BASIS_INSTALL_PREFIX
"" CACHE PATH
"Installation prefix for CMake BASIS.")
73 message (FATAL_ERROR
"Could not find an existing CMake BASIS installation!\n" 74 "This project uses CMake BASIS for the build configuration." 75 " Next time you configure this build by running CMake again," 76 " BASIS version ${BASIS_VERSION} will be automatically downloaded" 77 " and build as part of the build configuration of this project." 78 " If you want to install this version permanently," 79 " specify an installation prefix for CMake BASIS using" 80 " BASIS_INSTALL_PREFIX. Otherwise, leave it blank.\n" 81 "If you installed CMake BASIS already on your system, please" 82 " specify its location by setting the BASIS_DIR variable" 83 " before you re-configure the build system of this project.\n" 84 "Visit http://opensource.andreasschuh.com/cmake-basis for" 85 " more information about the CMake BASIS package.\n")
89 set (DOWNLOAD_PATH "${CMAKE_CURRENT_BINARY_DIR}
") 91 set (BASIS_ARCHIVE "cmake-
basis-${BASIS_VERSION}.zip
") 93 set (BASIS_ARCHIVE "cmake-
basis-${BASIS_VERSION}.tar.gz
") 95 if (NOT BASIS_DOWNLOAD_URL) 96 set (BASIS_DOWNLOAD_URL "http:
98 if (NOT BASIS_DOWNLOAD_URL MATCHES "\\.(zip|tar\\.gz)$")
99 set (BASIS_DOWNLOAD_URL "${BASIS_DOWNLOAD_URL}/${BASIS_ARCHIVE}
") 101 set (BASIS_SOURCE_DIR "${DOWNLOAD_PATH}/cmake-
basis-${BASIS_VERSION}
") 102 set (BASIS_BINARY_DIR "${DOWNLOAD_PATH}/cmake-
basis-${BASIS_VERSION}/build
") 104 # bootstrap BASIS build/installation only if not done before 105 # or when BASIS_INSTALL_PREFIX has changed 106 if ( NOT IS_DIRECTORY "${BASIS_BINARY_DIR}
" 107 OR NOT DEFINED BASIS_INSTALL_PREFIX_CONFIGURED 108 OR NOT BASIS_INSTALL_PREFIX_CONFIGURED STREQUAL "${BASIS_INSTALL_PREFIX}
") 110 # download and extract source code if not done before 111 if (NOT EXISTS "${BASIS_SOURCE_DIR}/BasisProject.cmake
") 112 # download source code distribution package 113 if (NOT EXISTS "${DOWNLOAD_PATH}/${BASIS_ARCHIVE}
") 114 message (STATUS "Downloading CMake BASIS v${BASIS_VERSION}...
") 115 file (DOWNLOAD "${BASIS_DOWNLOAD_URL}
" "${DOWNLOAD_PATH}/${BASIS_ARCHIVE}
" STATUS RETVAL) 116 list (GET RETVAL 1 ERRMSG) 117 list (GET RETVAL 0 RETVAL) 118 if (NOT RETVAL EQUAL 0) 119 message (FATAL_ERROR "Failed to download CMake BASIS v${BASIS_VERSION} from\n
" 120 "\t${BASIS_DOWNLOAD_URL}\n
" 122 "Either
try again or follow the instructions at\n
" 124 "to download and install it manually before configuring this project.\n")
126 message (STATUS "Downloading CMake BASIS v${BASIS_VERSION}... - done
") 128 # extract source package 129 message (STATUS "Extracting CMake BASIS...
") 130 execute_process (COMMAND ${CMAKE_COMMAND} -E tar -xvzf "${DOWNLOAD_PATH}/${BASIS_ARCHIVE}
" RESULT_VARIABLE RETVAL) 131 if (NOT RETVAL EQUAL 0) 132 file (REMOVE_RECURSE "${BASIS_SOURCE_DIR}
") 133 message (FATAL_ERROR "Failed to extract the downloaded archive file ${DOWNLOAD_PATH}/${BASIS_ARCHIVE}!
") 135 message (STATUS "Extracting CMake BASIS... - done
") 139 # TODO: Does this work on Windows as well ? Do we need "-G${CMAKE_GENERATOR}
" ? 140 file (MAKE_DIRECTORY "${BASIS_BINARY_DIR}
") 142 set (CMAKE_ARGUMENTS "-DBASIS_REGISTER:BOOL=OFF
") # do not register this BASIS build/installation 143 # as it should only be used by this project 144 if (BASIS_INSTALL_PREFIX) 145 list (APPEND CMAKE_ARGUMENTS "-DCMAKE_INSTALL_PREFIX=${BASIS_INSTALL_PREFIX}
") 147 list (LENGTH BASIS_UNPARSED_ARGUMENTS N) 149 list (GET BASIS_UNPARSED_ARGUMENTS 0 VARIABLE_NAME) 150 list (GET BASIS_UNPARSED_ARGUMENTS 1 VARIABLE_VALUE) 151 list (APPEND CMAKE_ARGUMENTS "-D${
VARIABLE_NAME}=${VARIABLE_VALUE}
") 152 list (REMOVE_AT BASIS_UNPARSED_ARGUMENTS 0 1) 153 math (EXPR N "${N} - 2
") 156 COMMAND "${CMAKE_COMMAND}
" ${CMAKE_ARGUMENTS} "${BASIS_SOURCE_DIR}
" 157 WORKING_DIRECTORY "${BASIS_BINARY_DIR}
" 160 execute_process (COMMAND "${CMAKE_BUILD_TOOL}
" all WORKING_DIRECTORY "${BASIS_BINARY_DIR}
") 162 if (BASIS_INSTALL_PREFIX) 163 execute_process (COMMAND "${CMAKE_BUILD_TOOL}
" install WORKING_DIRECTORY "${BASIS_BINARY_DIR}
") 164 set (BASIS_DIR "${BASIS_INSTALL_PREFIX}
" PARENT_SCOPE) 166 set (BASIS_DIR "${BASIS_BINARY_DIR}
" PARENT_SCOPE) 169 # remember in which directory BASIS was installed to avoid re-running 170 # the bootstrapping every time the project needs to be re-configured 171 set (BASIS_INSTALL_PREFIX_CONFIGURED "${BASIS_INSTALL_PREFIX}
" CACHE INTERNAL "" FORCE) 173 elseif (BASIS_INSTALL_PREFIX_CONFIGURED) 174 set (BASIS_DIR "${BASIS_INSTALL_PREFIX_CONFIGURED}
" PARENT_SCOPE) 176 set (BASIS_DIR "${BASIS_BINARY_DIR}
" PARENT_SCOPE) 179 endfunction (basis_bootstrap) function basis_bootstrap(in ARGN)
Boostrap build of CMake BASIS during configuration of project.