-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCMakeLists.txt
102 lines (78 loc) · 4.21 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
# (C) Copyright 2011- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation nor
# does it submit to any jurisdiction.
########################################################################################################################
cmake_minimum_required( VERSION 3.12 FATAL_ERROR )
find_package( ecbuild 3.4 REQUIRED HINTS ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../ecbuild)
project( odc LANGUAGES C CXX )
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
########################################################################################################################
### sanity checks
### long and double must be 64 bits exactly
# test by c compilation
ecbuild_check_c_source_return(
"#include <stdio.h>\nint main(){printf(\"%ld\",sizeof(long));return 0;}"
VAR check_long_final
OUTPUT __sizeof_long_final
)
ecbuild_check_c_source_return(
"#include <stdio.h>\nint main(){printf(\"%ld\",sizeof(double));return 0;}"
VAR check_double_final
OUTPUT __sizeof_double_final
)
if( NOT check_long_final OR NOT __sizeof_long_final EQUAL "8" )
message( FATAL_ERROR "operating system ${CMAKE_SYSTEM} (${EC_OS_BITS} bits) and sizeof long [${__sizeof_long_final}] -- long must be 64 bits exactly" )
elseif( NOT check_double_final OR NOT __sizeof_double_final EQUAL "8" )
message( FATAL_ERROR "operating system ${CMAKE_SYSTEM} (${EC_OS_BITS} bits) and sizeof double [${__sizeof_double_final}] -- double must be 64 bits exactly" )
endif()
# test by cxx compilation
ecbuild_check_cxx_source_return(
"#include <iostream>\nint main(){ std::cout << sizeof(long);return 0;}"
VAR cxx_check_long_final
OUTPUT __cxx_sizeof_long_final
)
ecbuild_check_cxx_source_return(
"#include <iostream>\nint main(){ std::cout << sizeof(double);return 0;}"
VAR cxx_check_double_final
OUTPUT __cxx_sizeof_double_final
)
if( NOT cxx_check_long_final OR NOT __cxx_sizeof_long_final EQUAL "8" )
message( FATAL_ERROR "operating system ${CMAKE_SYSTEM} (${EC_OS_BITS} bits) and sizeof long [${__cxx_sizeof_long_final}] -- long must be 64 bits exactly" )
elseif( NOT cxx_check_double_final OR NOT __cxx_sizeof_double_final EQUAL "8" )
message( FATAL_ERROR "operating system ${CMAKE_SYSTEM} (${EC_OS_BITS} bits) and sizeof double [${__cxx_sizeof_double_final}] -- double must be 64 bits exactly" )
endif()
check_type_size( long ODC_SIZEOF_LONG )
check_type_size( double ODC_SIZEOF_DOUBLE )
if( NOT ODC_SIZEOF_LONG EQUAL "8" )
message( FATAL_ERROR "operating system ${CMAKE_SYSTEM} (${EC_OS_BITS} bits) and sizeof long [${ODC_SIZEOF_LONG}] -- long must be 64 bits exactly" )
elseif( NOT ODC_SIZEOF_LONG EQUAL "8" )
message( FATAL_ERROR "operating system ${CMAKE_SYSTEM} (${EC_OS_BITS} bits) and sizeof double [${ODC_SIZEOF_LONG}] -- double must be 64 bits exactly" )
endif()
########################################################################################################################
### dependencies and options
ecbuild_find_package( NAME eckit VERSION 1.4 REQUIRED )
ecbuild_add_option( FEATURE FORTRAN
DESCRIPTION "whether or not to build the Fortran interface"
DEFAULT OFF )
if( HAVE_FORTRAN )
ecbuild_enable_fortran( REQUIRED MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/module )
endif()
########################################################################################################################
# contents
include(cmake/compiler_warnings.cmake) # optionally handle compiler specific warnings
add_subdirectory( src )
add_subdirectory( regressions )
add_subdirectory( tests )
############################################################################################
# finalize
ecbuild_pkgconfig( NAME ${PROJECT_NAME}
DESCRIPTION "ECMWF encoding and decoding of observational data in ODB2 format"
URL "https://software.ecmwf.int/wiki/display/ODC"
LIBRARIES odccore )
ecbuild_install_project( NAME odc )
ecbuild_print_summary()