forked from NOAA-EMC/NCEPLIBS-landsfcutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
69 lines (58 loc) · 2.42 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
cmake_minimum_required(VERSION 3.15)
project(landsfcutil VERSION 2.1.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)
if(NOT BUILD_RELEASE )
STRING(COMPARE EQUAL ${CMAKE_BUILD_TYPE} "RELEASE" BUILD_RELEASE)
endif()
STRING(COMPARE EQUAL ${CMAKE_BUILD_TYPE} "PRODUCTION" BUILD_PRODUCTION)
STRING(COMPARE EQUAL ${CMAKE_BUILD_TYPE} "DEBUG" BUILD_DEBUG)
if( (BUILD_RELEASE) OR (BUILD_PRODUCTION) )
if(IntelComp)
set(shared_fortran_flags "-O3" "-fp-model strict" "-ip" "-FR")
set(fortran_d_flags "-r8")
set(fortran_4_flags)
elseif(GNUComp)
set(shared_fortran_flags "-O3" "-ffree-form")
set(fortran_d_flags "-fdefault-real-8")
set(fortran_4_flags)
else()
message("unknown compiler!")
exit()
endif()
endif()
file(GLOB fortran_src ${CMAKE_CURRENT_SOURCE_DIR}/src/*.f ${CMAKE_CURRENT_SOURCE_DIR}/src/*.F)
set(kinds "4" "d")
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})
set_target_properties(${lib_name} PROPERTIES OUTPUT_NAME "${versioned_lib_name}")
target_compile_definitions(${lib_name} PRIVATE "${platform_definition}")
target_compile_options(${lib_name} PRIVATE "${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 bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(DIRECTORY ${module_dir} DESTINATION ${CMAKE_INSTALL_PREFIX})
endforeach()
install(EXPORT ${PROJECT_NAME}-config DESTINATION ${CMAKE_INSTALL_PREFIX})