Skip to content

Commit

Permalink
Merge pull request NCAR#34 from climbfuji/gmtb-ccpp-build-system-fixes
Browse files Browse the repository at this point in the history
gmtb-ccpp scm integration: build system update
  • Loading branch information
climbfuji authored Mar 23, 2018
2 parents 4cddc33 + a607b0e commit 5648b1c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 209 deletions.
30 changes: 5 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

#------------------------------------------------------------------------------
Expand Down
104 changes: 0 additions & 104 deletions cmake/FindOpenMP_Fortran.cmake

This file was deleted.

5 changes: 0 additions & 5 deletions cmake/README_FindOpenMP_Fortran.txt

This file was deleted.

3 changes: 3 additions & 0 deletions schemes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)

62 changes: 9 additions & 53 deletions schemes/check/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Use rpaths on MacOSX
set(CMAKE_MACOSX_RPATH 1)

#------------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8.11)

Expand All @@ -14,7 +17,7 @@ endif(POLICY CMP0048)

#------------------------------------------------------------------------------
set(PACKAGE "check")
set(AUTHORS "Timothy Brown")
set(AUTHORS "Timothy Brown" "Dom Heinzeller")
string(TIMESTAMP YEAR "%Y")

#------------------------------------------------------------------------------
Expand All @@ -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)
Expand Down Expand Up @@ -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})
4 changes: 2 additions & 2 deletions scripts/ccpp_prebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 28 additions & 20 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

#------------------------------------------------------------------------------
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5648b1c

Please sign in to comment.