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 )
endforeach( )
if ( hasSourceFiles )
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)
message(STATUS "Skipping ${ARG_NAME} since pystencils code generation is not enabled")
return()
endif()
if ( CUDA_FOUND )
cuda_add_library( ${moduleLibraryName} STATIC ${sourceFiles} ${otherFiles} )
cuda_add_library( ${moduleLibraryName} STATIC ${sourceFiles} ${generatedSourceFiles} ${generatorSourceFiles} ${otherFiles} )
else()
add_library( ${moduleLibraryName} STATIC ${sourceFiles} ${otherFiles} )
add_library( ${moduleLibraryName} STATIC ${sourceFiles} ${generatedSourceFiles} ${generatorSourceFiles} ${otherFiles} )
endif( CUDA_FOUND )
set_source_files_properties( ${generatedSourceFiles} PROPERTIES GENERATED TRUE )
else( )
add_custom_target( ${moduleLibraryName} SOURCES ${sourceFiles} ${otherFiles} ) # dummy IDE target
endif( )
add_custom_target( ${moduleLibraryName} SOURCES ${sourceFiles} ${generatedSourceFiles} ${otherFiles} ) # dummy IDE target
endif( )
waLBerla_register_dependency ( ${moduleName} ${ARG_DEPENDS} )
# This property is needed for visual studio to group modules together
......@@ -204,17 +208,22 @@ function ( waLBerla_add_executable )
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)
message(STATUS "Skipping ${ARG_NAME} since pystencils code generation is not enabled")
return()
endif()
if ( CUDA_FOUND )
cuda_add_executable( ${ARG_NAME} ${sourceFiles} )
cuda_add_executable( ${ARG_NAME} ${sourceFiles} ${generatedSourceFiles} ${generatorSourceFiles} )
else()
add_executable( ${ARG_NAME} ${sourceFiles} )
add_executable( ${ARG_NAME} ${sourceFiles} ${generatedSourceFiles} ${generatorSourceFiles} )
endif()
set_source_files_properties( ${generatedSourceFiles} PROPERTIES GENERATED TRUE )
target_link_modules ( ${ARG_NAME} ${ARG_DEPENDS} )
target_link_libraries( ${ARG_NAME} ${SERVICE_LIBS} )
......
......@@ -28,8 +28,10 @@ endfunction ( add_flag )
# 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(generatedResult )
set(generatorsResult )
set(codeGenRequired NO)
foreach( sourceFile ${ARGN} )
if( ${sourceFile} MATCHES ".*\\.gen\\.py$" )
......@@ -41,20 +43,23 @@ function( handle_python_codegen sourceFilesOut codeGenRequiredOut )
string(REPLACE ".gen.py" ".h" genHeaderFile ${sourceFileName})
string(REPLACE ".gen.py" ".cpp" genSourceFile ${sourceFileName})
endif()
list(APPEND result ${CMAKE_CURRENT_BINARY_DIR}/${genSourceFile}
${CMAKE_CURRENT_BINARY_DIR}/${genHeaderFile})
list(APPEND generatedResult ${CMAKE_CURRENT_BINARY_DIR}/${genSourceFile}
${CMAKE_CURRENT_BINARY_DIR}/${genHeaderFile})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${genSourceFile}
${CMAKE_CURRENT_BINARY_DIR}/${genHeaderFile}
DEPENDS ${sourceFile}
COMMAND ${PYTHON_EXECUTABLE} ${sourceFile}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
list(APPEND generatorsResult ${sourceFile} )
set(codeGenRequired YES)
else()
list(APPEND result ${sourceFile})
endif()
endforeach()
set( ${sourceFilesOut} ${result} PARENT_SCOPE )
set( ${generatedSourceFilesOut} ${generatedResult} PARENT_SCOPE )
set( ${generatorsOut} ${generatorsResult} PARENT_SCOPE )
set( ${codeGenRequiredOut} ${codeGenRequired} PARENT_SCOPE )
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