diff --git a/CMakeLists.txt b/CMakeLists.txt index 39798ec2..f6c4a078 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -460,6 +460,7 @@ if(EMSCRIPTEN) # 3) Shift the resource dir and the sysroot to a common location. # 4) Preload everything required together. endif() + # Tests # ===== diff --git a/include/xeus-cpp/xinterpreter.hpp b/include/xeus-cpp/xinterpreter.hpp index 25eeb049..20c2ab4b 100644 --- a/include/xeus-cpp/xinterpreter.hpp +++ b/include/xeus-cpp/xinterpreter.hpp @@ -12,6 +12,7 @@ #define XEUS_CPP_INTERPRETER_HPP #include +#include #include #include #include diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index 5ed527e3..4e2b6e16 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -112,6 +112,7 @@ __get_cxx_version () createInterpreter(Args(argv ? argv + 1 : argv, argv + argc)); m_version = get_stdopt(); redirect_output(); + init_includes(); init_preamble(); init_magic(); } @@ -356,6 +357,24 @@ __get_cxx_version () publish_stream("stderr", s); } + void interpreter::init_includes() + { + if (const char* paths = std::getenv("XEUS_SEARCH_PATH")) + { + std::istringstream stream(paths); + std::string path; + char delimiter = (std::string(paths).find(';') != std::string::npos) ? ';' : ':'; + + while (std::getline(stream, path, delimiter)) + { + if (!path.empty()) + { + Cpp::AddIncludePath(path.c_str()); + } + } + } + } + void interpreter::init_preamble() { //NOLINTBEGIN(cppcoreguidelines-owning-memory) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8ef68992..e323a468 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -67,3 +67,21 @@ target_link_libraries(test_xeus_cpp xeus-cpp doctest::doctest ${CMAKE_THREAD_LIB target_include_directories(test_xeus_cpp PRIVATE ${XEUS_CPP_INCLUDE_DIR}) add_custom_target(xtest COMMAND test_xeus_cpp DEPENDS test_xeus_cpp) + +# Test for non-standard include paths +add_executable(test_include_paths 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) + +set(XEUS_SEARCH_PATH $,:>) + +if (NOT EMSCRIPTEN) + set(XEUS_SEARCH_PATH "${XEUS_SEARCH_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/src") +endif() + +target_compile_definitions(xeus-cpp PRIVATE "XEUS_SEARCH_PATH=\"${XEUS_SEARCH_PATH}\"") \ No newline at end of file diff --git a/test/custom_includes/test_header.hpp b/test/custom_includes/test_header.hpp new file mode 100644 index 00000000..16bded66 --- /dev/null +++ b/test/custom_includes/test_header.hpp @@ -0,0 +1,9 @@ +#ifndef TEST_HEADER_HPP +#define TEST_HEADER_HPP + +namespace test_ns +{ + constexpr int test_value = 42; +} + +#endif \ No newline at end of file diff --git a/test/test_include_paths.cpp b/test/test_include_paths.cpp new file mode 100644 index 00000000..95580364 --- /dev/null +++ b/test/test_include_paths.cpp @@ -0,0 +1,8 @@ +#include "test_header.hpp" +#include +#include + +TEST_CASE("Test non-standard include paths") +{ + CHECK(test_ns::test_value == 42); +} \ No newline at end of file