forked from espressomd/espresso
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmake: Rewrite optional dependency build system
Generate an error when an explicitly requested optional dependency is not found instead of silently carrying on. This is achieved by creating a wrapper around the `option()` function to check whether the user explicitly passed a CMake flag `-DWITH_FEATURE=ON`.
- Loading branch information
Showing
2 changed files
with
77 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (C) 2020 The ESPResSo project | ||
# | ||
# This file is part of ESPResSo. | ||
# | ||
# ESPResSo is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# ESPResSo is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
# Like `option()`, but create an extra boolean variable to store whether the | ||
# option was set to its default value or to a user-provided value. With this | ||
# command, the project can be installed with optional dependencies without | ||
# the need to provide a list of CMake flags. Unavailable dependencies will be | ||
# silently ignored. However, if the user specifically requested an optional | ||
# dependency by passing the corresponding CMake flag, the build system has | ||
# the possibility to throw an error if the dependency is unavailable. | ||
# | ||
# Note that when calling CMake again without clearing the build folder, | ||
# variables from the previous CMake call are loaded in memory. For example, | ||
# if the user passed a value to an `option_if_available()` the first time but | ||
# not the second time, the variable will still be flagged as a user-provided | ||
# value in the second CMake call. | ||
macro(option_if_available varname help_text default_value) | ||
if("${${varname}}" STREQUAL "") | ||
set(${varname}_IS_DEFAULT_VALUE TRUE) | ||
else() | ||
set(${varname}_IS_DEFAULT_VALUE FALSE) | ||
endif() | ||
option(${varname} ${help_text} ${default_value}) | ||
endmacro() |