Commit a6cbcc2c authored by Martin Bauer's avatar Martin Bauer

pystencils-codegen: support for multiple configurations per python file

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