Skip to content

Commit 79f578f

Browse files
authored
Merge pull request bemanproject#190 from bretbrownjr/fix-install-option
Polish beman_install_library
2 parents 8e45a74 + e98506f commit 79f578f

2 files changed

Lines changed: 69 additions & 4 deletions

File tree

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,49 @@ so it does not respect the usual structure of a Beman library repository nor The
99

1010
## Description
1111

12+
* `cmake/`: CMake modules and toolchain files used by Beman libraries.
1213
* `containers/`: Containers used for CI builds and tests in the Beman org.
1314
* `tools/`: Tools used to manage the infrastructure and the codebase (e.g., linting, formatting, etc.).
15+
16+
## Usage
17+
18+
This repository is intended to be used as a beman-submodule in other Beman repositories. See
19+
[the Beman Submodule documentation](./tools/beman-submodule/README.md) for details.
20+
21+
22+
### CMake Modules
23+
24+
25+
#### `beman_install_library`
26+
27+
The CMake modules in this repository are intended to be used by Beman libraries. Use the
28+
`beman_add_install_library_config()` function to install your library, along with header
29+
files, any metadata files, and a CMake config file for `find_package()` support.
30+
31+
```cmake
32+
add_library(beman.something)
33+
add_library(beman::something ALIAS beman.something)
34+
35+
# ... configure your target as needed ...
36+
37+
find_package(beman-install-library REQUIRED)
38+
beman_install_library(beman.something)
39+
```
40+
41+
Note that the target must be created before calling `beman_install_library()`. The module
42+
also assumes that the target is named using the `beman.something` convention, and it
43+
uses that assumption to derive the names to match other Beman standards and conventions.
44+
If your target does not follow that convention, raise an issue or pull request to add
45+
more configurability to the module.
46+
47+
The module will configure the target to install:
48+
49+
* The library target itself
50+
* Any public headers associated with the target
51+
* CMake files for `find_package(beman.something)` support
52+
53+
Some options for the project and target will also be supported:
54+
55+
* `BEMAN_INSTALL_CONFIG_FILE_PACKAGES` - a list of package names (e.g., `beman.something`) for which to install the config file
56+
(default: all packages)
57+
* `<BEMAN_NAME>_INSTALL_CONFIG_FILE_PACKAGE` - a per-project option to enable/disable config file installation (default: `ON` if the project is top-level, `OFF` otherwise). For instance for `beman.something`, the option would be `BEMAN_SOMETHING_INSTALL_CONFIG_FILE_PACKAGE`.

cmake/beman-install-library-config.cmake

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,32 @@ function(beman_install_library name)
8181
string(TOUPPER "${name}" project_prefix)
8282
string(REPLACE "." "_" project_prefix "${project_prefix}")
8383

84-
if(
85-
"${name}" IN_LIST BEMAN_INSTALL_CONFIG_FILE_PACKAGES
86-
OR "${project_prefix}_INSTALL_CONFIG_FILE_PACKAGE"
84+
option(
85+
${project_prefix}_INSTALL_CONFIG_FILE_PACKAGE
86+
"Enable building examples. Default: ${PROJECT_IS_TOP_LEVEL}. Values: { ON, OFF }."
87+
${PROJECT_IS_TOP_LEVEL}
8788
)
88-
set(install_config_package ON)
89+
90+
# By default, install the config package
91+
set(install_config_package ON)
92+
93+
# Turn OFF installation of config package by default if,
94+
# in order of precedence:
95+
# 1. The specific package variable is set to OFF
96+
# 2. The package name is not in the list of packages to install config files
97+
if(DEFINED BEMAN_INSTALL_CONFIG_FILE_PACKAGES)
98+
if(
99+
NOT "${install_component_name}"
100+
IN_LIST
101+
BEMAN_INSTALL_CONFIG_FILE_PACKAGES
102+
)
103+
set(install_config_package OFF)
104+
endif()
105+
endif()
106+
if(DEFINED ${project_prefix}_INSTALL_CONFIG_FILE_PACKAGE)
107+
set(install_config_package
108+
${${project_prefix}_INSTALL_CONFIG_FILE_PACKAGE}
109+
)
89110
endif()
90111

91112
if(install_config_package)

0 commit comments

Comments
 (0)