Skip to content

Commit 1103f86

Browse files
committed
cmake: Define and use MP_INCLUDE_DIR variable
This is needed to refer to the include directory when the cmake project is not a top-level project (when it is included with add_subdirectory) because ${CMAKE_SOURCE_DIR}/include will no longer refer to the right location. This is also nice because the variable can be used in the target_capnp_sources function and simplify calls to that function.
1 parent 10bb7e4 commit 1103f86

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ include("cmake/compat_config.cmake")
2626
include("cmake/pthread_checks.cmake")
2727
include(GNUInstallDirs)
2828

29+
set(MP_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
30+
2931
# Generated C++ preprocessor defines
3032
configure_file(include/mp/config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/mp/config.h")
3133

cmake/TargetCapnpSources.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function(target_capnp_sources target include_prefix)
6868
foreach(capnp_file IN LISTS TCS_UNPARSED_ARGUMENTS)
6969
add_custom_command(
7070
OUTPUT ${capnp_file}.c++ ${capnp_file}.h ${capnp_file}.proxy-client.c++ ${capnp_file}.proxy-types.h ${capnp_file}.proxy-server.c++ ${capnp_file}.proxy-types.c++ ${capnp_file}.proxy.h
71-
COMMAND Libmultiprocess::mpgen ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS}
71+
COMMAND Libmultiprocess::mpgen ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS} ${MP_INCLUDE_DIR}
7272
DEPENDS ${capnp_file}
7373
VERBATIM
7474
)
@@ -89,7 +89,7 @@ function(target_capnp_sources target include_prefix)
8989
if(relative_path)
9090
string(APPEND build_include_prefix "/" "${relative_path}")
9191
endif()
92-
target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${build_include_prefix}>)
92+
target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${build_include_prefix}> ${MP_INCLUDE_DIR})
9393

9494
if(TARGET Libmultiprocess::multiprocess)
9595
target_link_libraries(${target} PRIVATE Libmultiprocess::multiprocess)

example/CMakeLists.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,21 @@ include(${PROJECT_SOURCE_DIR}/cmake/TargetCapnpSources.cmake)
77
add_executable(mpcalculator
88
calculator.cpp
99
)
10-
target_capnp_sources(mpcalculator ${CMAKE_CURRENT_SOURCE_DIR} init.capnp calculator.capnp printer.capnp
11-
IMPORT_PATHS ${CMAKE_SOURCE_DIR}/include
12-
)
10+
target_capnp_sources(mpcalculator ${CMAKE_CURRENT_SOURCE_DIR} init.capnp calculator.capnp printer.capnp)
1311
target_include_directories(mpcalculator PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
1412
target_link_libraries(mpcalculator PRIVATE Threads::Threads)
1513

1614
add_executable(mpprinter
1715
printer.cpp
1816
)
19-
target_capnp_sources(mpprinter ${CMAKE_CURRENT_SOURCE_DIR} init.capnp calculator.capnp printer.capnp
20-
IMPORT_PATHS ${CMAKE_SOURCE_DIR}/include
21-
)
17+
target_capnp_sources(mpprinter ${CMAKE_CURRENT_SOURCE_DIR} init.capnp calculator.capnp printer.capnp)
2218
target_include_directories(mpprinter PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
2319
target_link_libraries(mpprinter PRIVATE Threads::Threads)
2420

2521
add_executable(mpexample
2622
example.cpp
2723
)
28-
target_capnp_sources(mpexample ${CMAKE_CURRENT_SOURCE_DIR} init.capnp calculator.capnp printer.capnp
29-
IMPORT_PATHS ${CMAKE_SOURCE_DIR}/include
30-
)
24+
target_capnp_sources(mpexample ${CMAKE_CURRENT_SOURCE_DIR} init.capnp calculator.capnp printer.capnp)
3125
target_include_directories(mpexample PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
3226
target_link_libraries(mpexample PRIVATE Threads::Threads)
3327
target_link_libraries(mpexample PRIVATE stdc++fs)

test/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ if(BUILD_TESTING AND TARGET CapnProto::kj-test)
2424
mp/test/test.cpp
2525
)
2626
include(${PROJECT_SOURCE_DIR}/cmake/TargetCapnpSources.cmake)
27-
target_capnp_sources(mptest ${CMAKE_CURRENT_SOURCE_DIR} mp/test/foo.capnp
28-
IMPORT_PATHS ${CMAKE_SOURCE_DIR}/include
29-
)
27+
target_capnp_sources(mptest ${CMAKE_CURRENT_SOURCE_DIR} mp/test/foo.capnp)
3028
target_include_directories(mptest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
3129
target_link_libraries(mptest PRIVATE CapnProto::kj-test)
3230
target_link_libraries(mptest PRIVATE Threads::Threads)

0 commit comments

Comments
 (0)