diff --git a/CMakeLists.txt b/CMakeLists.txt index 8dfb3bb5..c3c9606c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,39 +40,19 @@ endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") #------------------------------------------------------------------------------ -# Find OpenMP for C/C++ +# Find OpenMP for C/C++/Fortran if (OPENMP) find_package(OpenMP) if(OPENMP_FOUND) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") - message(STATUS "Enabled OpenMP support for C/C++ compiler") - else(OPENMP_FOUND) - message (FATAL_ERROR "C/C++ compiler does not support OpenMP") - endif() -else(OPENMP) - message (STATUS "Disable OpenMP support for C/C++ compiler") -endif() - -#------------------------------------------------------------------------------ -# Find OpenMP for Fortran -if (OPENMP) - FIND_PACKAGE(OpenMP_Fortran) - if(OpenMP_FLAG_DETECTED) set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}") - message(STATUS "Enabled OpenMP support for Fortran compiler") - else(OpenMP_FLAG_DETECTED) - if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - # On MacOSX, OpenMP_FLAG_DETECTED is not set correctly, even though - # the flags and libraries are set correctly. Force cmake to continue. - message (INFO "Detecting OpenMP on MacOSX not working properly - force CMAKE_Fortran_FLAGS='${CMAKE_Fortran_FLAGS}'") - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}") - else (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - message (FATAL_ERROR "Fortran compiler does not support OpenMP") - endif() + message(STATUS "Enabled OpenMP support for C/C++/Fortran compiler") + else(OPENMP_FOUND) + message (FATAL_ERROR "C/C++/Fortran compiler does not support OpenMP") endif() else(OPENMP) - message (STATUS "Disable OpenMP support for Fortran compiler") + message (STATUS "Disable OpenMP support for C/C++/Fortran compiler") endif() #------------------------------------------------------------------------------ diff --git a/cmake/FindOpenMP_Fortran.cmake b/cmake/FindOpenMP_Fortran.cmake deleted file mode 100644 index 9be54f89..00000000 --- a/cmake/FindOpenMP_Fortran.cmake +++ /dev/null @@ -1,104 +0,0 @@ -# - Finds OpenMP support -# This module can be used to detect OpenMP support in a compiler. -# If the compiler supports OpenMP, the flags required to compile with -# openmp support are set. -# -# This module was modified from the standard FindOpenMP module to find Fortran -# flags. -# -# The following variables are set: -# OpenMP_Fortran_FLAGS - flags to add to the Fortran compiler for OpenMP -# support. In general, you must use these at both -# compile- and link-time. -# OMP_NUM_PROCS - the max number of processors available to OpenMP - -#============================================================================= -# Copyright 2009 Kitware, Inc. -# Copyright 2008-2009 André Rigland Brodtkorb -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -INCLUDE (${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) - -SET (OpenMP_Fortran_FLAG_CANDIDATES - #Microsoft Visual Studio - "/openmp" - #Intel windows - "/Qopenmp" - #Intel - "-qopenmp" - #Gnu - "-fopenmp" - #Empty, if compiler automatically accepts openmp - " " - #Sun - "-xopenmp" - #HP - "+Oopenmp" - #IBM XL C/c++ - "-qsmp" - #Portland Group - "-mp" -) - -IF (DEFINED OpenMP_Fortran_FLAGS) - SET (OpenMP_Fortran_FLAG_CANDIDATES) -ENDIF (DEFINED OpenMP_Fortran_FLAGS) - -# check fortran compiler. also determine number of processors -FOREACH (FLAG ${OpenMP_Fortran_FLAG_CANDIDATES}) - SET (SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") - SET (CMAKE_REQUIRED_FLAGS "${FLAG}") - UNSET (OpenMP_FLAG_DETECTED CACHE) - MESSAGE (STATUS "Try OpenMP Fortran flag = [${FLAG}]") - FILE (WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranOpenMP.f90" -" -program TestOpenMP - use omp_lib - write(*,'(I2)',ADVANCE='NO') omp_get_num_procs() -end program TestOpenMP -") - SET (MACRO_CHECK_FUNCTION_DEFINITIONS - "-DOpenMP_FLAG_DETECTED ${CMAKE_REQUIRED_FLAGS}") - TRY_RUN (OpenMP_RUN_FAILED OpenMP_FLAG_DETECTED ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranOpenMP.f90 - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} - COMPILE_OUTPUT_VARIABLE OUTPUT - RUN_OUTPUT_VARIABLE OMP_NUM_PROCS_INTERNAL) - IF (OpenMP_FLAG_DETECTED) - FILE (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Determining if the Fortran compiler supports OpenMP passed with " - "the following output:\n${OUTPUT}\n\n") - SET (OpenMP_FLAG_DETECTED 1) - IF (OpenMP_RUN_FAILED) - MESSAGE (FATAL_ERROR "OpenMP found, but test code did not run") - ENDIF (OpenMP_RUN_FAILED) - SET (OMP_NUM_PROCS ${OMP_NUM_PROCS_INTERNAL} CACHE - STRING "Number of processors OpenMP may use" FORCE) - SET (OpenMP_Fortran_FLAGS_INTERNAL "${FLAG}") - BREAK () - ELSE () - FILE (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining if the Fortran compiler supports OpenMP failed with " - "the following output:\n${OUTPUT}\n\n") - SET (OpenMP_FLAG_DETECTED 0) - ENDIF (OpenMP_FLAG_DETECTED) -ENDFOREACH (FLAG ${OpenMP_Fortran_FLAG_CANDIDATES}) - -SET (OpenMP_Fortran_FLAGS "${OpenMP_Fortran_FLAGS_INTERNAL}" - CACHE STRING "Fortran compiler flags for OpenMP parallization") - -# handle the standard arguments for FIND_PACKAGE -FIND_PACKAGE_HANDLE_STANDARD_ARGS (OpenMP_Fortran DEFAULT_MSG - OpenMP_Fortran_FLAGS) - -MARK_AS_ADVANCED(OpenMP_Fortran_FLAGS) diff --git a/cmake/README_FindOpenMP_Fortran.txt b/cmake/README_FindOpenMP_Fortran.txt deleted file mode 100644 index 0bb5967d..00000000 --- a/cmake/README_FindOpenMP_Fortran.txt +++ /dev/null @@ -1,5 +0,0 @@ -Credits: Seth M. Morton - - http://sethmmorton.github.io/how%20to/2013/04/28/using-cmake-to-find-openmp-flags-for-fortran-compilers - - https://github.com/SethMMorton/cmake_fortran_template/blob/master/cmake/Modules/FindOpenMP_Fortran.cmake \ No newline at end of file diff --git a/schemes/CMakeLists.txt b/schemes/CMakeLists.txt index d6b1e290..41b39d94 100644 --- a/schemes/CMakeLists.txt +++ b/schemes/CMakeLists.txt @@ -17,5 +17,8 @@ ExternalProject_Add( CMAKE_ARGS -DCCPP_INCLUDE_DIRS=${CCPP_INCLUDE_DIRS} -DCCPP_LIB_DIRS=${CCPP_LIB_DIRS} -DCCPP_MKCAP=${CMAKE_CURRENT_SOURCE_DIR}/mkcap.py + -DCMAKE_Fortran_FLAGS=${CMAKE_Fortran_FLAGS} + -DCMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS=${CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ) diff --git a/schemes/check/CMakeLists.txt b/schemes/check/CMakeLists.txt index 72474416..4667e58b 100644 --- a/schemes/check/CMakeLists.txt +++ b/schemes/check/CMakeLists.txt @@ -1,3 +1,6 @@ +# Use rpaths on MacOSX +set(CMAKE_MACOSX_RPATH 1) + #------------------------------------------------------------------------------ cmake_minimum_required(VERSION 2.8.11) @@ -14,7 +17,7 @@ endif(POLICY CMP0048) #------------------------------------------------------------------------------ set(PACKAGE "check") -set(AUTHORS "Timothy Brown") +set(AUTHORS "Timothy Brown" "Dom Heinzeller") string(TIMESTAMP YEAR "%Y") #------------------------------------------------------------------------------ @@ -26,55 +29,6 @@ enable_language(Fortran) # Set the CMake module path list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake") -#------------------------------------------------------------------------------ -# Find OpenMP for C/C++ -find_package(OpenMP) -if(OPENMP_FOUND) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") - message(STATUS "Enabled OpenMP support for C/C++ compiler") -else(OPENMP_FOUND) - message (STATUS "C/C++ compiler does not support OpenMP") -endif() - -#------------------------------------------------------------------------------ -# Find OpenMP for Fortran -FIND_PACKAGE(OpenMP_Fortran) -if(OpenMP_FLAG_DETECTED) - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}") - message(STATUS "Enabled OpenMP support for Fortran compiler") -else(OpenMP_FLAG_DETECTED) - message (STATUS "Fortran compiler does not support OpenMP") -endif() - -message (STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") -message (STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") -message (STATUS "CMAKE_Fortran_FLAGS: ${CMAKE_Fortran_FLAGS}") - -#------------------------------------------------------------------------------ -# The Fortran compiler/linker flag inserted by cmake to create shared libraries -# with the Intel compiler is deprecated (-i_dynamic), correct here. -# CMAKE_Fortran_COMPILER_ID = {"Intel", "PGI", "GNU", "Clang", "MSVC", ...} -if ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Intel") - string(REPLACE "-i_dynamic" "-shared-intel" - CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS - "${CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS}") - string(REPLACE "-i_dynamic" "-shared-intel" - CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS - "${CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS}") -endif() - -#------------------------------------------------------------------------------ -# Set a default build type if none was specified -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to 'Debug' as none was specified.") - set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE) - - # Set the possible values of build type for cmake-gui - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" - "MinSizeRel" "RelWithDebInfo") -endif() - #------------------------------------------------------------------------------ # By default we want a shared library option(BUILD_SHARED_LIBS "Build a shared library" ON) @@ -107,10 +61,12 @@ add_custom_command( ) list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/check_test_cap.f90) +# Guard for undefined/empty CMAKE_Fortran_FLAGS +set(CMAKE_Fortran_FLAGS " ${CMAKE_Fortran_FLAGS}") + add_library(check ${SOURCES}) target_link_libraries(check LINK_PUBLIC ${LIBS}) set_target_properties(check PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} - COMPILE_FLAGS ${OpenMP_Fortran_FLAGS} - LINK_FLAGS ${OpenMP_Fortran_FLAGS}) - + COMPILE_FLAGS ${CMAKE_Fortran_FLAGS} + LINK_FLAGS ${CMAKE_Fortran_FLAGS}) diff --git a/scripts/ccpp_prebuild.py b/scripts/ccpp_prebuild.py index c39775ad..2654b965 100755 --- a/scripts/ccpp_prebuild.py +++ b/scripts/ccpp_prebuild.py @@ -28,8 +28,8 @@ ############################################################################### # Define host model (only parameter to set in this file) -#HOST_MODEL = "SCM" -HOST_MODEL = "FV3" +HOST_MODEL = "SCM" +#HOST_MODEL = "FV3" # No further modifications should be required below, # all other parameters are set in ccpp_prebuild_config_HOST_MODEL.py diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 45abea84..74d2e491 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,24 +34,19 @@ endif(LIBXML2_FOUND) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") #------------------------------------------------------------------------------ -# Find OpenMP for C/C++ -find_package(OpenMP) -if(OPENMP_FOUND) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") - message(STATUS "Enabled OpenMP support for C/C++ compiler") -else(OPENMP_FOUND) - message (STATUS "C/C++ compiler does not support OpenMP") -endif() - -#------------------------------------------------------------------------------ -# Find OpenMP for Fortran -FIND_PACKAGE(OpenMP_Fortran) -if(OpenMP_FLAG_DETECTED) - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}") - message(STATUS "Enabled OpenMP support for Fortran compiler") -else(OpenMP_FLAG_DETECTED) - message (STATUS "Fortran compiler does not support OpenMP") +# Find OpenMP for C/C++/Fortran +if (OPENMP) + find_package(OpenMP) + if(OPENMP_FOUND) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}") + message(STATUS "Enabled OpenMP support for C/C++/Fortran compiler") + else(OPENMP_FOUND) + message (FATAL_ERROR "C/C++/Fortran compiler does not support OpenMP") + endif() +else(OPENMP) + message (STATUS "Disable OpenMP support for C/C++/Fortran compiler") endif() #------------------------------------------------------------------------------ @@ -67,6 +62,19 @@ if ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Intel") "${CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS}") endif() +#------------------------------------------------------------------------------ +# Set a default build type if none was specified +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + #message(STATUS "Setting build type to 'Debug' as none was specified.") + #set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE) + message(STATUS "Setting build type to 'Release' as none was specified.") + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) + + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" + "MinSizeRel" "RelWithDebInfo") +endif() + #------------------------------------------------------------------------------ # Pass debug/release flag to Fortran files for preprocessor if(CMAKE_BUILD_TYPE STREQUAL "Debug") @@ -100,8 +108,8 @@ add_library(ccpp ${SOURCES}) target_link_libraries(ccpp LINK_PUBLIC ${LIBS} ${CMAKE_DL_LIBS}) set_target_properties(ccpp PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} - COMPILE_FLAGS ${OpenMP_Fortran_FLAGS} - LINK_FLAGS ${OpenMP_Fortran_FLAGS}) + COMPILE_FLAGS ${CMAKE_Fortran_FLAGS} + LINK_FLAGS ${CMAKE_Fortran_FLAGS}) #------------------------------------------------------------------------------ # Installation