1if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
2    # The new Python3 module is much more robust than the previous PythonInterp
3    find_package(Python3 COMPONENTS Interpreter)
4    # Set variables for backwards compatibility with cmake < 3.12.0
5    set(PYTHONINTERP_FOUND ${Python3_Interpreter_FOUND})
6    set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
7else()
8    set(Python_ADDITIONAL_VERSIONS 3.8)
9    find_package(PythonInterp 3)
10endif()
11
12add_executable(jsontestrunner_exe
13    main.cpp
14)
15
16if(BUILD_SHARED_LIBS)
17    if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
18        add_compile_definitions( JSON_DLL )
19    else()
20        add_definitions(-DJSON_DLL)
21    endif()
22    target_link_libraries(jsontestrunner_exe jsoncpp_lib)
23else()
24    target_link_libraries(jsontestrunner_exe jsoncpp_static)
25endif()
26
27set_target_properties(jsontestrunner_exe PROPERTIES OUTPUT_NAME jsontestrunner_exe)
28
29if(PYTHONINTERP_FOUND)
30    # Run end to end parser/writer tests
31    set(TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../test)
32    set(RUNJSONTESTS_PATH ${TEST_DIR}/runjsontests.py)
33
34    # Run unit tests in post-build
35    # (default cmake workflow hides away the test result into a file, resulting in poor dev workflow?!?)
36    add_custom_target(jsoncpp_readerwriter_tests
37        "${PYTHON_EXECUTABLE}" -B "${RUNJSONTESTS_PATH}" $<TARGET_FILE:jsontestrunner_exe> "${TEST_DIR}/data"
38        DEPENDS jsontestrunner_exe jsoncpp_test
39    )
40    add_custom_target(jsoncpp_check DEPENDS jsoncpp_readerwriter_tests)
41
42    ## Create tests for dashboard submission, allows easy review of CI results https://my.cdash.org/index.php?project=jsoncpp
43    add_test(NAME jsoncpp_readerwriter
44        COMMAND "${PYTHON_EXECUTABLE}" -B "${RUNJSONTESTS_PATH}" $<TARGET_FILE:jsontestrunner_exe> "${TEST_DIR}/data"
45        WORKING_DIRECTORY "${TEST_DIR}/data"
46    )
47    add_test(NAME jsoncpp_readerwriter_json_checker
48        COMMAND "${PYTHON_EXECUTABLE}" -B "${RUNJSONTESTS_PATH}" --with-json-checker  $<TARGET_FILE:jsontestrunner_exe> "${TEST_DIR}/data"
49        WORKING_DIRECTORY "${TEST_DIR}/data"
50    )
51endif()
52