Skip to content

Commit 938e46f

Browse files
authored
Add cmake_utils feature to set a library minimum version (#10)
Signed-off-by: jparisu <javierparis@eprosima.com> Signed-off-by: jparisu <javierparis@eprosima.com>
1 parent 0e734f1 commit 938e46f

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

cmake_utils/README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ In order to compile a C++ library, use the following macros:
3030
1. To compile tests for the library: `compile_test(${<test path>})`
3131
1. To install the package following eprosima defaults `eprosima_packaging()`
3232

33+
---
34+
3335
## Module Requirements
3436

3537
In order create a package (called Module from now on) using this library,
@@ -49,8 +51,9 @@ The version will be loaded from this file if it is not set in `project_settings.
4951

5052
Every module requires to have a `LICENSE` file in order to install it with the result of the module.
5153

54+
---
5255

53-
#### Project using cmake_utils variables
56+
## Project configuration using cmake_utils variables
5457

5558
These are the variables that could/must be set in the `project_settings.cmake` file.
5659
Those variables which default is `x` must be set, and those with `-` are not required.
@@ -87,7 +90,21 @@ Those variables which default is `x` must be set, and those with `-` are not req
8790
|------------------------------|-------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
8891
| MODULE_CPP_VERSION | C++17 | C++ version |
8992

90-
#### Project using cmake_utils CMake options
93+
### Minimum Package Version
94+
95+
Setting the CMake variable `<library>_MINIMUM_VERSION` will force the `find_package` call to look for library
96+
`<library>` with minimum version `${<library>_MINIMUM_VERSION}`.
97+
98+
e.g.
99+
100+
```cmake
101+
set(MODULE_FIND_PACKAGES fastrtps)
102+
set(fastrtps_MINIMUM_VERSION "2.8") # This will force to use a version of fastrtps higher or equal 2.8
103+
```
104+
105+
---
106+
107+
## Project using cmake_utils CMake options set
91108

92109
There are default CMake options used within cmake_utils package that will always be set.
93110
In case the user sets these variables, they will have that value. Otherwise,

cmake_utils/cmake/cpp_common/find_external.cmake

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,28 @@
2020
#
2121
# ARGUMENTS:
2222
# - EXTERNAL_PROJECT_NAMES: List of names of external projects to find
23+
#
24+
# If ${${EXTERNAL_PROJECT}_MINIMUM_VERSION} is set for any of the project names passed as argument, it will
25+
# be used in order to look for a minimum version for this package.
26+
#
27+
2328
macro(find_external_projects EXTERNAL_PROJECT_NAMES)
2429

2530
foreach(EXTERNAL_PROJECT ${EXTERNAL_PROJECT_NAMES})
26-
find_package("${EXTERNAL_PROJECT}" REQUIRED)
27-
message(STATUS "Package ${EXTERNAL_PROJECT} found")
31+
# Check if this project requires a minimum version, set as ${EXTERNAL_PROJECT}_MINIMUM_VERSION
32+
if (${${EXTERNAL_PROJECT}_MINIMUM_VERSION})
33+
34+
find_package("${EXTERNAL_PROJECT}" "${${EXTERNAL_PROJECT}_MINIMUM_VERSION}" REQUIRED)
35+
message(
36+
STATUS
37+
"Package ${EXTERNAL_PROJECT} found higher than minimum version ${EXTERNAL_PROJECT}_MINIMUM_VERSION")
38+
39+
else()
40+
41+
find_package("${EXTERNAL_PROJECT}" REQUIRED)
42+
message(STATUS "Package ${EXTERNAL_PROJECT} found")
43+
44+
endif()
2845
endforeach()
2946

3047
# Finish macro

0 commit comments

Comments
 (0)