Skip to content

Commit dc9b4e6

Browse files
committed
cmake: Combine installed packages
This change combines previous installed "cmake/LibmultiprocessLibConfig.cmake" and "cmake/LibmultiprocessBinConfig.cmake" files into a single "cmake/Libmultiprocess/LibmultiprocessConfig.cmake" file, so it can be imported with "find_package(Libmultiprocess)". The previous locations which were set in #97 were not actually compatible with find_package search behavior by default. The change also adds some documentation about using the new package to doc/install.md.
1 parent 2ed1e9a commit dc9b4e6

File tree

5 files changed

+77
-34
lines changed

5 files changed

+77
-34
lines changed

CMakeLists.txt

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,6 @@ set_target_properties(multiprocess PROPERTIES
6464
install(TARGETS multiprocess EXPORT LibTargets
6565
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib
6666
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mp COMPONENT lib)
67-
include(CMakePackageConfigHelpers)
68-
configure_package_config_file(
69-
${PROJECT_SOURCE_DIR}/cmake/LibmultiprocessLibConfig.cmake.in
70-
LibmultiprocessLibConfig.cmake
71-
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake
72-
NO_SET_AND_CHECK_MACRO)
73-
install(
74-
FILES
75-
${CMAKE_CURRENT_BINARY_DIR}/LibmultiprocessLibConfig.cmake
76-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake COMPONENT lib)
7767

7868
# mpgen code generator
7969
add_executable(mpgen src/mp/gen.cpp $<TARGET_OBJECTS:util>)
@@ -92,16 +82,6 @@ set_target_properties(mpgen PROPERTIES
9282
install(TARGETS mpgen EXPORT BinTargets
9383
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin
9484
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mp COMPONENT bin)
95-
include(CMakePackageConfigHelpers)
96-
configure_package_config_file(
97-
${PROJECT_SOURCE_DIR}/cmake/LibmultiprocessBinConfig.cmake.in
98-
LibmultiprocessBinConfig.cmake
99-
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake
100-
NO_SET_AND_CHECK_MACRO)
101-
install(
102-
FILES
103-
${CMAKE_CURRENT_BINARY_DIR}/LibmultiprocessBinConfig.cmake
104-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake COMPONENT bin)
10585

10686
# makefile include to invoke mpgen code generator, for downstream Make projects
10787
install(FILES "include/mpgen.mk"
@@ -126,13 +106,28 @@ install(EXPORT LibTargets
126106
NAMESPACE Libmultiprocess::
127107
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess COMPONENT lib)
128108

109+
# CMake find_package config file, for downstream CMake projects
110+
include(CMakePackageConfigHelpers)
111+
configure_package_config_file(
112+
${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in
113+
LibmultiprocessConfig.cmake
114+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess
115+
NO_SET_AND_CHECK_MACRO)
116+
install(
117+
FILES
118+
${CMAKE_CURRENT_BINARY_DIR}/LibmultiprocessConfig.cmake
119+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess
120+
COMPONENT common)
121+
129122
# Makefile targets to support "make install-bin" "make install-lib"
130123
add_custom_target(install-bin
131124
COMMAND ${CMAKE_COMMAND} -DCOMPONENT=bin -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
125+
COMMAND ${CMAKE_COMMAND} -DCOMPONENT=common -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
132126
VERBATIM)
133127
add_dependencies(install-bin mpgen)
134128
add_custom_target(install-lib
135129
COMMAND ${CMAKE_COMMAND} -DCOMPONENT=lib -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
130+
COMMAND ${CMAKE_COMMAND} -DCOMPONENT=common -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
136131
VERBATIM)
137132
add_dependencies(install-lib multiprocess)
138133

cmake/Config.cmake.in

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@PACKAGE_INIT@
2+
3+
# CMake find_package compatible package file, for downstream CMake projects
4+
#
5+
# Based on https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#adding-components
6+
7+
set(_Libmultiprocess_supported_components Bin Lib)
8+
9+
# If no components specified, include all components.
10+
list(LENGTH Libmultiprocess_FIND_COMPONENTS Libmultiprocess_FIND_COMPONENTS_len)
11+
if(Libmultiprocess_FIND_COMPONENTS_len EQUAL 0)
12+
set(Libmultiprocess_FIND_COMPONENTS ${_Libmultiprocess_supported_components})
13+
endif()
14+
15+
if ("Bin" IN_LIST Libmultiprocess_FIND_COMPONENTS)
16+
include("${CMAKE_CURRENT_LIST_DIR}/TargetCapnpSources.cmake")
17+
endif()
18+
19+
if ("Lib" IN_LIST Libmultiprocess_FIND_COMPONENTS)
20+
include(CMakeFindDependencyMacro)
21+
find_dependency(CapnProto)
22+
endif()
23+
24+
foreach(_comp ${Libmultiprocess_FIND_COMPONENTS})
25+
if (NOT _comp IN_LIST _Libmultiprocess_supported_components)
26+
set(Libmultiprocess_FOUND False)
27+
set(Libmultiprocess_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}")
28+
endif()
29+
include("${CMAKE_CURRENT_LIST_DIR}/${_comp}Targets.cmake")
30+
endforeach()

cmake/LibmultiprocessBinConfig.cmake.in

Lines changed: 0 additions & 6 deletions
This file was deleted.

cmake/LibmultiprocessLibConfig.cmake.in

Lines changed: 0 additions & 8 deletions
This file was deleted.

doc/install.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,35 @@ make
1818
make check # Optionally build and run tests
1919
make install
2020
```
21+
22+
To build with libmultiprocess in a CMake project can specify:
23+
24+
```cmake
25+
find_package(Libmultiprocess)
26+
target_capnp_sources(mytarget ${CMAKE_CURRENT_SOURCE_DIR} myschema.capnp)
27+
```
28+
29+
Which will locate the libmultiprocess cmake package, and call the
30+
`target_capnp_sources` function to generate C++ files and link them into a
31+
library or executable target. See `example/CMakeLists.txt` for a complete
32+
example.
33+
34+
To build with libmultiprocess in a non-CMake project can use installed
35+
`<prefix>/include/mpgen.mk` Makefile rule to generate C++ files, and
36+
`<prefix>/lib/pkgconfig/libmultiprocess.pc` pkg-config definition to link
37+
against the runtime library.
38+
39+
For cross-compilation, it may be useful to build the runtime library and code
40+
generation binaries separately, which can be done with:
41+
42+
```sh
43+
make install-bin # install bin/mpgen and related files
44+
make install-lib # install lib/libmultiprocess.a and related files
45+
```
46+
47+
It is also possible to import CMake targets separately with:
48+
49+
```cmake
50+
find_package(Libmultiprocess COMPONENTS Bin)
51+
find_package(Libmultiprocess COMPONENTS Lib)
52+
```

0 commit comments

Comments
 (0)