diff --git a/src/pystencilssfg/cmake/modules/PystencilsSfg.cmake b/src/pystencilssfg/cmake/modules/PystencilsSfg.cmake index 03b701d4c3a97489df1758b852293c56fa9fe120..7f3b2da624c0e233ce815071b58d64b8024e6af2 100644 --- a/src/pystencilssfg/cmake/modules/PystencilsSfg.cmake +++ b/src/pystencilssfg/cmake/modules/PystencilsSfg.cmake @@ -6,15 +6,18 @@ to dynamically locate it. #]] -set(PystencilsSfg_GENERATED_SOURCES_DIR "${CMAKE_BINARY_DIR}/sfg_sources" CACHE PATH "Output directory for genenerated sources" ) -mark_as_advanced(PystencilsSfg_GENERATED_SOURCES_DIR) - # This cache variable definition is a duplicate of the one in FindPystencilsSfg.cmake if(NOT DEFINED CACHE{PystencilsSfg_PYTHON_INTERPRETER}) set(PystencilsSfg_PYTHON_INTERPRETER ${Python_EXECUTABLE} CACHE PATH "Path to the Python executable used to run pystencils-sfg") endif() -file(MAKE_DIRECTORY "${PystencilsSfg_GENERATED_SOURCES_DIR}") +if(NOT DEFINED CACHE{_Pystencils_Include_Dir}) + execute_process( + COMMAND ${PystencilsSfg_PYTHON_INTERPRETER} -c "from pystencils.include import get_pystencils_include_path; print(get_pystencils_include_path(), end='')" + OUTPUT_VARIABLE _pystencils_includepath_result + ) + set(_Pystencils_Include_Dir ${_pystencils_includepath_result} CACHE PATH "") +endif() function(_pssfg_add_gen_source target script) set(options) @@ -23,7 +26,10 @@ function(_pssfg_add_gen_source target script) cmake_parse_arguments(_pssfg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - set(generatedSourcesDir ${PystencilsSfg_GENERATED_SOURCES_DIR}/gen/${target}) + set(generatedSourcesIncludeDir ${CMAKE_CURRENT_BINARY_DIR}/_gen/${target}) + set(generatedSourcesDir ${generatedSourcesIncludeDir}/gen) + file(MAKE_DIRECTORY ${generatedSourcesDir}) + get_filename_component(basename ${script} NAME_WLE) cmake_path(ABSOLUTE_PATH script OUTPUT_VARIABLE scriptAbsolute) @@ -31,9 +37,6 @@ function(_pssfg_add_gen_source target script) OUTPUT_VARIABLE generatedSources RESULT_VARIABLE _pssfg_result ERROR_VARIABLE _pssfg_stderr) - execute_process(COMMAND ${PystencilsSfg_PYTHON_INTERPRETER} -c "from pystencils.include import get_pystencils_include_path; print(get_pystencils_include_path(), end='')" - OUTPUT_VARIABLE _Pystencils_INCLUDE_DIR) - if(NOT (${_pssfg_result} EQUAL 0)) message( FATAL_ERROR ${_pssfg_stderr} ) endif() @@ -51,7 +54,7 @@ function(_pssfg_add_gen_source target script) WORKING_DIRECTORY "${generatedSourcesDir}") target_sources(${target} PRIVATE ${generatedSourcesAbsolute}) - target_include_directories(${target} PRIVATE ${PystencilsSfg_GENERATED_SOURCES_DIR} ${_Pystencils_INCLUDE_DIR}) + target_include_directories(${target} PRIVATE ${generatedSourcesIncludeDir} ${_Pystencils_Include_Dir}) endfunction() diff --git a/tests/integration/cmake_project/TestApp.cpp b/tests/integration/cmake_project/TestApp.cpp index 7ceb98b42f40e6c91dddad76170b4654e14d4851..aefde8d7d70a7758f84fbd34d80fe9ad6f6ff7e6 100644 --- a/tests/integration/cmake_project/TestApp.cpp +++ b/tests/integration/cmake_project/TestApp.cpp @@ -1,4 +1,4 @@ -#include "gen/TestApp/GenTest.hpp" +#include "gen/GenTest.hpp" int main(void) { return int( gen::getValue() ); diff --git a/tests/integration/test_cmake.py b/tests/integration/test_cmake.py index 7d539647eb00b60c8b262d049df47c1eed8a1087..1f0d9b2dc55a6be773a87b5ecd9b937dd2d08251 100644 --- a/tests/integration/test_cmake.py +++ b/tests/integration/test_cmake.py @@ -32,13 +32,13 @@ def test_cmake_project(tmp_path, config_source): run_result = subprocess.run(run_cmd) if config_source is not None: - assert (tmp_path / "sfg_sources" / "gen" / "TestApp" / "GenTest.c++").exists() + assert (tmp_path / "_gen" / "TestApp" / "gen" / "GenTest.c++").exists() assert run_result.returncode == 31 else: - assert (tmp_path / "sfg_sources" / "gen" / "TestApp" / "GenTest.cpp").exists() + assert (tmp_path / "_gen" / "TestApp" / "gen" / "GenTest.cpp").exists() assert run_result.returncode == 42 - cli_test_output = tmp_path / "sfg_sources" / "gen" / "TestApp" / "CliTest.hpp" + cli_test_output = tmp_path / "_gen" / "TestApp" / "gen" / "CliTest.hpp" assert cli_test_output.exists() content = cli_test_output.read_text()