diff --git a/CMakeLists.txt b/CMakeLists.txt index 0de496a7..3d6fc0c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,8 +13,8 @@ set(SIMDJSON_LIB_SOVERSION "1" CACHE STRING "simdjson library soversion") set(SIMDJSON_GITHUB_REPOSITORY https://github.com/simdjson/simdjson) include(GNUInstallDirs) -include(simdjson-flags.cmake) -include(simdjson-user-cmakecache.cmake) +include(cmake/simdjson-flags.cmake) +include(cmake/simdjson-user-cmakecache.cmake) if(SIMDJSON_JUST_LIBRARY) MESSAGE( STATUS "Building just the library, omitting all tests, tools and benchmarks." ) diff --git a/tests/add_cpp_test.cmake b/cmake/add_cpp_test.cmake similarity index 60% rename from tests/add_cpp_test.cmake rename to cmake/add_cpp_test.cmake index 417b67e8..b41087fa 100644 --- a/tests/add_cpp_test.cmake +++ b/cmake/add_cpp_test.cmake @@ -3,19 +3,23 @@ # SOURCES defaults to testname.cpp if not specified. function(add_cpp_test TEST_NAME) # Parse arguments - cmake_parse_arguments(PARSE_ARGV 1 ARGS "COMPILE_ONLY;WILL_FAIL" "" "SOURCES;LABELS") + cmake_parse_arguments(PARSE_ARGV 1 ARGS "COMPILE_ONLY;LIBRARY;WILL_FAIL" "" "SOURCES;LABELS") if (NOT ARGS_SOURCES) list(APPEND ARGS_SOURCES ${TEST_NAME}.cpp) endif() - if (COMPILE_ONLY) + if (ARGS_COMPILE_ONLY) list(APPEND ${ARGS_LABELS} compile) endif() - # Add executable - add_executable(${TEST_NAME} ${ARGS_SOURCES}) + # Add the compile target + if (ARGS_LIBRARY) + add_library(${TEST_NAME} STATIC ${ARGS_SOURCES}) + else(ARGS_LIBRARY) + add_executable(${TEST_NAME} ${ARGS_SOURCES}) + endif(ARGS_LIBRARY) # Add test - if (ARGS_COMPILE_ONLY) + if (ARGS_COMPILE_ONLY OR ARGS_LIBRARY) add_test( NAME ${TEST_NAME} COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME} --config $ @@ -34,3 +38,12 @@ function(add_cpp_test TEST_NAME) set_property(TEST ${TEST_NAME} PROPERTY WILL_FAIL TRUE) endif() endfunction() + +function(add_compile_only_test TEST_NAME) + add_test( + NAME ${TEST_NAME} + COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME} --config $ + WORKING_DIRECTORY ${PROJECT_BINARY_DIR} + ) + set_target_properties(${TEST_NAME} PROPERTIES EXCLUDE_FROM_ALL TRUE EXCLUDE_FROM_DEFAULT_BUILD TRUE) +endfunction() \ No newline at end of file diff --git a/simdjson-flags.cmake b/cmake/simdjson-flags.cmake similarity index 99% rename from simdjson-flags.cmake rename to cmake/simdjson-flags.cmake index 907805fa..e040accb 100644 --- a/simdjson-flags.cmake +++ b/cmake/simdjson-flags.cmake @@ -1,4 +1,5 @@ option(SIMDJSON_JUST_LIBRARY "Build just the library, omit tests, tools and benchmarks" OFF) + # # Flags used by exes and by the simdjson library (project-wide flags) # diff --git a/simdjson-user-cmakecache.cmake b/cmake/simdjson-user-cmakecache.cmake similarity index 100% rename from simdjson-user-cmakecache.cmake rename to cmake/simdjson-user-cmakecache.cmake diff --git a/singleheader/CMakeLists.txt b/singleheader/CMakeLists.txt index c7e9de0c..f2015939 100644 --- a/singleheader/CMakeLists.txt +++ b/singleheader/CMakeLists.txt @@ -1,3 +1,5 @@ +include(${PROJECT_SOURCE_DIR}/cmake/add_cpp_test.cmake) + # # Amalgamation # @@ -122,6 +124,7 @@ install(FILES simdjson.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) add_library(simdjson-singleheader STATIC "") target_link_libraries(simdjson-singleheader simdjson-singleheader-source simdjson-internal-flags) +add_compile_only_test(simdjson-singleheader) # # Test the existing simdjson.cpp/simdjson.h using the existing amalgamate_demo.cpp, using diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ee1bb8ab..c15c164e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,7 +37,7 @@ endfunction() # Most tests need test data, and many need windows headers. link_libraries(simdjson-internal-flags test-data simdjson-windows-headers) -include(${PROJECT_SOURCE_DIR}/tests/add_cpp_test.cmake) +include(${PROJECT_SOURCE_DIR}/cmake/add_cpp_test.cmake) # # These tests explicitly do #include "simdjson.cpp" so they can override stuff