From 6c2f30dd145560fb69d8ade335a6d128b7fdaa25 Mon Sep 17 00:00:00 2001 From: Thibault Lestang Date: Thu, 24 Feb 2022 20:23:09 +0000 Subject: [PATCH 1/7] Add minimal cmake build. #17 --- CMakeLists.txt | 33 +++++++++++++++++++++++++++++++++ decomp2d/CMakeLists.txt | 11 +++++++++++ src/CMakeLists.txt | 25 +++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 decomp2d/CMakeLists.txt create mode 100644 src/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a00a471 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.12) +cmake_policy(SET CMP0074 NEW) + +project(xcompact3d LANGUAGES Fortran) + +find_package(MPI REQUIRED) +if (MPI_Fortran_COMPILER) + message(STATUS "MPI_Fortran_COMPILER found: ${MPI_Fortran_COMPILER}") +else (MPI_Fortran_COMPILER) + message(SEND_ERROR "This application cannot compile without MPI") +endif(MPI_Fortran_COMPILER) + +# Warning if Include are not found => can be fixed with more recent cmake version +if (MPI_FOUND) + message(STATUS "MPI FOUND: ${MPI_FOUND}") + include_directories(SYSTEM ${MPI_INCLUDE_PATH}) + message(STATUS "MPI INCL ALSO FOUND: ${MPI_INCLUDE_PATH}") +else (MPI_FOUND) + message(STATUS "NO MPI include have been found. The executable won't be targeted with MPI include") + message(STATUS "Code will compile but performaces can be compromised") + message(STATUS "Using a CMake vers > 3.10 should solve the problem") + message(STATUS "Alternatively use ccmake to manually set the include if available") +endif (MPI_FOUND) + + +set(CMAKE_Fortran_FLAGS "-cpp -funroll-loops -floop-optimize -g +-Warray-bounds -fcray-pointer -fbacktrace -ffree-line-length-none") + +# Create a static library for the fft +add_subdirectory(decomp2d) + +# Create the Xcompact3d executable +add_subdirectory(src) diff --git a/decomp2d/CMakeLists.txt b/decomp2d/CMakeLists.txt new file mode 100644 index 0000000..2b8f7a4 --- /dev/null +++ b/decomp2d/CMakeLists.txt @@ -0,0 +1,11 @@ +file(GLOB files_decomp decomp_2d.f90 glassman.f90) +file(GLOB files_fft fft_generic.f90) +set(SRCFILES ${files_decomp} ${files_fft}) + +add_library(decomp2d STATIC ${SRCFILES}) +target_link_libraries(decomp2d PRIVATE MPI::MPI_Fortran) +install(TARGETS decomp2d + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..389c4d9 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,25 @@ +set(SRCFILES + xcompact3d.f90 + case.f90 + derive.f90 + module_param.f90 + mom.f90 + navier.f90 + parameters.f90 + poisson.f90 + schemes.f90 + transeq.f90 + variables.f90 + ) + +add_executable(xcompact3d ${SRCFILES}) + +target_include_directories(xcompact3d PRIVATE ${PROJECT_BINARY_DIR}/decomp2d) +target_link_libraries(xcompact3d PRIVATE decomp2d) +target_link_libraries(xcompact3d PRIVATE MPI::MPI_Fortran) + +install(TARGETS xcompact3d + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} +) From 0ae61121691c7dcf1d9929ced3aa2e838c5bb504 Mon Sep 17 00:00:00 2001 From: Thibault Lestang Date: Thu, 24 Feb 2022 21:03:17 +0000 Subject: [PATCH 2/7] Add GNU compiler options to COMPILE_OPTIONS for each target. #17 A separate list of command line options is defined for both xcompact3d and the decomp2d library. Because they are currently the same, the list could technically be defined one for decomp2d with the PUBLIC attribute. However, it is likely that these 2 lists will diverge in the future. Or at least it's helpful to allow it. --- CMakeLists.txt | 4 ---- decomp2d/CMakeLists.txt | 4 ++++ decomp2d/cmake/gfortran_flags.cmake | 10 ++++++++++ src/CMakeLists.txt | 3 +++ src/cmake/gfortran_flags.cmake | 10 ++++++++++ 5 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 decomp2d/cmake/gfortran_flags.cmake create mode 100644 src/cmake/gfortran_flags.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a00a471..7694eba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,10 +22,6 @@ else (MPI_FOUND) message(STATUS "Alternatively use ccmake to manually set the include if available") endif (MPI_FOUND) - -set(CMAKE_Fortran_FLAGS "-cpp -funroll-loops -floop-optimize -g --Warray-bounds -fcray-pointer -fbacktrace -ffree-line-length-none") - # Create a static library for the fft add_subdirectory(decomp2d) diff --git a/decomp2d/CMakeLists.txt b/decomp2d/CMakeLists.txt index 2b8f7a4..3a364bf 100644 --- a/decomp2d/CMakeLists.txt +++ b/decomp2d/CMakeLists.txt @@ -4,6 +4,10 @@ set(SRCFILES ${files_decomp} ${files_fft}) add_library(decomp2d STATIC ${SRCFILES}) target_link_libraries(decomp2d PRIVATE MPI::MPI_Fortran) + +include(cmake/gfortran_flags.cmake) +target_compile_options(decomp2d PRIVATE ${gfortran_flags}) + install(TARGETS decomp2d RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/decomp2d/cmake/gfortran_flags.cmake b/decomp2d/cmake/gfortran_flags.cmake new file mode 100644 index 0000000..3a63bea --- /dev/null +++ b/decomp2d/cmake/gfortran_flags.cmake @@ -0,0 +1,10 @@ +set(gfortran_flags + -cpp + -funroll-loops + -floop-optimize + -g + -Warray-bounds + -fcray-pointer + -fbacktrace + -ffree-line-length-none + ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 389c4d9..4af9c01 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,6 +18,9 @@ target_include_directories(xcompact3d PRIVATE ${PROJECT_BINARY_DIR}/decomp2d) target_link_libraries(xcompact3d PRIVATE decomp2d) target_link_libraries(xcompact3d PRIVATE MPI::MPI_Fortran) +include(cmake/gfortran_flags.cmake) +target_compile_options(xcompact3d PRIVATE ${gfortran_flags}) + install(TARGETS xcompact3d RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/src/cmake/gfortran_flags.cmake b/src/cmake/gfortran_flags.cmake new file mode 100644 index 0000000..3a63bea --- /dev/null +++ b/src/cmake/gfortran_flags.cmake @@ -0,0 +1,10 @@ +set(gfortran_flags + -cpp + -funroll-loops + -floop-optimize + -g + -Warray-bounds + -fcray-pointer + -fbacktrace + -ffree-line-length-none + ) From a9cecd2a550add7aead3061b4a8a878c61b43bd8 Mon Sep 17 00:00:00 2001 From: Thibault Lestang Date: Thu, 24 Feb 2022 21:08:49 +0000 Subject: [PATCH 3/7] Remove specification of MPI headers. #17 --- CMakeLists.txt | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7694eba..699cd22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,18 +10,6 @@ else (MPI_Fortran_COMPILER) message(SEND_ERROR "This application cannot compile without MPI") endif(MPI_Fortran_COMPILER) -# Warning if Include are not found => can be fixed with more recent cmake version -if (MPI_FOUND) - message(STATUS "MPI FOUND: ${MPI_FOUND}") - include_directories(SYSTEM ${MPI_INCLUDE_PATH}) - message(STATUS "MPI INCL ALSO FOUND: ${MPI_INCLUDE_PATH}") -else (MPI_FOUND) - message(STATUS "NO MPI include have been found. The executable won't be targeted with MPI include") - message(STATUS "Code will compile but performaces can be compromised") - message(STATUS "Using a CMake vers > 3.10 should solve the problem") - message(STATUS "Alternatively use ccmake to manually set the include if available") -endif (MPI_FOUND) - # Create a static library for the fft add_subdirectory(decomp2d) From 35aed1419eb1b1a3501ed94d4293c2ee9a9a6e86 Mon Sep 17 00:00:00 2001 From: Thibault Lestang Date: Mon, 28 Feb 2022 08:45:35 +0000 Subject: [PATCH 4/7] Add fallow-argument-mismatch option for recent gcc compilers. #17 --- decomp2d/CMakeLists.txt | 5 +++++ src/CMakeLists.txt | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/decomp2d/CMakeLists.txt b/decomp2d/CMakeLists.txt index 3a364bf..2f5f4a7 100644 --- a/decomp2d/CMakeLists.txt +++ b/decomp2d/CMakeLists.txt @@ -6,6 +6,11 @@ add_library(decomp2d STATIC ${SRCFILES}) target_link_libraries(decomp2d PRIVATE MPI::MPI_Fortran) include(cmake/gfortran_flags.cmake) + +if(${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 10.3) + list(APPEND ${gfortran_flags} -fallow-argument-mismatch) + # See https://github.com/xcompact3d/x3div/pull/20#discussion_r814948614 +endif() target_compile_options(decomp2d PRIVATE ${gfortran_flags}) install(TARGETS decomp2d diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4af9c01..42ba606 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,10 @@ target_link_libraries(xcompact3d PRIVATE decomp2d) target_link_libraries(xcompact3d PRIVATE MPI::MPI_Fortran) include(cmake/gfortran_flags.cmake) +if(${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 10.3) + list(APPEND ${gfortran_flags} -fallow-argument-mismatch) + # See https://github.com/xcompact3d/x3div/pull/20#discussion_r814948614 +endif() target_compile_options(xcompact3d PRIVATE ${gfortran_flags}) install(TARGETS xcompact3d From b4f697e7babdea3d65adc66cf2904194e55f16b6 Mon Sep 17 00:00:00 2001 From: Thibault Lestang Date: Mon, 28 Feb 2022 08:49:55 +0000 Subject: [PATCH 5/7] [fix] Do not dereference list gfortran_flags when appending to it --- decomp2d/CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/decomp2d/CMakeLists.txt b/decomp2d/CMakeLists.txt index 2f5f4a7..5e536b2 100644 --- a/decomp2d/CMakeLists.txt +++ b/decomp2d/CMakeLists.txt @@ -8,7 +8,7 @@ target_link_libraries(decomp2d PRIVATE MPI::MPI_Fortran) include(cmake/gfortran_flags.cmake) if(${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 10.3) - list(APPEND ${gfortran_flags} -fallow-argument-mismatch) + list(APPEND gfortran_flags -fallow-argument-mismatch) # See https://github.com/xcompact3d/x3div/pull/20#discussion_r814948614 endif() target_compile_options(decomp2d PRIVATE ${gfortran_flags}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 42ba606..0c8d4bc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,7 +20,7 @@ target_link_libraries(xcompact3d PRIVATE MPI::MPI_Fortran) include(cmake/gfortran_flags.cmake) if(${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 10.3) - list(APPEND ${gfortran_flags} -fallow-argument-mismatch) + list(APPEND gfortran_flags -fallow-argument-mismatch) # See https://github.com/xcompact3d/x3div/pull/20#discussion_r814948614 endif() target_compile_options(xcompact3d PRIVATE ${gfortran_flags}) From b6de1d3ba5350d9c843ec8fff37434909dd17cfd Mon Sep 17 00:00:00 2001 From: Thibault Lestang Date: Mon, 28 Feb 2022 13:49:43 +0000 Subject: [PATCH 6/7] Only install xcompact3d exe, from top level CMakeLists. #17 --- CMakeLists.txt | 5 +++++ decomp2d/CMakeLists.txt | 6 ------ src/CMakeLists.txt | 6 ------ 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 699cd22..7820d64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,3 +15,8 @@ add_subdirectory(decomp2d) # Create the Xcompact3d executable add_subdirectory(src) + +include(GNUInstallDirs) +install(TARGETS xcompact3d + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) diff --git a/decomp2d/CMakeLists.txt b/decomp2d/CMakeLists.txt index 5e536b2..f837c6d 100644 --- a/decomp2d/CMakeLists.txt +++ b/decomp2d/CMakeLists.txt @@ -12,9 +12,3 @@ if(${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 10.3) # See https://github.com/xcompact3d/x3div/pull/20#discussion_r814948614 endif() target_compile_options(decomp2d PRIVATE ${gfortran_flags}) - -install(TARGETS decomp2d - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} -) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0c8d4bc..e50dbbf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,9 +24,3 @@ if(${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 10.3) # See https://github.com/xcompact3d/x3div/pull/20#discussion_r814948614 endif() target_compile_options(xcompact3d PRIVATE ${gfortran_flags}) - -install(TARGETS xcompact3d - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} -) From db433bb18e12510b4643de1d2b78048932044dfc Mon Sep 17 00:00:00 2001 From: Thibault Lestang Date: Mon, 28 Feb 2022 13:50:23 +0000 Subject: [PATCH 7/7] Install executable within project binary directory. #17 --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7820d64..3e81dcc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ add_subdirectory(decomp2d) add_subdirectory(src) include(GNUInstallDirs) +set(CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR}) install(TARGETS xcompact3d RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )