Skip to content

Commit 4d93c90

Browse files
author
Vincent Palancher
committed
cmake: Replaces CACHE variables with overridable variables.
This patch replaces every CACHE variable that has a hard-coded default value with a overridable variable (using a new function that automatizes its creation). An overridable variable is a variable that uses a default value if it doesn't already exists, either in the cache or in the environment. Doing this enables us to update the hard-coded values by changing the CMake files, consequently updating any existing configuration that doesn't have an overriden value for these variables (therefore using the default values). Change-Id: I740ee98c0d680be4d86940968af320bc1e1a634e Reviewed-on: http://gerrit2.aldebaran.lan/1384 Reviewed-by: philippe.martin <philippe.martin@softbankrobotics.com> Tested-by: vincent.palancher <vincent.palancher@softbankrobotics.com> Reviewed-by: jmonnon <jmonnon@aldebaran.com>
1 parent 8dff0ef commit 4d93c90

3 files changed

Lines changed: 48 additions & 51 deletions

File tree

cmake/set_dependencies.cmake

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,42 +44,30 @@
4444

4545
include_guard(GLOBAL)
4646

47-
set(BOOST_VERSION 1.64
48-
CACHE STRING
49-
"Version of Boost to use. It will be used as the argument to the
50-
`find_package(Boost)` call.")
51-
52-
set(PYBIND11_VERSION 2.5.0
53-
CACHE STRING
54-
"Version of pybind11 to use.")
55-
56-
set(PYBIND11_GIT_REPOSITORY https://github.com/pybind/pybind11
57-
CACHE STRING
58-
"URL of the git repository from which to download pybind11. For more \
59-
details, see CMake `ExternalProject` module documentation of the \
60-
`GIT_REPOSITORY` argument.")
61-
62-
set(PYBIND11_GIT_TAG v${PYBIND11_VERSION}
63-
CACHE STRING
64-
"Git branch name, tag or commit hash to checkout for pybind11. \
65-
For more details, see CMake `ExternalProject` module documentation of the \
66-
`GIT_TAG` argument.")
67-
68-
set(GOOGLETEST_VERSION 1.10.0
69-
CACHE STRING
70-
"Version of googletest to use.")
71-
72-
set(GOOGLETEST_GIT_REPOSITORY https://github.com/google/googletest.git
73-
CACHE STRING
74-
"URL of the git repository from which to download googletest. For more \
75-
details, see CMake `ExternalProject` module documentation of the \
76-
`GIT_REPOSITORY` argument.")
77-
78-
set(GOOGLETEST_GIT_TAG release-${GOOGLETEST_VERSION}
79-
CACHE STRING
80-
"Git branch name, tag or commit hash to checkout for googletest. \
81-
For more details, see CMake `ExternalProject` module documentation of the \
82-
`GIT_TAG` argument.")
47+
# Version of Boost to use. It will be used as the argument to the `find_package(Boost)` call.
48+
overridable_variable(BOOST_VERSION 1.64)
49+
50+
# Version of pybind11 to use.
51+
overridable_variable(PYBIND11_VERSION 2.5.0)
52+
53+
# URL of the git repository from which to download pybind11. For more details, see CMake
54+
# `ExternalProject` module documentation of the `GIT_REPOSITORY` argument.
55+
overridable_variable(PYBIND11_GIT_REPOSITORY https://github.com/pybind/pybind11)
56+
57+
# Git branch name, tag or commit hash to checkout for pybind11. For more details, see CMake
58+
# `ExternalProject` module documentation of the `GIT_TAG` argument.
59+
overridable_variable(PYBIND11_GIT_TAG v${PYBIND11_VERSION})
60+
61+
# Version of googletest to use.
62+
overridable_variable(GOOGLETEST_VERSION 1.10.0)
63+
64+
# URL of the git repository from which to download googletest. For more details, see CMake
65+
# `ExternalProject` module documentation of the `GIT_REPOSITORY` argument.
66+
overridable_variable(GOOGLETEST_GIT_REPOSITORY https://github.com/google/googletest.git)
67+
68+
# Git branch name, tag or commit hash to checkout for googletest. For more details, see CMake
69+
# `ExternalProject` module documentation of the `GIT_TAG` argument.
70+
overridable_variable(GOOGLETEST_GIT_TAG release-${GOOGLETEST_VERSION})
8371

8472
set(PYTHON_VERSION_STRING "" CACHE STRING "Version of Python to look for. This \
8573
variable can be specified by tools run directly from Python to enforce the \

cmake/set_libqi_dependency.cmake

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1-
set(LIBQI_VERSION 1.8.6
2-
CACHE STRING
3-
"Version of LibQi to use. If not empty, it will be checked against the \
4-
version in the `package.xml` file in the libqi sources.")
1+
overridable_variable(LIBQI_VERSION 1.8.6)
52

63
# Our github clone is sometimes late or is missing tags, so we enable
74
# customisation of the URL at configuration time, so users can use another clone.
8-
set(LIBQI_GIT_REPOSITORY https://github.com/aldebaran/libqi.git
9-
CACHE STRING
10-
"URL of the git repository from which to download LibQi. For more details, \
11-
see CMake `ExternalProject` module documentation of the `GIT_REPOSITORY` \
12-
argument.")
13-
14-
set(LIBQI_GIT_TAG qi-framework-v${LIBQI_VERSION}
15-
CACHE STRING
16-
"Git branch name, tag or commit hash to checkout for LibQi. \
17-
For more details, see CMake `ExternalProject` module documentation of the \
18-
`GIT_TAG` argument.")
5+
overridable_variable(LIBQI_GIT_REPOSITORY https://github.com/aldebaran/libqi.git)
196

7+
overridable_variable(LIBQI_GIT_TAG qi-framework-v${LIBQI_VERSION})
208

219
if(LIBQI_VERSION)
2210
message(STATUS "LibQi: expected version is \"${LIBQI_VERSION}\"")

cmake/utils.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,24 @@ function(set_install_rpath)
8383
endif()
8484
endforeach()
8585
endfunction()
86+
87+
# Creates a variable that can be overridden by the user from either the
88+
# command-line, the cache or the environment.
89+
# The order of preference is:
90+
# - the value from the variable in cache (or the command-line, since setting
91+
# a variable from the command-line automatically adds it to the cache).
92+
# - the value from the variable in the environment.
93+
# - the default value for the variable.
94+
function(overridable_variable name default_value)
95+
# The variable already exists in the cache. It's the preferred value, so we
96+
# don't change it.
97+
if(DEFINED CACHE{${name}})
98+
return()
99+
endif()
100+
101+
set(value ${default_value})
102+
if(DEFINED ENV{${name}})
103+
set(value $ENV{${name}})
104+
endif()
105+
set(${name} ${value} PARENT_SCOPE)
106+
endfunction()

0 commit comments

Comments
 (0)