5 # Find CMake Build system And Software Implementation Standard (BASIS) 6 # installation using the find_package command in CONFIG mode. 10 # BASIS_FOUND - True if CMake BASIS was found. 11 # BASIS_VERSION - Version of found CMake BASIS installation. 12 # BASIS_VERSION_MAJOR - Major version number of found CMake BASIS installation. 13 # BASIS_VERSION_MINOR - Minor version number of found CMake BASIS installation. 14 # BASIS_VERSION_PATCH - Patch number of found CMake BASIS installation. 15 # BASIS_INCLUDE_DIRS - CMake BASIS Utilities include directories. 16 # BASIS_LIBRARY_DIRS - Link directories for CMake BASIS Utilities. 18 # By default, this module reads hints about search paths from variables:: 20 # DEPENDS_BASIS_DIR - Either installation root or BASISConfig.cmake directory. 21 # BASIS_DIR - Directory containing the BASISConfig.cmake file. 22 # BASIS_ROOT - Root directory of CMake BASIS installation. 24 # This module considers the common ``BASIS_DIR`` and ``BASIS_ROOT`` CMake or environment 25 # variables to initialize the ``DEPENDS_BASIS_DIR`` cache entry. The ``DEPENDS_BASIS_DIR`` 26 # is the non-internal cache entry visible in the CMake GUI. This variable can be set 27 # to either the installation prefix of CMake BASIS, i.e., the top-level directory, 28 # or the directory containing the ``BASISConfig.cmake`` file. It therefore is a hybrid 29 # of ``BASIS_ROOT`` and ``BASIS_DIR`` and replaces these. The common DEPENDS prefix 30 # for cache entries used to set the location of dependencies allows the grouping 31 # of these variables in the CMake GUI. This is a feature of basis_find_package. 32 # As this command is not available without having found a CMake BASIS installation before, 33 # this module can be used to replicate a subset of its functionality for finding BASIS. 35 #============================================================================= 36 # Copyright 2016 Andreas Schuh 38 # Redistribution and use in source and binary forms, with or without 39 # modification, are permitted provided that the following conditions 42 # * Redistributions of source code must retain the above copyright 43 # notice, this list of conditions and the following disclaimer. 45 # * Redistributions in binary form must reproduce the above copyright 46 # notice, this list of conditions and the following disclaimer in the 47 # documentation and/or other materials provided with the distribution. 49 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 #============================================================================= 62 # Set BASISConfig.cmake directory from installation prefix path 63 function (_basis_root_to_config_dir OUT IN)
66 set(${OUT}
"${IN}/CMake" PARENT_SCOPE)
68 set(${OUT}
"${IN}/lib/cmake/basis" PARENT_SCOPE)
71 set(${OUT}
"NOTFOUND" PARENT_SCOPE)
75 # Set installation prefix path from BASISConfig.cmake directory 76 function (_basis_config_to_root_dir OUT IN)
79 string(REGEX REPLACE
"/+CMake/*$" "" _prefix "${IN}")
81 string(REGEX REPLACE
"/+lib/+cmake/+basis/*$" "" _prefix "${IN}")
86 set(${OUT}
"${_prefix}" PARENT_SCOPE)
89 # Use more user friendly hybrid DEPENDS_BASIS_DIR cache variable which allows grouping 90 # of DEPENDS paths or custom named cache entry, but still consider BASIS_ROOT and 91 # BASIS_DIR as more common alternatives set in the user shell environment or on the 92 # CMake command line. The DEPENDS_<Package>_DIR is what CMake BASIS uses by default. 94 "Installation prefix of CMake BASIS or directory containing BASISConfig.cmake file." 98 # were specified on the command line
using the -D option. Note that these variables
99 # cannot be
set in the CMake GUI because their type
is changed here to INTERNAL.
100 # This has two reasons, firstly to not have duplicate variables with different
101 # names
for the same purpose, and secondly to be able to recognize when their
102 # value
is changed
using the -D command line option of the cmake command.
104 _basis_config_to_root_dir(
_prefix "${BASIS_DIR}")
107 if (BASIS_ROOT AND (NOT DEFINED _BASIS_ROOT OR (DEFINED _BASIS_ROOT AND NOT "^${
BASIS_ROOT}$
" STREQUAL "^${_BASIS_ROOT}$
"))) 108 set_property(CACHE DEPENDS_BASIS_DIR PROPERTY VALUE "${
BASIS_ROOT}
") 111 # Mark alternatives as internal cache entries 112 foreach (_var IN ITEMS BASIS_DIR BASIS_ROOT) 113 get_property(_cached CACHE ${_var} PROPERTY TYPE SET) 115 set_property(CACHE ${_var} PROPERTY TYPE INTERNAL) 119 # If still not set, use common environment variables to set DEPENDS_BASIS_DIR 120 if (NOT DEPENDS_BASIS_DIR) 123 set_property(CACHE DEPENDS_BASIS_DIR PROPERTY VALUE "${_dir}
") 129 # Convert path to CMake style with forward slashes 132 # Circumvent issue with CMake's find_package() interpreting these variables 133 # relative to the current binary directory instead of the top-level directory 138 # Allow DEPENDS_BASIS_DIR to be set to either the root directory... 139 if (DEPENDS_BASIS_DIR) 142 # ...or the directory containing the BASISConfig.cmake file 143 set(BASIS_DIR "${
DEPENDS_BASIS_DIR}
" CACHE INTERNAL "Directory containing BASISConfig.cmake file.
" FORCE) 145 # Look for CMake BASIS installation 146 if (NOT BASIS_FIND_QUIETLY) 147 set(_msg "Looking
for BASIS
") 148 if (BASIS_FIND_VERSION) 149 set(_msg "${
_msg} ${BASIS_FIND_VERSION}
") 151 if (BASIS_FIND_COMPONENTS) 152 set(_msg "${
_msg} [${BASIS_FIND_COMPONENTS}]
") 154 message(STATUS "${
_msg}...
") 158 if (BASIS_FIND_VERSION) 159 list(APPEND _argv ${BASIS_FIND_VERSION}) 161 if (BASIS_FIND_VERSION_EXACT) 162 list(APPEND _argv EXACT) 166 foreach (_comp IN LISTS BASIS_FIND_COMPONENTS) 167 if (BASIS_FIND_REQUIRED_${_component}) 168 list(APPEND _comps ${_component}) 170 list(APPEND _comps_opt ${_component}) 174 list(APPEND _argv COMPONENTS ${_comps}) 177 list(APPEND _argv OPTIONAL_COMPONENTS ${_comps_opt}) 180 find_package(BASIS ${_argv} CONFIG QUIET) 182 if (NOT BASIS_FIND_QUIETLY) 184 if (BASIS_VERSION AND NOT BASIS_VERSION STREQUAL "0.0.0
") 185 message(STATUS "Looking
for BASIS... - found v${BASIS_VERSION}
") 187 message(STATUS "Looking
for BASIS... - found
") 190 message(STATUS "Looking
for BASIS... - not found
") 194 # Make internal search path cache entries consistent with non-internal cache entry 196 _basis_config_to_root_dir(_prefix "${
BASIS_DIR}
") 198 set(_prefix NOTFOUND) 201 set_property(CACHE BASIS_DIR PROPERTY TYPE INTERNAL) 204 get_property(_cached CACHE BASIS_ROOT PROPERTY TYPE SET) 206 set_property(CACHE BASIS_ROOT PROPERTY VALUE "${
_prefix}
") 210 if (NOT _cache MATCHES "^BASIS_(
DIR|ROOT)$
") 211 set_property(CACHE DEPENDS_BASIS_DIR PROPERTY VALUE "${
_prefix}
") 214 # Make internal cache copies of alternative search path variables 215 # so we can detect when a new value was specified using -D option 216 foreach (_var IN ITEMS BASIS_DIR BASIS_ROOT) 218 get_property(_cached CACHE ${_var} PROPERTY TYPE SET) 220 set(_${_var} "${${_var}}
" CACHE INTERNAL "Previous value of ${_var} after last
find_package(BASIS)
" FORCE) 225 # Raise fatal error when CMake BASIS required but not found 226 if (BASIS_FIND_REQUIRED AND NOT BASIS_FOUND) 227 message(FATAL_ERROR "Could not find CMake BASIS! Please ensure that it
is installed
" 229 " to the installation prefix of BASIS, i.e., the root directory,
" 230 " or the directory containing the BASISConfig.cmake file.
") 233 # Unset local variables
function is(in result, in expected, in name)
Test whether a given result is equal to the expected result.
macro find_package()
Overloaded find_package() command.