diff --git a/CMakeLists.txt b/CMakeLists.txt index be5d3928..bf898e82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,8 @@ message(STATUS "Building xeus-cpp v${${PROJECT_NAME}_VERSION}") # Build options # ============= +# Note: XEUS_SEARCH_PATH is now handled at runtime through environment variables + option(XEUS_CPP_BUILD_STATIC "Build xeus-cpp static library" ON) option(XEUS_CPP_BUILD_SHARED "Split xcpp build into executable and library" ON) option(XEUS_CPP_BUILD_EXECUTABLE "Build the xcpp executable" ON) @@ -404,7 +406,21 @@ endif() # ===== if(XEUS_CPP_BUILD_TESTS) + enable_testing() add_subdirectory(test) + + # Find doctest package + find_package(doctest REQUIRED) + + # Test for non-standard include paths + add_executable(test_include_paths test/test_include_paths.cpp) + target_link_libraries(test_include_paths PRIVATE doctest::doctest) + target_include_directories(test_include_paths PRIVATE + ${CMAKE_SOURCE_DIR}/test/custom_includes + ${DOCTEST_INCLUDE_DIR} + ) + target_compile_definitions(test_include_paths PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN) + add_test(NAME test_include_paths COMMAND test_include_paths) endif() # Installation diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index abcec349..8a8018f1 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -360,10 +360,13 @@ __get_cxx_version () // Add the standard include path Cpp::AddIncludePath((xeus::prefix_path() + "/include/").c_str()); - // Add non-standard include paths from XEUS_SEARCH_PATH - const char* non_standard_paths = XEUS_SEARCH_PATH; + // Get include paths from environment variable + const char* non_standard_paths = std::getenv("XEUS_SEARCH_PATH"); + if (!non_standard_paths) { + non_standard_paths = ""; + } - if (non_standard_paths && std::strlen(non_standard_paths) > 0) + if (std::strlen(non_standard_paths) > 0) { // Split the paths by colon ':' and add each one std::istringstream stream(non_standard_paths); diff --git a/test/custom_includes/test_header.hpp b/test/custom_includes/test_header.hpp new file mode 100644 index 00000000..ad3354b1 --- /dev/null +++ b/test/custom_includes/test_header.hpp @@ -0,0 +1,8 @@ +#ifndef TEST_HEADER_HPP +#define TEST_HEADER_HPP + +namespace test_ns { + constexpr int test_value = 42; +} + +#endif diff --git a/test/test_include_paths.cpp b/test/test_include_paths.cpp new file mode 100644 index 00000000..b27bf670 --- /dev/null +++ b/test/test_include_paths.cpp @@ -0,0 +1,8 @@ +#include +#include +#include "test_header.hpp" + +TEST_CASE("Test non-standard include paths") +{ + CHECK(test_ns::test_value == 42); +}