Automatically re-amalgamate when source/headers change
This commit is contained in:
parent
a3b39dfd1a
commit
6cd418b60a
|
@ -9,18 +9,29 @@ set(SINGLEHEADER_FILES
|
|||
${CMAKE_CURRENT_BINARY_DIR}/amalgamate_demo.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/README.md
|
||||
)
|
||||
set(SINGLEHEADER_REPO_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/simdjson.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/simdjson.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/amalgamate_demo.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/README.md
|
||||
)
|
||||
set_source_files_properties(${SINGLEHEADER_FILES} PROPERTIES GENERATED TRUE)
|
||||
|
||||
if (MSVC)
|
||||
# MSVC doesn't have bash, so we use existing amalgamated files instead of generating them ...
|
||||
add_custom_command(
|
||||
OUTPUT ${SINGLEHEADER_FILES}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
simdjson.cpp simdjson.h amalgamate_demo.cpp README.md
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
DEPENDS simdjson.cpp simdjson.h amalgamate_demo.cpp README.md
|
||||
)
|
||||
else()
|
||||
# (Do not do this if the source and destination are the same!)
|
||||
if (NOT (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}))
|
||||
add_custom_command(
|
||||
OUTPUT ${SINGLEHEADER_FILES}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${SINGLEHEADER_REPO_FILES}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
DEPENDS ${SINGLEHEADER_REPO_FILES}
|
||||
)
|
||||
endif()
|
||||
|
||||
else(MSVC)
|
||||
|
||||
##
|
||||
# Important! The script amalgamate.sh is not generally executable. It
|
||||
# assumes that bash is at /bin/bash which may not be true.
|
||||
|
@ -32,11 +43,38 @@ else()
|
|||
AMALGAMATE_INPUT_PATH=${PROJECT_SOURCE_DIR}/include
|
||||
AMALGAMATE_OUTPUT_PATH=${CMAKE_CURRENT_BINARY_DIR}
|
||||
bash ${CMAKE_CURRENT_SOURCE_DIR}/amalgamate.sh
|
||||
DEPENDS amalgamate.sh simdjson-source
|
||||
#
|
||||
# This is the best way I could find to make amalgamation trigger whenever source files or
|
||||
# header files change: since the "simdjson" library has to get rebuilt when that happens, we
|
||||
# take a dependency on the generated library file (even though we're not using it). Depending
|
||||
# on simdjson-source doesn't do the trick because DEPENDS here can only depend on an
|
||||
# *artifact*--it won't scan source and include files the way a concrete library or executable
|
||||
# will.
|
||||
#
|
||||
# It sucks that we have to build the actual library to make it happen, but it's better than\
|
||||
# nothing!
|
||||
#
|
||||
DEPENDS amalgamate.sh simdjson
|
||||
)
|
||||
endif()
|
||||
|
||||
add_custom_target(amalgamate DEPENDS ${SIINGLEHEADER_FILES})
|
||||
# This is used by "make amalgamate" to update the original source files. We obviously don't do
|
||||
# this if source and generated files are in the same place--cmake gets mad!
|
||||
if (NOT (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}))
|
||||
add_custom_command(
|
||||
# We don't really need want this to trigger other stuff, it's a terminal target.
|
||||
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/simdjson.cpp ${CMAKE_CURRENT_SOURCE_DIR}/simdjson.h ${CMAKE_CURRENT_SOURCE_DIR}/amalgamate_demo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/README.md
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${SINGLEHEADER_FILES} ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPENDS ${SINGLEHEADER_FILES}
|
||||
)
|
||||
endif()
|
||||
|
||||
#
|
||||
# "make amalgamate" to generate the header files directly and update the original source
|
||||
#
|
||||
add_custom_target(amalgamate DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/simdjson.cpp ${CMAKE_CURRENT_SOURCE_DIR}/simdjson.h ${CMAKE_CURRENT_SOURCE_DIR}/amalgamate_demo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
|
||||
|
||||
endif(MSVC)
|
||||
|
||||
|
||||
#
|
||||
# Include this if you intend to #include "simdjson.cpp" in your own .cpp files.
|
||||
|
@ -56,5 +94,5 @@ add_dependencies(simdjson-singleheader-source amalgamate)
|
|||
# Test the generated simdjson.cpp/simdjson.h using the generated amalgamate_demo.cpp
|
||||
#
|
||||
add_executable(amalgamate_demo $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/amalgamate_demo.cpp>)
|
||||
target_link_libraries(amalgamate_demo simdjson-singleheader-include-source)
|
||||
target_link_libraries(amalgamate_demo simdjson-singleheader-include-source simdjson-flags)
|
||||
add_test(amalgamate_demo amalgamate_demo ${EXAMPLE_JSON} ${EXAMPLE_NDJSON})
|
||||
|
|
Loading…
Reference in New Issue