Skip to content

Commit

Permalink
Switch XEUS_SEARCH_PATH from compile-time to runtime
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AhmedFatthy1040 committed Dec 3, 2024
1 parent 3050471 commit 71cd1ec
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions test/custom_includes/test_header.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef TEST_HEADER_HPP
#define TEST_HEADER_HPP

namespace test_ns {
constexpr int test_value = 42;
}

#endif
8 changes: 8 additions & 0 deletions test/test_include_paths.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <doctest/doctest.h>
#include <string>
#include "test_header.hpp"

TEST_CASE("Test non-standard include paths")
{
CHECK(test_ns::test_value == 42);
}

0 comments on commit 71cd1ec

Please sign in to comment.