Skip to content
Snippets Groups Projects
Commit a6cbcc2c authored by Martin Bauer's avatar Martin Bauer
Browse files

pystencils-codegen: support for multiple configurations per python file

parent b323b32f
No related merge requests found
......@@ -91,7 +91,7 @@ function ( waLBerla_add_module )
if ( hasSourceFiles )
set( generatedSourceFiles )
set( generatorSourceFiles )
handle_python_codegen(sourceFiles generatedSourceFiles generatorSourceFiles codeGenRequired ${sourceFiles})
handle_python_codegen(sourceFiles generatedSourceFiles generatorSourceFiles codeGenRequired "default_codegen" ${sourceFiles})
if( NOT WALBERLA_BUILD_WITH_CODEGEN AND codeGenRequired)
message(STATUS "Skipping ${ARG_NAME} since pystencils code generation is not enabled")
return()
......@@ -125,6 +125,10 @@ function ( waLBerla_add_module )
ARCHIVE DESTINATION lib )
endif( )
if( codeGenRequired)
target_include_directories(${ARG_NAME} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/default_codegen")
endif()
# Install rule for header
install ( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION "walberla/${moduleName}"
......@@ -159,12 +163,13 @@ endfunction ( waLBerla_add_module )
# The application is linked against all waLBerla modules that are listed after DEPENDS
#
#
# NAME [required] Name of application
# GROUP [optional] IDE group name (e.g. VS)
# DEPENDS [required] list of modules, that this application depends on
# FILES [optional] list of all source and header files belonging to that application
# if this is not given, all source and header files in the directory are added.
# Careful: when file was added or deleted, cmake has to be run again
# NAME [required] Name of application
# GROUP [optional] IDE group name (e.g. VS)
# DEPENDS [required] list of modules, that this application depends on
# FILES [optional] list of all source and header files belonging to that application
# if this is not given, all source and header files in the directory are added.
# Careful: when file was added or deleted, cmake has to be run again
# CODGEN_CFG [optional] string passed to code generation scripts
#
# Example:
# waLBerla_compile_app ( NAME myApp DEPENDS core field lbm/boundary )
......@@ -172,14 +177,18 @@ endfunction ( waLBerla_add_module )
function ( waLBerla_add_executable )
set( options )
set( oneValueArgs NAME GROUP )
set( multiValueArgs FILES DEPENDS )
set( oneValueArgs NAME GROUP CODEGEN_CFG)
set( multiValueArgs FILES DEPENDS)
cmake_parse_arguments( ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
if( NOT ARG_NAME )
message ( FATAL_ERROR "waLBerla_add_executable called without a NAME" )
endif()
if( NOT ARG_CODEGEN_CFG)
set(ARG_CODEGEN_CFG "default_codegen")
endif()
# Skip this app, if it depends on modules that have not been built ( because they for example depend on PE)
foreach ( depMod ${ARG_DEPENDS} )
get_module_library_name ( depModLibraryName ${depMod} )
......@@ -211,7 +220,8 @@ function ( waLBerla_add_executable )
set( generatedSourceFiles )
set( generatorSourceFiles )
handle_python_codegen(sourceFiles generatedSourceFiles generatorSourceFiles codeGenRequired ${sourceFiles})
handle_python_codegen(sourceFiles generatedSourceFiles generatorSourceFiles
codeGenRequired ${ARG_CODEGEN_CFG} ${sourceFiles} )
if( NOT WALBERLA_BUILD_WITH_CODEGEN AND codeGenRequired)
message(STATUS "Skipping ${ARG_NAME} since pystencils code generation is not enabled")
......@@ -237,6 +247,10 @@ function ( waLBerla_add_executable )
set_property( TARGET ${ARG_NAME} PROPERTY FOLDER ${ARG_GROUP} )
endif()
if( codeGenRequired )
target_include_directories(${ARG_NAME} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/${ARG_CODEGEN_CFG}")
endif()
endfunction ( waLBerla_add_executable )
#######################################################################################################################
......
......@@ -31,7 +31,7 @@ endfunction ( add_flag )
# The python script, when called with -l, should return a semicolon-separated list of generated files
# if this list changes, CMake has to be run manually again.
#######################################################################################################################
function( handle_python_codegen sourceFilesOut generatedSourceFilesOut generatorsOut codeGenRequiredOut )
function( handle_python_codegen sourceFilesOut generatedSourceFilesOut generatorsOut codeGenRequiredOut codegenCfg)
set(result )
set(generatedResult )
set(generatorsResult )
......@@ -45,7 +45,7 @@ function( handle_python_codegen sourceFilesOut generatedSourceFilesOut generator
set( generatedWithAbsolutePath )
foreach( filename ${generatedSourceFiles} )
list(APPEND generatedWithAbsolutePath ${CMAKE_CURRENT_BINARY_DIR}/${filename})
list(APPEND generatedWithAbsolutePath ${CMAKE_CURRENT_BINARY_DIR}/${codegenCfg}/${filename})
endforeach()
list(APPEND generatedResult ${generatedWithAbsolutePath} )
......@@ -56,6 +56,7 @@ function( handle_python_codegen sourceFilesOut generatedSourceFilesOut generator
"\\\{\"EXPECTED_FILES\": [\"${jsonFileList}\"], \"CMAKE_VARS\" : \\\{ "
"\"WALBERLA_OPTIMIZE_FOR_LOCALHOST\": \"${WALBERLA_OPTIMIZE_FOR_LOCALHOST}\","
"\"WALBERLA_DOUBLE_ACCURACY\": \"${WALBERLA_DOUBLE_ACCURACY}\","
"\"CODEGEN_CFG\": \"${codegenCfg}\","
"\"WALBERLA_BUILD_WITH_MPI\": \"${WALBERLA_BUILD_WITH_MPI}\","
"\"WALBERLA_BUILD_WITH_CUDA\": \"${WALBERLA_BUILD_WITH_CUDA}\","
"\"WALBERLA_BUILD_WITH_OPENMP\": \"${WALBERLA_BUILD_WITH_OPENMP}\" \\\} \\\}"
......@@ -63,11 +64,11 @@ function( handle_python_codegen sourceFilesOut generatedSourceFilesOut generator
string(REPLACE "\"" "\\\"" pythonParameters ${pythonParameters}) # even one more quoting level required
string(REPLACE "\n" "" pythonParameters ${pythonParameters}) # remove newline characters
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${codegenCfg}")
add_custom_command(OUTPUT ${generatedWithAbsolutePath}
DEPENDS ${sourceFile}
COMMAND ${PYTHON_EXECUTABLE} ${sourceFile} ${pythonParameters}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${codegenCfg}")
endif()
else()
list(APPEND result ${sourceFile})
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment