Skip to content

Commit 201abd9

Browse files
committed
Merge #289: cmake: make target_capnp_sources use CURRENT dirs
615a94f cmake: document ONLY_CAPNP option in target_capnp_sources (Ryan Ofsky) 620f297 cmake: make target_capnp_sources use CURRENT dirs (Ryan Ofsky) Pull request description: Tweak `target_capnp_sources` to use `CMAKE_CURRENT_SOURCE_DIR` and `CMAKE_CURRENT_BINARY_DIR` instead of `CMAKE_SOURCE_DIR` and `CMAKE_BINARY_DIR` to compute include directory paths. This allows `target_capnp_sources` to work properly inside libmultiprocess when libmultiprocess is used as a subproject and `CMAKE_SOURCE_DIR` point somewhere outside of it, as happens in support branch used by #287. This is also a good change to make more generally because `CMAKE_CURRENT_SOURCE_DIR` is a more predictable path than `CMAKE_SOURCE_DIR` and is passed in by all current `target_capnp_sources` callers. ACKs for top commit: hebasto: re-ACK 615a94f. Tree-SHA512: 978a3172dee80cff4dd2afb4858347216c9211a6f182b6b0b9ad71641f30ccaea619d5ddd61484cd08375dd21c290b8fb5b52307baadc8042443b12bd6c3b908
2 parents 99820c8 + 615a94f commit 201abd9

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

cmake/TargetCapnpSources.cmake

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ Arguments:
2727
2828
#include <schema.capnp.h>
2929
30-
The specified include_prefix should be ${CMAKE_SOURCE_DIR} or a
31-
subdirectory of it to include files relative to the project root. It can
32-
be ${CMAKE_CURRENT_SOURCE_DIR} to include files relative to the current
33-
source directory.
30+
Pass ${CMAKE_CURRENT_SOURCE_DIR} or a subdirectory of it to include files
31+
relative to the current source directory (the typical usage).
3432
3533
Additional Unnamed Arguments:
3634
@@ -43,12 +41,19 @@ Optional Keyword Arguments:
4341
IMPORT_PATHS: Specifies additional directories to search for imported
4442
`.capnp` files.
4543
44+
ONLY_CAPNP: If specified, only the Cap'n Proto serialization files
45+
(`.capnp.h`, `.capnp.c++`) are generated and compiled. The mpgen proxy
46+
files (`.capnp.proxy-client.c++`, `.capnp.proxy-server.c++`,
47+
`.capnp.proxy-types.c++`, etc.) are skipped. Useful when you need
48+
Cap'n Proto serialization without the multiprocess RPC proxy
49+
infrastructure.
50+
4651
Example:
4752
# Assuming `my_library` is a target and `lib/` contains `.capnp` schema
4853
# files with imports from `include/`.
49-
target_capnp_sources(my_library "${CMAKE_SOURCE_DIR}"
54+
target_capnp_sources(my_library "${CMAKE_CURRENT_SOURCE_DIR}"
5055
lib/schema1.capnp lib/schema2.capnp
51-
IMPORT_PATHS ${CMAKE_SOURCE_DIR}/include)
56+
IMPORT_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/include)
5257
5358
#]=]
5459

@@ -98,8 +103,8 @@ function(target_capnp_sources target include_prefix)
98103

99104
# Translate include_prefix from a source path to a binary path and add it as a
100105
# target include directory.
101-
set(build_include_prefix ${CMAKE_BINARY_DIR})
102-
file(RELATIVE_PATH relative_path ${CMAKE_SOURCE_DIR} ${include_prefix})
106+
set(build_include_prefix ${CMAKE_CURRENT_BINARY_DIR})
107+
file(RELATIVE_PATH relative_path ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix})
103108
if(relative_path)
104109
string(APPEND build_include_prefix "/" "${relative_path}")
105110
endif()

0 commit comments

Comments
 (0)