From b409eff3383dbac0d74f4b9d0c58e56cc790df4c Mon Sep 17 00:00:00 2001 From: Stephan Schulz <stephan.schulz-x2q@rub.de> Date: Mon, 25 Jan 2021 12:38:22 +0100 Subject: [PATCH] update subdirectory example for VTK and Voronoi --- example/CMakeProjectSubdir/ALL_test_src.cpp | 1 + example/CMakeProjectSubdir/CMakeLists.txt | 45 ++++++++++++++----- example/CMakeProjectSubdir/build_all.sh | 10 +++++ .../vtk_bin_contains_vtk_install_dir | 0 4 files changed, 44 insertions(+), 12 deletions(-) create mode 120000 example/CMakeProjectSubdir/ALL_test_src.cpp create mode 100644 example/CMakeProjectSubdir/vtk_bin_contains_vtk_install_dir diff --git a/example/CMakeProjectSubdir/ALL_test_src.cpp b/example/CMakeProjectSubdir/ALL_test_src.cpp new file mode 120000 index 0000000..4ade0dc --- /dev/null +++ b/example/CMakeProjectSubdir/ALL_test_src.cpp @@ -0,0 +1 @@ +../ALL_test.cpp \ No newline at end of file diff --git a/example/CMakeProjectSubdir/CMakeLists.txt b/example/CMakeProjectSubdir/CMakeLists.txt index a7afacc..b13887e 100644 --- a/example/CMakeProjectSubdir/CMakeLists.txt +++ b/example/CMakeProjectSubdir/CMakeLists.txt @@ -1,6 +1,5 @@ -# REMEMBER TO SET CC AND CXX! CMake is too dumb to find compiler in your path! -# mkdcd build -# CC=gcc CXX=g++ cmake -DALL_DIR=`pwd`/../../jall_bin/lib/cmake/ALL ../ +# REMEMBER TO SET CC AND CXX! +# CC=gcc CXX=g++ cmake -S . -B build -DALL_DIR=`pwd`/../../jall_bin/lib/cmake/ALL cmake_minimum_required(VERSION 3.14) project(ExampleProject) @@ -11,20 +10,42 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +# For cleaner code we should also include MPI here, since this project's source +# also needs MPI. Otherwise, we are free to leave it out, since the parts +# required by ALL are automatically included. +find_package(MPI REQUIRED COMPONENTS CXX Fortran) + +# Some variants for testing VTK output and the voronoi method. These are only +# required, so the code used in .this. project has the corresponding features +# enabled and calls the respective functions from the library. This is not +# required for the library itself. Although the library needs to be build with +# the respective features enabled. +add_compile_definitions(TEST_VTK_OUTPUT) +add_compile_definitions(TEST_VORONOI) + set(CM_ALL_FORTRAN ON) #set(CM_ALL_USE_F08 ON) set(CM_ALL_VORONOI ON) -#set(CM_ALL_VTK_OUTPUT ON) +set(CM_ALL_VTK_OUTPUT ON) add_subdirectory(all) -#find_package(MPI REQUIRED COMPONENTS CXX Fortran) +# The target names have Ex prefixed, since these are already taken by the library itself. +add_executable(ExALL_Staggered ALL_Staggered.cpp) +target_link_libraries(ExALL_Staggered PUBLIC ALL) +# This is in this case not .necessary., since it is already inherited from ALL, +# however, for readability and clear intent, we should still link against MPI +# ourselves, since our code also uses MPI directly. +target_link_libraries(ExALL_Staggered PUBLIC ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES}) +target_include_directories(ExALL_Staggered PRIVATE ${MPI_CXX_INCLUDE_PATH}) -add_executable(EALL_Staggered ALL_Staggered.cpp) -target_link_libraries(EALL_Staggered PRIVATE ALL) +add_executable(ExALL_Staggered_f ALL_Staggered_f.F90) +set_property(TARGET ExALL_Staggered_f PROPERTY LINKER_LANGUAGE Fortran) +target_link_libraries(ExALL_Staggered_f PUBLIC ALL_fortran) +target_link_libraries(ExALL_Staggered_f PUBLIC ${MPI_Fortran_LINK_FLAGS} ${MPI_Fortran_LIBRARIES}) +target_include_directories(ExALL_Staggered_f PRIVATE ${MPI_Fortran_INCLUDE_PATH}) -add_executable(EALL_Staggered_f ALL_Staggered_f.F90) -target_link_libraries(EALL_Staggered_f LINK_PRIVATE ALL) -target_link_libraries(EALL_Staggered_f LINK_PRIVATE ALL_fortran) -set_property(TARGET EALL_Staggered_f PROPERTY LINKER_LANGUAGE Fortran) -#todo(s.schulz): link against MPI +add_executable(ExALL_test ALL_test.cpp) +target_link_libraries(ExALL_test PUBLIC ALL) +target_link_libraries(ExALL_test PUBLIC ${MPI_CXX_LINK_FLAGS} ${MPI_CXX_LIBRARIES}) +target_include_directories(ExALL_test PRIVATE ${MPI_CXX_INCLUDE_PATH}) diff --git a/example/CMakeProjectSubdir/build_all.sh b/example/CMakeProjectSubdir/build_all.sh index 960c622..8f8fe62 100755 --- a/example/CMakeProjectSubdir/build_all.sh +++ b/example/CMakeProjectSubdir/build_all.sh @@ -1,3 +1,13 @@ #!/bin/bash +export VTK_DIR="`pwd`/vtk_bin/lib/cmake/vtk-7.1" + +prepare_example () { + cat $1 | sed \ + -e 's/ALL_VTK_OUTPUT/TEST_VTK_OUTPUT/'\ + -e 's/ALL_VORONOI_ACTIVE/TEST_VORONOI/'\ + > $2 +} + +prepare_example ALL_test_src.cpp ALL_test.cpp rm -rf build && CC=gcc CXX=g++ cmake -S . -B build && VERBOSE=1 cmake --build build diff --git a/example/CMakeProjectSubdir/vtk_bin_contains_vtk_install_dir b/example/CMakeProjectSubdir/vtk_bin_contains_vtk_install_dir new file mode 100644 index 0000000..e69de29 -- GitLab