forked from Goddard-Fortran-Ecosystem/gFTL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
103 lines (85 loc) · 3.33 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
cmake_minimum_required (VERSION 3.12)
if (COMMAND cmake_policy)
cmake_policy (SET CMP0003 NEW)
endif (COMMAND cmake_policy)
project (GFTL
VERSION 1.8.3
LANGUAGES NONE)
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/installed" CACHE PATH "..." FORCE)
message("-- Setting default install prefix to ${CMAKE_INSTALL_PREFIX}.")
message(" Override with -DCMAKE_INSTALL_PREFIX=<path>.")
endif ()
# For BSD systems use GNU m4
find_program( M4 NAMES "gm4" "m4" PATHS "${CMAKE_CURRENT_BINARY_DIR}/m4/bin")
if( NOT M4 )
if( WIN32 )
message( STATUS "Downloading M4 program from SourceForge")
file(DOWNLOAD "https://downloads.sourceforge.net/gnuwin32/m4-1.4.14-1-bin.zip" "${CMAKE_CURRENT_BINARY_DIR}/m4-bin.zip" )
file(DOWNLOAD "http://downloads.sourceforge.net/gnuwin32/m4-1.4.14-1-dep.zip" "${CMAKE_CURRENT_BINARY_DIR}/m4-dep.zip" )
file(ARCHIVE_EXTRACT INPUT "${CMAKE_CURRENT_BINARY_DIR}/m4-bin.zip" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/m4" PATTERNS "bin")
file(ARCHIVE_EXTRACT INPUT "${CMAKE_CURRENT_BINARY_DIR}/m4-dep.zip" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/m4" PATTERNS "bin")
set(M4 "${CMAKE_CURRENT_BINARY_DIR}/m4/bin/m4.exe")
else ()
message( SEND_ERROR "m4 program not found" )
endif()
endif()
# Some preprocessing tests can be run without the
# Fortran testing framework.
enable_testing()
if (NOT TARGET tests)
add_custom_target(tests COMMAND ${CMAKE_CTEST_COMMAND})
endif ()
# "source" code is all include files for gFTL:
add_subdirectory (include)
#add_subdirectory (examples)
# No Fortran compiler is required to build GFTL, but the tests do
# require Fortran. So we check for that before searching for the
# testing framework.
include(CheckLanguage)
check_language (Fortran)
if (CMAKE_Fortran_COMPILER)
enable_language(Fortran)
find_package (PFUNIT 4.1 QUIET)
if (PFUNIT_FOUND)
message("-- Detecting pFUnit: ${PFUNIT_DIR}")
project (GFTL-TEST
VERSION ${GFTL_VERSION}
LANGUAGES Fortran
)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${GFTL_SOURCE_DIR}/cmake")
include (${CMAKE_Fortran_COMPILER_ID} RESULT_VARIABLE found)
include (CheckFortranSource)
include (CheckCompilerCapabilities)
add_subdirectory(tests EXCLUDE_FROM_ALL)
endif ()
endif ()
# The following is needed for external projects using *nix make when
# parent project builds GFTL as a subproject.
set (top_dir "GFTL-${GFTL_VERSION_MAJOR}.${GFTL_VERSION_MINOR}")
set (GFTL_TOP_DIR "${CMAKE_INSTALL_PREFIX}/${top_dir}" CACHE PATH "")
include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/GFTLConfig.cmake.in GFTLConfig.cmake
INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/GFTLConfig.cmake
)
write_basic_package_version_file(GFTLConfig-version.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY SameMajorVersion
)
install (
FILES ${CMAKE_CURRENT_BINARY_DIR}/GFTLConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/GFTLConfig-version.cmake
DESTINATION ${top_dir}/cmake
)
configure_file(cmake/GFTL.mk.in ${CMAKE_CURRENT_BINARY_DIR}/GFTL.mk @ONLY)
install (
FILES ${CMAKE_CURRENT_BINARY_DIR}/GFTL.mk
DESTINATION "${top_dir}/include"
)
install(EXPORT GFTL FILE GFTLTargets.cmake
NAMESPACE GFTL::
DESTINATION "${top_dir}/cmake"
)
export(EXPORT GFTL
FILE "${CMAKE_CURRENT_BINARY_DIR}/GFTLTargets.cmake"
NAMESPACE GFTL::
)