From 527a69bb64d2d03e385b02cfec72130e70f9b37f Mon Sep 17 00:00:00 2001 From: Chris Kitching Date: Wed, 11 May 2016 01:38:52 +0100 Subject: [PATCH] Install the test binary and test data. Fixes #241 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The resulting install tree, when tests are enabled, looks like this: ``` . ├── cmake │   ├── nlohmann_jsonConfig.cmake │   ├── nlohmann_jsonConfigVersion.cmake │   └── nlohmann_jsonTargets.cmake ├── include │   └── nlohmann │   └── json.hpp └── test ├── bin │   └── json_unit └── data ├── json_nlohmann_tests │   ├── all_unicode.json │   └── bom.json ├── json.org │   ├── 1.json │   ├── ... ├── json_roundtrip │   ├── roundtrip01.json │   ├── roundtrip02.json │   └── ... ├── json_tests │   ├── fail10.json │   └── ... └── json_testsuite └── sample.json ``` It has the property that you can invoke the test binary from the root of the install tree and the tests work correctly (you no longer depend on the test binary being run inside the source tree). If tests are disabled, the entire `test/` subtree is omitted. Notice how that yields exactly what you want for using this library in other projects. I do not believe I need to update travis due to this change, as the evil Makefile continues to do in-tree builds. I expect I'll find out soon enough. --- test/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0039fd84c..b63e5a394 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,5 +11,11 @@ set_target_properties(json_unit PROPERTIES COMPILE_OPTIONS "$<$:/EHsc;$<$:/Od>>" ) +# Install the test binary. +install(TARGETS json_unit RUNTIME DESTINATION test/bin) + +# Copy the test data to the install tree. +install(DIRECTORY data/ DESTINATION test/data) + target_include_directories(json_unit PRIVATE "src") target_link_libraries(json_unit ${JSON_TARGET_NAME})