Skip to content

Commit

Permalink
Use cmake STREQUAL instead of MATCHES when exact comparisons are requ…
Browse files Browse the repository at this point in the history
…ired; introduce new/legacy project name CCPP-FV3v0 in CMakeLists.txt to fix build issues
  • Loading branch information
DomHeinzeller committed May 11, 2018
1 parent 9f24fb2 commit a81aad3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
18 changes: 14 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ string(TIMESTAMP YEAR "%Y")
# Set the CMake module path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

#------------------------------------------------------------------------------
# Set MPI preprocessor flag for legacy CCPP-FV3v0
if (PROJECT STREQUAL "CCPP-FV3v0")
add_definitions("-DMPI")
endif (PROJECT STREQUAL "CCPP-FV3v0")

#------------------------------------------------------------------------------
# Set OpenMP flags for C/C++/Fortran
if (OPENMP)
Expand All @@ -48,10 +54,14 @@ if (OPENMP)
set (CMAKE_Fortran_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_Fortran_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
# Set OpenMP preprocessor flag for legacy CCPP-FV3v0
if (PROJECT STREQUAL "CCPP-FV3v0")
add_definitions("-DOPENMP")
endif (PROJECT STREQUAL "CCPP-FV3v0")
message(STATUS "Enable OpenMP support for C/C++/Fortran compiler")
else(OPENMP)
else (OPENMP)
message (STATUS "Disable OpenMP support for C/C++/Fortran compiler")
endif()
endif (OPENMP)

#------------------------------------------------------------------------------
# The Fortran compiler/linker flag inserted by cmake to create shared libraries
Expand Down Expand Up @@ -81,7 +91,7 @@ endif()
# This is due to how it labels subroutines within a modules.
# For example the subroutine b() in the moduel a(), gets named a_b.
# GCC and Intel do NOT do this, it is name simply as b.
if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "PGI")
if ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "PGI")
message(STATUS "WARNING: PGI compiler is not fully ISO_C compliant; working solution involves a hack pgifix.py")
endif()

Expand All @@ -91,7 +101,7 @@ option(BUILD_SHARED_LIBS "Build a shared library" ON)

#------------------------------------------------------------------------------
# Enable code coverage
if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU" AND (CMAKE_BUILD_TYPE STREQUAL "Coverage"))
if ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU" AND (CMAKE_BUILD_TYPE STREQUAL "Coverage"))
include(code_coverage)
list(APPEND LIBS "gcov")
endif()
Expand Down
10 changes: 3 additions & 7 deletions schemes/check/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ endif (NOT PROJECT)
# Use rpaths on MacOSX
set(CMAKE_MACOSX_RPATH 1)

message (INFO "CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
message (INFO "CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}")
#message (FATAL_ERROR "BLA")

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

Expand Down Expand Up @@ -46,21 +42,21 @@ option(BUILD_SHARED_LIBS "Build a shared library" ON)
#------------------------------------------------------------------------------
# Add the CCPP include/module directory and libraries, currently depends on build
# see FV3_current_trunk/ccpp/CMakeLists.txt on how to set CCPP_INCLUDE_DIRS etc.
if (PROJECT MATCHES "CCPP-FV3")
if (PROJECT STREQUAL "CCPP-FV3")
# Add the CCPP include/module directory
set(CCPP_INCLUDE_DIRS "" CACHE FILEPATH "Path to ccpp includes")
set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES ${CCPP_INCLUDE_DIRS})
# Add the CCPP library
set(CCPP_LIB_DIRS "" CACHE FILEPATH "Path to ccpp library")
link_directories(${CCPP_LIB_DIRS})
list(APPEND LIBS "ccpp")
else (PROJECT MATCHES "CCPP-FV3")
else (PROJECT STREQUAL "CCPP-FV3")
# Add the CCPP include/module directory
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}/../../../../src")
# Add the CCPP library
LINK_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}/../../../../src")
list(APPEND LIBS "ccpp")
endif (PROJECT MATCHES "CCPP-FV3")
endif (PROJECT STREQUAL "CCPP-FV3")

#------------------------------------------------------------------------------
# Set the sources
Expand Down
12 changes: 6 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ file(GLOB HEADERS_C
"${CMAKE_CURRENT_SOURCE_DIR}/ccpp*.h"
)

if (PROJECT MATCHES "CCPP-FV3")
if (PROJECT STREQUAL "CCPP-FV3")
target_include_directories(ccpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
else (PROJECT MATCHES "CCPP-FV3")
else (PROJECT STREQUAL "CCPP-FV3")
target_include_directories(ccpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)
endif (PROJECT MATCHES "CCPP-FV3")
endif (PROJECT STREQUAL "CCPP-FV3")

# Define where to install the library
install(TARGETS ccpp
Expand All @@ -144,12 +144,12 @@ install(EXPORT ccpp-targets
DESTINATION lib/cmake
)

if (PROJECT MATCHES "CCPP-FV3")
if (PROJECT STREQUAL "CCPP-FV3")
# Define where to install the C headers and Fortran modules
install(FILES ${HEADERS_C} DESTINATION include)
install(FILES ${MODULES_F90} DESTINATION include)
else (PROJECT MATCHES "CCPP-FV3")
else (PROJECT STREQUAL "CCPP-FV3")
# Define where to install the C headers and Fortran modules
install(FILES ${HEADERS_C} DESTINATION include/${PROJECT_NAME})
install(FILES ${MODULES_F90} DESTINATION include/${PROJECT_NAME})
endif (PROJECT MATCHES "CCPP-FV3")
endif (PROJECT STREQUAL "CCPP-FV3")

0 comments on commit a81aad3

Please sign in to comment.