Hot questions for Using Cap'n Proto in cmake

Question:

I have temp.capnp file where my cmake file has

find_package(CapnProto CONFIG REQUIRED)
include_directories(${CAPNP_INCLUDE_DIRS})
add_definitions(${CAPNP_DEFINITIONS})

set(CAPNPC_SRC_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}" CACHE STRING "" FORCE)
set(CAPNPC_OUTPUT_DIR "." CACHE STRING "" FORCE)
file(MAKE_DIRECTORY "${CAPNPC_OUTPUT_DIR}")

capnp_generate_cpp(CAPNP_SOURCES CAPNP_HEADERS temp.capnp)

with this, it does not generate respective files for capnp, it does not give any error as well. what I am missing here?


Answer:

Macro capnp_generate_cpp generates files in form of the add_custom_command, that is, nothing is performed unless some target depends on these files.

The most simple form of such dependency is produced by add_executable:

# Create rules for generate source and header files.
capnp_generate_cpp(CAPNP_SOURCES CAPNP_HEADERS temp.capnp)
# Consume these files for executable.
add_executable(foo main.cpp ${CAPNP_SOURCES} ${CAPNP_HEADERS})

BTW, such example is provided in the description for CapnProtoConfig.cmake script, which is processed via find_package(CapnProto). (Do not forget about other lines in this example for make the executable built successfully).