-
Notifications
You must be signed in to change notification settings - Fork 10
/
CMakeLists.txt
97 lines (77 loc) · 3.46 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
# CMake project file for NETCDF2LITTLER
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)
# Ensures that we do an out of source build
MACRO(MACRO_ENSURE_OUT_OF_SOURCE_BUILD MSG)
STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" insource)
GET_FILENAME_COMPONENT(PARENTDIR ${CMAKE_SOURCE_DIR} PATH)
STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${PARENTDIR}" insourcesubdir)
IF(insource OR insourcesubdir)
IF(EXISTS ${CMAKE_SOURCE_DIR}/CMakeCache.txt OR EXISTS ${CMAKE_SOURCE_DIR}/CMakeFiles)
MESSAGE(FATAL_ERROR "Found results from an in-source build in your source directory.")
ENDIF()
MESSAGE(FATAL_ERROR "${MSG}")
ENDIF(insource OR insourcesubdir)
ENDMACRO(MACRO_ENSURE_OUT_OF_SOURCE_BUILD)
MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
"${CMAKE_PROJECT_NAME} requires an out of source build."
)
PROJECT(NETCDF2LITTLER Fortran)
# Set the NETCDF2LITTLER version
SET(VERSION alpha)
# Add local modules to the module path
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")
SET(LIBRARY_OUTPUT_PATH ${NETCDF2LITTLER_BINARY_DIR}/lib CACHE PATH "Single directory for all libraries." )
SET( EXECUTABLE_OUTPUT_PATH ${NETCDF2LITTLER_BINARY_DIR}/bin CACHE PATH "Single directory for all executables." )
MARK_AS_ADVANCED( EXECUTABLE_OUTPUT_PATH )
MARK_AS_ADVANCED( LIBRARY_OUTPUT_PATH )
# check if fortran compiler supports fortran90
IF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)
MESSAGE(FATAL_ERROR "Fortran compiler does not support F90")
ENDIF(NOT CMAKE_Fortran_COMPILER_SUPPORTS_F90)
# This INCLUDE statement executes code that sets the compile flags for DEBUG,
# RELEASE, and TESTING
INCLUDE(${CMAKE_MODULE_PATH}/SetCompilerFlags.cmake)
# There is an error in CMAKE with this flag for pgf90. Unset it
GET_FILENAME_COMPONENT(FCNAME ${CMAKE_Fortran_COMPILER} NAME)
IF(FCNAME STREQUAL "pgf90")
UNSET(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
ENDIF(FCNAME STREQUAL "pgf90")
# Define the executable in terms of the source files
# Check if NetCDF for Fortran90 is installed
SET (NETCDF_F90 "YES")
INCLUDE(${CMAKE_MODULE_PATH}/FindNetCDF.cmake)
# check if udunits2 is installed
INCLUDE(${CMAKE_MODULE_PATH}/FindUdunits2.cmake)
############################################################
# Define the actual files and folders that make up the build
############################################################
# Define the executable name
SET(NETCDF2LITTLEREXE netcdf2littler)
# Define the library name
SET(FUDUNITS2LIB f_udunits_2)
SET(netcdf2littlerLIB netcdf2littler)
# Define some directories
SET(SRC ${CMAKE_SOURCE_DIR}/src)
SET(FUDUNITS2_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/src/f_udunits_2)
SET(SRCNETCDF2LITTLER ${SRC}/netcdf2littler)
SET(SRCFUDUNITS2 ${SRC}/f_udunits_2)
# The source for the f_udunits_2 library
ADD_SUBDIRECTORY(${SRCFUDUNITS2})
# The source for the netcdf2littler binary
ADD_SUBDIRECTORY(${SRCNETCDF2LITTLER})
# only build tests if -DBUILD_TESTS=True
if (ENABLE_COVERAGE)
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)
SET(NETCDF2LITTLERTESTSEXE netcdf2littler-tests)
SET(SRCNETCDF2LITTLERTESTS ${CMAKE_SOURCE_DIR}/tests)
# enable code coverage
find_package(codecov)
enable_testing()
# The source for the netcdf2littler binary
ADD_SUBDIRECTORY(${SRCNETCDF2LITTLERTESTS})
# symlink the test_data into the build directory
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SOURCE_DIR}/test_data
${CMAKE_BINARY_DIR}/test_data)
# evaluate coverage
coverage_evaluate()
ENDIF()