From 11e3a669fe3c0e8d512ebfffb322b6c330378517 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal <grzegorz@amuncode.org> Date: Thu, 30 Jul 2020 12:58:49 -0300 Subject: [PATCH] MAKEFILE: Add initial support for CMake. Just call ccmake <path to AMUN code> and set options. GNU Fortran, Intel Fortran and PGI Fortran are supported. Signed-off-by: Grzegorz Kowal <grzegorz@amuncode.org> --- CMakeLists.txt | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f8eb155 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,69 @@ +cmake_minimum_required(VERSION 3.16) + +project(amun VERSION 1.0) + +enable_language(Fortran) + +set(default_build_type "Release") + +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to '${default_build_type}' as none was specified.") + set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE + STRING "Choose the type of build." FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif() + +if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") + add_compile_options("$<$<CONFIG:RELEASE>:-march=native;-pipe;-pedantic;-ftree-vectorize;-fno-unsafe-math-optimizations;-frounding-math;-fsignaling-nans;-finline-limit=10000;-fdiagnostics-color=always>") + add_compile_options("$<$<CONFIG:DEBUG>:-Og;-pedantic;-W;-Wall>") +endif() + +if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") + add_compile_options("$<$<CONFIG:RELEASE>:-xHost;-fp-model=source;-heap-arrays;-ip;-unroll-aggressive;-simd;-qopt-prefetch;-use-intel-optimized-headers;-finline-limit=1000;-fno-omit-frame-pointer>") + add_compile_options("$<$<CONFIG:DEBUG>:-O>") +endif() + +if(CMAKE_Fortran_COMPILER_ID MATCHES "PGI") + add_compile_options("$<$<CONFIG:RELEASE>:-fastsse;-O4;-Mvect=simd;-Minline=maxsize:1000>") + add_compile_options("$<$<CONFIG:DEBUG>:-O;-Minfo=all>") +endif() + +file(GLOB_RECURSE sources sources/*.F90) +add_executable(amun.x ${sources}) + +option(ENABLE_3D "Enables 3D domains" OFF) +if(ENABLE_3D) + target_compile_definitions(amun.x PRIVATE NDIMS=3) +else() + target_compile_definitions(amun.x PRIVATE NDIMS=2) +endif() + +option(ENABLE_HDF5 "Enable HDF5 support" ON) +if(ENABLE_HDF5) + find_package(HDF5 COMPONENTS Fortran) + if(HDF5_Fortran_FOUND) + include_directories(${HDF5_Fortran_INCLUDE_DIRS}) + target_compile_definitions(amun.x PRIVATE HDF5) + target_link_libraries(amun.x ${HDF5_Fortran_LIBRARIES}) + endif() +endif() + +option(ENABLE_MPI "Enable MPI support" ON) +if(ENABLE_MPI) + find_package(MPI COMPONENTS Fortran) + if(MPI_Fortran_FOUND) + include_directories(${MPI_Fortran_INCLUDE_DIRS}) + target_compile_definitions(amun.x PRIVATE MPI) + target_link_libraries(amun.x ${MPI_Fortran_LIBRARIES}) + endif() +endif() + +option(ENABLE_PROFILE "Enables profiling support" OFF) +if(ENABLE_PROFILE) + target_compile_definitions(amun.x PRIVATE PROFILE) +endif() + +option(ENABLE_SIGNALS "Enables signal handler support" ON) +if(ENABLE_SIGNALS) + target_compile_definitions(amun.x PRIVATE SIGNALS) +endif()