Skip to content

Commit

Permalink
Merge pull request #8 from mark-a-potts/gsi-update
Browse files Browse the repository at this point in the history
Gsi update
  • Loading branch information
mark-a-potts authored Jul 13, 2020
2 parents 369b197 + 55038a7 commit 252c90c
Show file tree
Hide file tree
Showing 9 changed files with 517 additions and 158 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build/
install/

*.[ao]
*.mod
*.so
.DS_Store

*.swp
135 changes: 16 additions & 119 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,128 +1,25 @@
cmake_minimum_required(VERSION 3.15)
project(bufr VERSION 11.3.0)
set(${PROJECT_NAME}_VERSION ${PROJECT_VERSION} CACHE INTERNAL "${PROJECT_NAME} version number")
enable_language (Fortran)

if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE RELEASE CACHE STRING
"Choose the type of build, options are: PRODUCTION Debug Release."
FORCE)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
set(IntelComp true )
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU*" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang*")
set(GNUComp true )
elseif(CMAKE_CXX_COMPILER_ID MATCHES "pgc*")
set(PGIComp true )
endif()

STRING(COMPARE EQUAL ${CMAKE_BUILD_TYPE} "RelWithDebInfo" BUILD_RELEASE)
STRING(COMPARE EQUAL ${CMAKE_BUILD_TYPE} "RELEASE" BUILD_RELEASE)
STRING(COMPARE EQUAL ${CMAKE_BUILD_TYPE} "PRODUCTION" BUILD_PRODUCTION)
STRING(COMPARE EQUAL ${CMAKE_BUILD_TYPE} "DEBUG" BUILD_DEBUG)

option(GSIBUILD "Build only libs for GSI" ON)

set(definitions "UNDERSCORE" "NFILES=32" "MAXCD=250" "MAXNC=600" "MXNAF=3")

if( (BUILD_RELEASE) OR (BUILD_PRODUCTION) )
if(IntelComp)
#shared with C and Fortran
set(shared_flags "-g" "-traceback" "-O3" "-axCORE-AVX2")

set(c_DA_allocation_def "DYNAMIC_ALLOCATION")
set(c_4_DA_flags)
set(c_8_DA_definitions "F77_INTSIZE_8")
set(c_d_DA_flags)

set(fortran_4_DA_flags)
set(fortran_8_DA_flags "-r8" "-i8")
set(fortran_d_DA_flags "-r8")

set(c_nonDA_allocation_def "STATIC_ALLOCATION")
set(c_4_flags)
set(c_8_flags)
set(c_8_definitions "F77_INTSIZE_8")
set(c_d_flags)
set(c_SS_flags "-mcmodel=medium" "-shared")
file(STRINGS "VERSION" pVersion)

set(fortran_4_flags)
set(fortran_8_flags "-r8" "-i8")
set(fortran_d_flags "-r8")
set(fortran_SS_flags "-mcmodel=medium" "-shared")
project(
bufr
VERSION ${pVersion}
LANGUAGES C Fortran)

elseif(GNUComp)
set(allocation_def "DYNAMIC_ALLOCATION")
set(shared_flags "-O3" "-ggdb" "-Wall")

set(c_d_flags)
set(c_4_flags)
set(c_8_flags)

set(shared_fortran_flags "-funroll-loops")
set(fortran_4_flags)
set(fortran_d_flags "-fdefault-real-8")
set(fortran_8_flags "-fdefault-integer-8" "-fdefault-real-8")
else()
message("unknown compiler!")
exit()
endif()
if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo|MinSizeRel)$")
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_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()


