Commit 8ad4dbd9 authored by Christian Godenschwager's avatar Christian Godenschwager
Browse files

Improvements to code generator

- Add generator files to targets to show them in VS solutions
- mark generated files as such in CMake
parent a89c9eed
Pipeline #4794 passed with stages
in 113 minutes and 42 seconds
...@@ -90,21 +90,25 @@ function ( waLBerla_add_module ) ...@@ -90,21 +90,25 @@ function ( waLBerla_add_module )
endforeach( ) endforeach( )
if ( hasSourceFiles ) if ( hasSourceFiles )
set( generatedSourceFiles )
handle_python_codegen(sourceFiles codeGenRequired ${sourceFiles}) set( generatorSourceFiles )
handle_python_codegen(sourceFiles generatedSourceFiles generatorSourceFiles codeGenRequired ${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()
endif() endif()
if ( CUDA_FOUND ) if ( CUDA_FOUND )
cuda_add_library( ${moduleLibraryName} STATIC ${sourceFiles} ${otherFiles} ) cuda_add_library( ${moduleLibraryName} STATIC ${sourceFiles} ${generatedSourceFiles} ${generatorSourceFiles} ${otherFiles} )
else() else()
add_library( ${moduleLibraryName} STATIC ${sourceFiles} ${otherFiles} ) add_library( ${moduleLibraryName} STATIC ${sourceFiles} ${generatedSourceFiles} ${generatorSourceFiles} ${otherFiles} )
endif( CUDA_FOUND ) endif( CUDA_FOUND )
set_source_files_properties( ${generatedSourceFiles} PROPERTIES GENERATED TRUE )
else( ) else( )
add_custom_target( ${moduleLibraryName} SOURCES ${sourceFiles} ${otherFiles} ) # dummy IDE target add_custom_target( ${moduleLibraryName} SOURCES ${sourceFiles} ${generatedSourceFiles} ${otherFiles} ) # dummy IDE target
endif( ) endif( )
waLBerla_register_dependency ( ${moduleName} ${ARG_DEPENDS} ) waLBerla_register_dependency ( ${moduleName} ${ARG_DEPENDS} )
# This property is needed for visual studio to group modules together # This property is needed for visual studio to group modules together
...@@ -204,17 +208,22 @@ function ( waLBerla_add_executable ) ...@@ -204,17 +208,22 @@ function ( waLBerla_add_executable )
endif ( ) endif ( )
endif() endif()
handle_python_codegen(sourceFiles codeGenRequired ${sourceFiles}) set( generatedSourceFiles )
set( generatorSourceFiles )
handle_python_codegen(sourceFiles generatedSourceFiles generatorSourceFiles codeGenRequired ${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()
endif() endif()
if ( CUDA_FOUND ) if ( CUDA_FOUND )
cuda_add_executable( ${ARG_NAME} ${sourceFiles} ) cuda_add_executable( ${ARG_NAME} ${sourceFiles} ${generatedSourceFiles} ${generatorSourceFiles} )
else() else()
add_executable( ${ARG_NAME} ${sourceFiles} ) add_executable( ${ARG_NAME} ${sourceFiles} ${generatedSourceFiles} ${generatorSourceFiles} )
endif() endif()
set_source_files_properties( ${generatedSourceFiles} PROPERTIES GENERATED TRUE )
target_link_modules ( ${ARG_NAME} ${ARG_DEPENDS} ) target_link_modules ( ${ARG_NAME} ${ARG_DEPENDS} )
target_link_libraries( ${ARG_NAME} ${SERVICE_LIBS} ) target_link_libraries( ${ARG_NAME} ${SERVICE_LIBS} )
......
...@@ -28,8 +28,10 @@ endfunction ( add_flag ) ...@@ -28,8 +28,10 @@ endfunction ( add_flag )
# Additionally creates a custom build rule for the code generation # Additionally creates a custom build rule for the code generation
# #
####################################################################################################################### #######################################################################################################################
function( handle_python_codegen sourceFilesOut codeGenRequiredOut ) function( handle_python_codegen sourceFilesOut generatedSourceFilesOut generatorsOut codeGenRequiredOut )
set(result ) set(result )
set(generatedResult )
set(generatorsResult )
set(codeGenRequired NO) set(codeGenRequired NO)
foreach( sourceFile ${ARGN} ) foreach( sourceFile ${ARGN} )
if( ${sourceFile} MATCHES ".*\\.gen\\.py$" ) if( ${sourceFile} MATCHES ".*\\.gen\\.py$" )
...@@ -41,20 +43,23 @@ function( handle_python_codegen sourceFilesOut codeGenRequiredOut ) ...@@ -41,20 +43,23 @@ function( handle_python_codegen sourceFilesOut codeGenRequiredOut )
string(REPLACE ".gen.py" ".h" genHeaderFile ${sourceFileName}) string(REPLACE ".gen.py" ".h" genHeaderFile ${sourceFileName})
string(REPLACE ".gen.py" ".cpp" genSourceFile ${sourceFileName}) string(REPLACE ".gen.py" ".cpp" genSourceFile ${sourceFileName})
endif() endif()
list(APPEND result ${CMAKE_CURRENT_BINARY_DIR}/${genSourceFile} list(APPEND generatedResult ${CMAKE_CURRENT_BINARY_DIR}/${genSourceFile}
${CMAKE_CURRENT_BINARY_DIR}/${genHeaderFile}) ${CMAKE_CURRENT_BINARY_DIR}/${genHeaderFile})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${genSourceFile} add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${genSourceFile}
${CMAKE_CURRENT_BINARY_DIR}/${genHeaderFile} ${CMAKE_CURRENT_BINARY_DIR}/${genHeaderFile}
DEPENDS ${sourceFile} DEPENDS ${sourceFile}
COMMAND ${PYTHON_EXECUTABLE} ${sourceFile} COMMAND ${PYTHON_EXECUTABLE} ${sourceFile}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR})
list(APPEND generatorsResult ${sourceFile} )
set(codeGenRequired YES) set(codeGenRequired YES)
else() else()
list(APPEND result ${sourceFile}) list(APPEND result ${sourceFile})
endif() endif()
endforeach() endforeach()
set( ${sourceFilesOut} ${result} PARENT_SCOPE ) set( ${sourceFilesOut} ${result} PARENT_SCOPE )
set( ${generatedSourceFilesOut} ${generatedResult} PARENT_SCOPE )
set( ${generatorsOut} ${generatorsResult} PARENT_SCOPE )
set( ${codeGenRequiredOut} ${codeGenRequired} PARENT_SCOPE ) set( ${codeGenRequiredOut} ${codeGenRequired} PARENT_SCOPE )
endfunction ( handle_python_codegen ) endfunction ( handle_python_codegen )
####################################################################################################################### #######################################################################################################################
......
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