Skip to content
Snippets Groups Projects
Commit ff0b2e5d authored by Dominic Kempf's avatar Dominic Kempf
Browse files

Remove CMake generated main function file

parent 56f2a6a1
No related branches found
No related tags found
No related merge requests found
install(FILES DunePerftoolMacros.cmake install(FILES deplist.py
DunePerftoolMacros.cmake
GeneratedSystemtest.cmake
perftool_sourcepath.py
DESTINATION ${DUNE_INSTALL_MODULEDIR}) DESTINATION ${DUNE_INSTALL_MODULEDIR})
...@@ -96,23 +96,18 @@ function(add_generated_executable) ...@@ -96,23 +96,18 @@ function(add_generated_executable)
endif() endif()
if(NOT GEN_SOURCE) if(NOT GEN_SOURCE)
# Generate a driver file # Generate a driver file
set(GEN_DRIVER ${GEN_TARGET}_driver.hh) set(GEN_SOURCE ${GEN_TARGET}_driver.cc)
add_custom_command(OUTPUT ${GEN_DRIVER} add_custom_command(OUTPUT ${GEN_SOURCE}
COMMAND ${CMAKE_BINARY_DIR}/run-in-dune-env generate_driver COMMAND ${CMAKE_BINARY_DIR}/run-in-dune-env generate_driver
--uflfile ${GEN_UFLFILE} --uflfile ${GEN_UFLFILE}
--ini-file ${GEN_INIFILE} --ini-file ${GEN_INIFILE}
--target-name ${GEN_TARGET} --target-name ${GEN_TARGET}
--driver-file ${GEN_DRIVER} --driver-file ${GEN_SOURCE}
--project-basedir ${CMAKE_BINARY_DIR} --project-basedir ${CMAKE_BINARY_DIR}
${GEN_FORM_COMPILER_ARGS} ${GEN_FORM_COMPILER_ARGS}
DEPENDS ${GEN_UFLFILE} ${UFL2PDELAB_SOURCES} ${GEN_DEPENDS} ${DUNE_PERFTOOL_ADDITIONAL_PYTHON_SOURCES} DEPENDS ${GEN_UFLFILE} ${UFL2PDELAB_SOURCES} ${GEN_DEPENDS} ${DUNE_PERFTOOL_ADDITIONAL_PYTHON_SOURCES}
COMMENT "Generating driver for the target ${GEN_TARGET}" COMMENT "Generating driver for the target ${GEN_TARGET}"
) )
set(GEN_SOURCE ${GEN_TARGET}_main.cc)
dune_module_path(MODULE dune-perftool
RESULT perftool_path
CMAKE_MODULES)
configure_file(${perftool_path}/StandardMain.cmake ${GEN_SOURCE})
endif() endif()
if(GEN_EXCLUDE_FROM_ALL) if(GEN_EXCLUDE_FROM_ALL)
set(GEN_EXCLUDE_FROM_ALL "EXCLUDE_FROM_ALL") set(GEN_EXCLUDE_FROM_ALL "EXCLUDE_FROM_ALL")
...@@ -143,7 +138,7 @@ function(add_generated_executable) ...@@ -143,7 +138,7 @@ function(add_generated_executable)
set(header_deps ${header_deps} ${depdata___${op}}) set(header_deps ${header_deps} ${depdata___${op}})
endforeach() endforeach()
add_executable(${GEN_TARGET} ${GEN_EXCLUDE_FROM_ALL} ${GEN_SOURCE} ${GEN_DRIVER} ${header_deps}) add_executable(${GEN_TARGET} ${GEN_EXCLUDE_FROM_ALL} ${GEN_SOURCE} ${header_deps})
target_include_directories(${GEN_TARGET} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(${GEN_TARGET} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
add_dependencies(generation ${GEN_TARGET}) add_dependencies(generation ${GEN_TARGET})
endfunction() endfunction()
......
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/exceptions.hh>
#include"@GEN_DRIVER@"
int main(int argc, char** argv)
{
try{
//Maybe initialize Mpi
Dune::MPIHelper& helper = Dune::MPIHelper::instance(argc, argv);
if(Dune::MPIHelper::isFake)
std::cout<< "This is a sequential program." << std::endl;
else
std::cout<<"I am rank "<<helper.rank()<<" of "<<helper.size()
<<" processes!"<<std::endl;
if (driver(argc, argv))
return 1;
else
return 0;
}
catch (Dune::Exception &e){
std::cerr << "Dune reported error: " << e << std::endl;
return 1;
}
catch (...){
std::cerr << "Unknown exception thrown!" << std::endl;
return 1;
}
}
...@@ -18,7 +18,7 @@ template_parameter = generator_factory(item_tags=("template_param",), context_ta ...@@ -18,7 +18,7 @@ template_parameter = generator_factory(item_tags=("template_param",), context_ta
class_basename = generator_factory(item_tags=("basename",), context_tags=("classtag",)) class_basename = generator_factory(item_tags=("basename",), context_tags=("classtag",))
@generator_factory(item_tags=("file", "include"), context_tags=("filetag",)) @generator_factory(item_tags=("file", "include"), context_tags=("filetag",), counted=True)
def include_file(include, system=False): def include_file(include, system=False):
return cgen.Include(include, system=system) return cgen.Include(include, system=system)
......
...@@ -232,6 +232,12 @@ def check_parallel_execution(): ...@@ -232,6 +232,12 @@ def check_parallel_execution():
def generate_driver(): def generate_driver():
# Guarantee that config.h is the very first include in the generated file
include_file("config.h", filetag="driver")
# Make sure that the MPI helper is instantiated
name_mpihelper()
# Add check to c++ file if this program should only be used in parallel mode # Add check to c++ file if this program should only be used in parallel mode
if get_option("parallel"): if get_option("parallel"):
check_parallel_execution() check_parallel_execution()
...@@ -273,7 +279,7 @@ def generate_driver(): ...@@ -273,7 +279,7 @@ def generate_driver():
from dune.perftool.generation import retrieve_cache_items from dune.perftool.generation import retrieve_cache_items
from cgen import FunctionDeclaration, FunctionBody, Block, Value, LineComment, Line from cgen import FunctionDeclaration, FunctionBody, Block, Value, LineComment, Line
driver_signature = FunctionDeclaration(Value('bool', 'driver'), [Value('int', 'argc'), Value('char**', 'argv')]) driver_signature = FunctionDeclaration(Value('int', 'main'), [Value('int', 'argc'), Value('char**', 'argv')])
contents = [] contents = []
...@@ -327,7 +333,7 @@ def generate_driver(): ...@@ -327,7 +333,7 @@ def generate_driver():
filename = get_option("driver_file") filename = get_option("driver_file")
from dune.perftool.file import generate_file from dune.perftool.file import generate_file
generate_file(filename, "driver", [driver]) generate_file(filename, "driver", [driver], headerguard=False)
# Reset the caching data structure # Reset the caching data structure
from dune.perftool.generation import delete_cache_items from dune.perftool.generation import delete_cache_items
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment