Skip to content

Commit 71cd1ec

Browse files
Switch XEUS_SEARCH_PATH from compile-time to runtime
This change: 1. Replaces compile-time XEUS_SEARCH_PATH define with runtime environment variable 2. Removes CMake definition to eliminate redefinition warnings 3. Adds test to verify non-standard include path functionality 4. Makes include path configuration more flexible (can be changed without recompiling) Resolves compiler-research#175
1 parent 3050471 commit 71cd1ec

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

CMakeLists.txt

+16
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ message(STATUS "Building xeus-cpp v${${PROJECT_NAME}_VERSION}")
5050
# Build options
5151
# =============
5252

53+
# Note: XEUS_SEARCH_PATH is now handled at runtime through environment variables
54+
5355
option(XEUS_CPP_BUILD_STATIC "Build xeus-cpp static library" ON)
5456
option(XEUS_CPP_BUILD_SHARED "Split xcpp build into executable and library" ON)
5557
option(XEUS_CPP_BUILD_EXECUTABLE "Build the xcpp executable" ON)
@@ -404,7 +406,21 @@ endif()
404406
# =====
405407

406408
if(XEUS_CPP_BUILD_TESTS)
409+
enable_testing()
407410
add_subdirectory(test)
411+
412+
# Find doctest package
413+
find_package(doctest REQUIRED)
414+
415+
# Test for non-standard include paths
416+
add_executable(test_include_paths test/test_include_paths.cpp)
417+
target_link_libraries(test_include_paths PRIVATE doctest::doctest)
418+
target_include_directories(test_include_paths PRIVATE
419+
${CMAKE_SOURCE_DIR}/test/custom_includes
420+
${DOCTEST_INCLUDE_DIR}
421+
)
422+
target_compile_definitions(test_include_paths PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN)
423+
add_test(NAME test_include_paths COMMAND test_include_paths)
408424
endif()
409425

410426
# Installation

src/xinterpreter.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,13 @@ __get_cxx_version ()
360360
// Add the standard include path
361361
Cpp::AddIncludePath((xeus::prefix_path() + "/include/").c_str());
362362

363-
// Add non-standard include paths from XEUS_SEARCH_PATH
364-
const char* non_standard_paths = XEUS_SEARCH_PATH;
363+
// Get include paths from environment variable
364+
const char* non_standard_paths = std::getenv("XEUS_SEARCH_PATH");
365+
if (!non_standard_paths) {
366+
non_standard_paths = "";
367+
}
365368

366-
if (non_standard_paths && std::strlen(non_standard_paths) > 0)
369+
if (std::strlen(non_standard_paths) > 0)
367370
{
368371
// Split the paths by colon ':' and add each one
369372
std::istringstream stream(non_standard_paths);

test/custom_includes/test_header.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef TEST_HEADER_HPP
2+
#define TEST_HEADER_HPP
3+
4+
namespace test_ns {
5+
constexpr int test_value = 42;
6+
}
7+
8+
#endif

test/test_include_paths.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <doctest/doctest.h>
2+
#include <string>
3+
#include "test_header.hpp"
4+
5+
TEST_CASE("Test non-standard include paths")
6+
{
7+
CHECK(test_ns::test_value == 42);
8+
}

0 commit comments

Comments
 (0)