file(GLOB fortran_src ${CMAKE_CURRENT_SOURCE_DIR}/src/*.f ${CMAKE_CURRENT_SOURCE_DIR}/src/*.F)
file(GLOB c_src ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)

if(GSIBUILD)
set(kinds "4" "d" "8")
else()
set(kinds "4" "d" "8" "SS" "4_DA" "8_DA" "d_DA")
if(NOT CMAKE_C_COMPILER_ID MATCHES "^(Intel|GNU|Clang|AppleClang)$")
message(WARNING "Compiler not officially supported: ${CMAKE_C_COMPILER_ID}")
endif()

foreach(kind ${kinds})
set(lib_name ${PROJECT_NAME}_${kind})
set(versioned_lib_name ${PROJECT_NAME}_v${PROJECT_VERSION}_${kind})
add_library(${lib_name} STATIC ${fortran_src} ${c_src})
set_target_properties(${lib_name} PROPERTIES OUTPUT_NAME "${versioned_lib_name}")

# different compiler definitions for Intel in DA vs non-DA
# -DDYNAMIC_ALLOCATION when compiled with DA and -DSTATIC_ALLOCATION
# check current kind and if it has 'DA' in it then set compiler def

if(IntelComp)
string(FIND ${kind} "DA" isDA)
if(isDA GREATER_EQUAL 0)
set(allocation_def ${c_DA_allocation_def})
else()
set(allocation_def ${c_nonDA_allocation_def})
endif()
endif()

target_compile_definitions(${lib_name} PRIVATE "${allocation_def}")

set_source_files_properties(${c_src} PROPERTIES
COMPILE_OPTIONS "${shared_flags};${c_${kind}_flags}")
set_source_files_properties(${c_src} PROPERTIES
COMPILE_DEFINITIONS "${c_definitions};${c_${kind}_definitions}")

set_source_files_properties(${fortran_src} PROPERTIES
COMPILE_OPTIONS "${shared_flags};${shared_fortran_flags};${fortran_${kind}_flags}")

set(module_dir "${CMAKE_CURRENT_BINARY_DIR}/include_${kind}")
set_target_properties(${lib_name} PROPERTIES Fortran_MODULE_DIRECTORY "${module_dir}")

target_include_directories(${lib_name} PUBLIC
$<BUILD_INTERFACE:${module_dir}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include_${kind}}>)

install(TARGETS ${lib_name}
EXPORT ${PROJECT_NAME}-config
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(DIRECTORY ${module_dir} DESTINATION ${CMAKE_INSTALL_PREFIX})
endforeach()

install(EXPORT ${PROJECT_NAME}-config DESTINATION ${CMAKE_INSTALL_PREFIX})
include(GNUInstallDirs)

add_subdirectory(src)
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11.3.1
19 changes: 19 additions & 0 deletions cmake/PackageConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@PACKAGE_INIT@

# * @PROJECT_NAME@::@PROJECT_NAME@_4_DA - real32 library target with dynamic allocation
# * @PROJECT_NAME@::@PROJECT_NAME@_8_DA - real64 library target with dynamic allocation
# * @PROJECT_NAME@::@PROJECT_NAME@_d_DA - mixed library target with dynamic allocation
# * @PROJECT_NAME@::@PROJECT_NAME@_4 - real32 library target
# * @PROJECT_NAME@::@PROJECT_NAME@_8 - real64 library target
# * @PROJECT_NAME@::@PROJECT_NAME@_d - mixed library target

# Include targets file. This will create IMPORTED target @PROJECT_NAME@
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

# Get the build type from real32 library target with dyanmic allocation
get_target_property(@PROJECT_NAME@_BUILD_TYPES @PROJECT_NAME@::@PROJECT_NAME@_4_DA IMPORTED_CONFIGURATIONS)

check_required_components("@PROJECT_NAME@")

get_target_property(location @PROJECT_NAME@::@PROJECT_NAME@_4_DA LOCATION)
message(STATUS "Found @PROJECT_NAME@: ${location} (found version \"@PROJECT_VERSION@\")")
13 changes: 0 additions & 13 deletions double/CMakeLists.txt

This file was deleted.

13 changes: 0 additions & 13 deletions doubleDA/CMakeLists.txt

This file was deleted.

134 changes: 134 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
if(CMAKE_C_COMPILER_ID MATCHES "^(Intel)$")

set(c_8_defs "F77_INTSIZE_8")
set(c_8_DA_defs ${c_8_defs})

set(CMAKE_Fortran_FLAGS "-g -traceback")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0")
set(CMAKE_Fortran_FLAGS_RELEASE "-O3")

set(fortran_8_flags "-r8 -i8")
set(fortran_d_flags "-r8")
set(fortran_8_DA_flags ${fortran_8_flags})
set(fortran_d_DA_flags ${fortran_d_flags})

elseif(CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$")

set(CMAKE_C_FLAGS_DEBUG "-ggdb -Wall -O0")

set(CMAKE_Fortran_FLAGS "-g -fbacktrace")
set(CMAKE_Fortran_FLAGS_DEBUG "-ggdb -Wall -O0")
set(CMAKE_Fortran_FLAGS_RELEASE "-O3")

set(fortran_8_flags "-fdefault-real-8 -fdefault-integer-8")
set(fortran_d_flags "-fdefault-real-8")

endif()

# Extract BUFRLIB parameters
file(READ bufrlib.prm _bufrlib_prm_str)
foreach(_var IN ITEMS MAXNC MXNAF)
if(_bufrlib_prm_str MATCHES "${_var} = ([0-9]+)")
list(APPEND c_defs ${_var}=${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Unable to parse variable ${_var} value from file: src/bufrlib.prm")
endif()
endforeach()

list(APPEND underscore_def UNDERSCORE)

include(TestBigEndian)
test_big_endian(IS_BIG_ENDIAN)
if(IS_BIG_ENDIAN)
list(APPEND endian_def BIG_ENDIAN)
else()
list(APPEND endian_def LITTLE_ENDIAN)
endif()

include("list_of_files.cmake")

# Both GNU and Intel support DYNAMIC_ALLOCATION
list(APPEND kinds "4_DA" "8_DA" "d_DA")

# Only Intel supports STATIC_ALLOCATION
if(CMAKE_C_COMPILER_ID MATCHES "^(Intel)$")
list(APPEND kinds "4" "8" "d")
endif()

foreach(kind ${kinds})
set(lib_name ${PROJECT_NAME}_${kind})
set(module_dir "${CMAKE_CURRENT_BINARY_DIR}/include_${kind}")

# determine ALLOCATION based on kind
if(${kind} MATCHES "^([4|8|d]_DA)$")
set(allocation_def "DYNAMIC_ALLOCATION")
else()
set(allocation_def "STATIC_ALLOCATION")
endif()

add_library(${lib_name}_f STATIC OBJECT ${fortran_src})
set_target_properties(${lib_name}_f PROPERTIES COMPILE_FLAGS
"${fortran_${kind}_flags}")
target_compile_definitions(${lib_name}_f PUBLIC "${allocation_def}")
target_compile_definitions(${lib_name}_f PUBLIC "${underscore_def}")
target_compile_definitions(${lib_name}_f PRIVATE "${endian_def}")

add_library(${lib_name}_c STATIC OBJECT ${c_src})
set_target_properties(${lib_name}_c PROPERTIES COMPILE_FLAGS
"${c_${kind}_flags}")
target_compile_definitions(${lib_name}_c PUBLIC "${allocation_def}")
target_compile_definitions(${lib_name}_c PUBLIC "${underscore_def}")
target_compile_definitions(${lib_name}_c PRIVATE "${endian_def}")
target_compile_definitions(${lib_name}_c PRIVATE "${c_defs}")
target_compile_definitions(${lib_name}_c PRIVATE "${c_${kind}_defs}")

set_target_properties(${lib_name}_f PROPERTIES Fortran_MODULE_DIRECTORY "${module_dir}")

add_library(${lib_name} STATIC $<TARGET_OBJECTS:${lib_name}_f>
$<TARGET_OBJECTS:${lib_name}_c>)
add_library(${PROJECT_NAME}::${lib_name} ALIAS ${lib_name})

target_include_directories(${lib_name} INTERFACE
$<BUILD_INTERFACE:${module_dir}>
$<INSTALL_INTERFACE:include_${kind}>)

target_compile_definitions(${lib_name} PUBLIC "${underscore_def}")
target_compile_definitions(${lib_name} PUBLIC "${allocation_def}")

list(APPEND LIB_TARGETS ${lib_name})
install(DIRECTORY ${module_dir} DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES ${c_hdr} DESTINATION ${CMAKE_INSTALL_PREFIX}/include_${kind})
endforeach()

install(
TARGETS ${LIB_TARGETS}
EXPORT ${PROJECT_NAME}Exports
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

### Package config
include(CMakePackageConfigHelpers)
set(CONFIG_INSTALL_DESTINATION lib/cmake/${PROJECT_NAME})

export(EXPORT ${PROJECT_NAME}Exports
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME}-targets.cmake)

configure_package_config_file(
${CMAKE_SOURCE_DIR}/cmake/PackageConfig.cmake.in ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${CONFIG_INSTALL_DESTINATION})
install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config.cmake
DESTINATION ${CONFIG_INSTALL_DESTINATION})

write_basic_package_version_file(
${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)
install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${CONFIG_INSTALL_DESTINATION})

install(EXPORT ${PROJECT_NAME}Exports
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME}-targets.cmake
DESTINATION ${CONFIG_INSTALL_DESTINATION})
Loading

0 comments on commit 252c90c

Please sign in to comment.