diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3e81dcc --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,23 @@ +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) + +# Create a static library for the fft +add_subdirectory(decomp2d) + +# Create the Xcompact3d executable +add_subdirectory(src) + +include(GNUInstallDirs) +set(CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR}) +install(TARGETS xcompact3d + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) diff --git a/decomp2d/CMakeLists.txt b/decomp2d/CMakeLists.txt new file mode 100644 index 0000000..f837c6d --- /dev/null +++ b/decomp2d/CMakeLists.txt @@ -0,0 +1,14 @@ +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) + +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}) 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 new file mode 100644 index 0000000..e50dbbf --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,26 @@ +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) + +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}) 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 + )