Skip to content

Commit b6b4ae9

Browse files
ethourisMikołaj Małecki
andauthored
[build] Add enabler variable to importing variable feature (#3307)
Co-authored-by: Mikołaj Małecki <mmalecki@haivision.com>
1 parent c3cfa17 commit b6b4ae9

2 files changed

Lines changed: 36 additions & 20 deletions

File tree

CMakeLists.txt

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,24 @@ endforeach()
122122
# SRT_MAVG_SAMPLING_RATE 40 /* Max sampling rate */
123123
# SRT_ENABLE_FREQUENT_LOG_TRACE 0 : set to 1 to enable printing reason for suppressed freq logs
124124

125-
# CMake offers the OLD behavior, where names that are defined below with
126-
# option() function, will be deleted if they are not in cache or do not have set
127-
# type - so effectively options provided through LIBSRT_* prefix would be rejected.
128-
# We do want these variables, obviously.
129-
# NOTE: This is introduced in cmake 3.13, so the namespaced-option feature will not
130-
# work properly in the old cmake.
131-
if (CMAKE_VERSION VERSION_GREATER 3.12)
132-
cmake_policy(SET CMP0077 NEW)
133-
endif()
134-
135-
# Import all options preceded with LIBSRT_ likely from a parent scope.
136-
# Names are not being checked, at worst it will set an unused variable.
137-
srt_import_parent_options()
125+
# Blocked by a general enabler, LIBSRT_ENABLE_IMPORT_VARIABLES, to prevent accidental use.
126+
if ( (DEFINED LIBSRT_ENABLE_IMPORT_VARIABLES) AND (LIBSRT_ENABLE_IMPORT_VARIABLES EQUAL 1))
127+
unset(LIBSRT_ENABLE_IMPORT_VARIABLES)
128+
129+
# CMake offers sometimes OLD behavior, where names that are defined below with
130+
# option() function, will be deleted if they are not in cache or do not have set
131+
# type - so effectively options provided through LIBSRT_* prefix would be rejected.
132+
# We do want these variables, obviously.
133+
# NOTE: This is introduced in cmake 3.13, so the namespaced-option feature will not
134+
# work properly in the old cmake.
135+
if (CMAKE_VERSION VERSION_GREATER 3.12)
136+
cmake_policy(SET CMP0077 NEW)
137+
endif()
138+
139+
# Import all options preceded with LIBSRT_ likely from a parent scope.
140+
# Names are not being checked, at worst it will set an unused variable.
141+
srt_import_parent_options()
142+
endif()
138143

139144
# option defaults
140145
set(ENABLE_HEAVY_LOGGING_DEFAULT OFF)

docs/build/build-options.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@ document and in the [SRT CookBook](https://srtlab.github.io/srt-cookbook/getting
2020
## Building as a subproject
2121

2222
The CMake tool offers the ability to add a complete project as a subdirectory.
23-
Variables used by the SRT project in this case remain in their own scope, but
24-
all variables from the parent scope are reflected. In order to prevent name
25-
clashes for option-designating variables, SRT provides a namespace-like
26-
prefixing for the optional variables it uses. If you want to configure optional
27-
variables from the level of `CMakeLists.txt` of the parent project, use the
28-
`LIBSRT_` prefix for the option names.
23+
If you do this with SRT, note that all variables that can be optionally set
24+
will get values from the parent configuration file including the one from SRT.
25+
26+
To allow isolation of these variables and setting them explicitly to desired
27+
values in case when the parent project uses variables with the same names,
28+
there's a special feature provided: set the desired variables for the SRT
29+
project using `LIBSRT_` prefix - this way they will get the values to the
30+
right variables, visible only in the scope of the SRT build configuration.
31+
32+
NOTE: This feature needs to be generally enabled by:
33+
34+
```
35+
set (LIBSRT_ENABLE_IMPORT_VARIABLES 1)
36+
```
37+
38+
otherwise all other variables with `LIBSRT_` prefix will be ignored.
2939

3040
This will not prevent the variables from being seen as derived in SRT project
3141
scope, but if you explicitly set a variable this way, it will be set to the
@@ -34,9 +44,10 @@ parent project, and it will also override (locally in SRT project only) any
3444
value of a variable with the same name in the parent project.
3545

3646
For example, if you want to set `ENABLE_SHARED=OFF` in the parent project,
37-
simply do:
47+
add this before importing the SRT project:
3848

3949
```
50+
set (LIBSRT_ENABLE_IMPORT_VARIABLES 1)
4051
set (LIBSRT_ENABLE_SHARED OFF)
4152
```
4253

0 commit comments

Comments
 (0)