diff --git a/cmake/generate_documentation.cmake b/cmake/generate_documentation.cmake index 6c3990b..380e543 100644 --- a/cmake/generate_documentation.cmake +++ b/cmake/generate_documentation.cmake @@ -5,6 +5,7 @@ if(CMKR_GENERATE_DOCUMENTATION) # Hook the add_test function to capture the tests in the order declared in tests/cmake.toml function(add_test) cmake_parse_arguments(TEST "" "WORKING_DIRECTORY" "" ${ARGN}) + get_filename_component(TEST_WORKING_DIRECTORY "${TEST_WORKING_DIRECTORY}" NAME) list(APPEND CMKR_TESTS "${TEST_WORKING_DIRECTORY}") set(CMKR_TESTS "${CMKR_TESTS}" CACHE INTERNAL "") _add_test(${test} ${ARGN}) @@ -19,7 +20,9 @@ function(generate_documentation) set(example_folder "${PROJECT_SOURCE_DIR}/docs/examples") file(GLOB example_files "${example_folder}/*.md") list(REMOVE_ITEM example_files "${example_folder}/index.md") - file(REMOVE ${example_files}) + if(example_files) + file(REMOVE ${example_files}) + endif() message(DEBUG "[cmkr] Test directories: ${CMKR_TESTS}") set(test_index 0) diff --git a/src/gen.cpp b/src/gen.cpp index 352c678..c660ffd 100644 --- a/src/gen.cpp +++ b/src/gen.cpp @@ -721,7 +721,11 @@ int generate_cmake(const char *path, bool root) { for (const auto &test : cmake.tests) { auto name = std::make_pair("NAME", test.name); auto configurations = std::make_pair("CONFIGURATIONS", test.configurations); - auto working_directory = std::make_pair("WORKING_DIRECTORY", test.working_directory); + auto dir = test.working_directory; + if (fs::is_directory(fs::path(path) / dir)) { + dir = "${CMAKE_CURRENT_LIST_DIR}/" + dir; + } + auto working_directory = std::make_pair("WORKING_DIRECTORY", dir); auto command = std::make_pair("COMMAND", test.command); auto arguments = std::make_pair("", test.arguments); cmd("add_test")(name, configurations, working_directory, command, arguments).endl(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1467cd1..19efc1f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,7 +12,7 @@ add_test( NAME basic WORKING_DIRECTORY - basic + "${CMAKE_CURRENT_LIST_DIR}/basic" COMMAND $ build @@ -22,7 +22,7 @@ add_test( NAME interface WORKING_DIRECTORY - interface + "${CMAKE_CURRENT_LIST_DIR}/interface" COMMAND $ build @@ -32,7 +32,7 @@ add_test( NAME fetch-content WORKING_DIRECTORY - fetch-content + "${CMAKE_CURRENT_LIST_DIR}/fetch-content" COMMAND $ build @@ -42,7 +42,7 @@ add_test( NAME conditions WORKING_DIRECTORY - conditions + "${CMAKE_CURRENT_LIST_DIR}/conditions" COMMAND $ build