Skip to content

Commit 1ec8660

Browse files
authored
capi: Improve header management during build (#11961)
This commit improves the management of header files in cmake to pick up changes to them after-configure in some situations. Previously the cmake scripts would copy all wasmtime headers into the build directory to live adjacent to the `conf.h`-generated header. This meant that there was only one `-I` directory, for example, but it meant that changes to the source files after configuration weren't reflected in the output. This commit fixes this by leaving the source headers in-place. This means that there are now two include directories during building. Various rules/targets should all be updated to handle this, and notably the build script of the C API still copies headers around as it did before (when built via Rust).
1 parent 4b7f3df commit 1ec8660

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

crates/c-api/CMakeLists.txt

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,15 @@ else()
106106
endif()
107107
endif()
108108

109-
target_include_directories(wasmtime INTERFACE ${CMAKE_BINARY_DIR}/include)
110-
set(WASMTIME_HEADER_DST ${CMAKE_BINARY_DIR}/include)
111-
include(cmake/install-headers.cmake)
109+
target_include_directories(wasmtime
110+
INTERFACE include
111+
INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/include)
112+
configure_file(include/wasmtime/conf.h.in include/wasmtime/conf.h)
112113

113114
include(GNUInstallDirs)
114-
install(DIRECTORY "${WASMTIME_HEADER_DST}/" TYPE INCLUDE)
115+
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ TYPE INCLUDE)
116+
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ TYPE INCLUDE
117+
FILES_MATCHING REGEX "\\.hh?$")
115118
install(FILES ${WASMTIME_SHARED_FILES} ${WASMTIME_STATIC_FILES}
116119
DESTINATION ${CMAKE_INSTALL_LIBDIR})
117120

@@ -130,15 +133,6 @@ add_custom_target(doc
130133
COMMAND doxygen ${DOXYGEN_CONF_OUT}
131134
DEPENDS ${WASMTIME_GENERATED_CONF_H} ${DOXYGEN_CONF_OUT}
132135
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
133-
add_dependencies(doc headers-to-doc)
134-
135-
file(GLOB headers "include/*.h")
136-
add_custom_target(headers-to-doc
137-
COMMAND
138-
${CMAKE_COMMAND}
139-
-DWASMTIME_HEADER_DST=${CMAKE_BINARY_DIR}/include
140-
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/install-headers.cmake
141-
DEPENDS ${headers})
142136

143137
if (NOT CMAKE_CXX_STANDARD)
144138
message(STATUS "Cannot detect C++ Standard. Switching to C++17 by default !!")
@@ -168,11 +162,6 @@ else()
168162
target_link_libraries(wasmtime-cpp INTERFACE stdc++ pthread)
169163
endif()
170164

171-
target_include_directories(
172-
wasmtime-cpp
173-
INTERFACE
174-
${PROJECT_SOURCE_DIR}/include)
175-
176165
if (BUILD_TESTS)
177166
message(STATUS "Building tests")
178167
set(CMAKE_CXX_STANDARD 20)

crates/c-api/doxygen.conf.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ WARN_LOGFILE =
864864
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
865865
# Note: If this tag is empty the current directory is searched.
866866

867-
INPUT = @CMAKE_BINARY_DIR@/include
867+
INPUT = @CMAKE_SOURCE_DIR@/include @CMAKE_BINARY_DIR@/include
868868

869869
# This tag can be used to specify the character encoding of the source files
870870
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

0 commit comments

Comments
 (0)