Skip to content
Snippets Groups Projects
Commit 6a5d7e3d authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Move generated files output directory below current binary dir

parent 0b3c60f2
No related branches found
No related tags found
1 merge request!16CMake Interaction Update
Pipeline #73073 passed
......@@ -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()
......
#include "gen/TestApp/GenTest.hpp"
#include "gen/GenTest.hpp"
int main(void) {
return int( gen::getValue() );
......
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment