-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
206 lines (176 loc) · 6.04 KB
/
CMakeLists.txt
File metadata and controls
206 lines (176 loc) · 6.04 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
cmake_minimum_required (VERSION 2.8.12)
include (CheckFunctionExists)
project (PIOC C)
#==============================================================================
# DEFINE THE TARGET
#==============================================================================
if (CMAKE_BUILD_TYPE)
define_property(
SOURCE
PROPERTY COMPILE_FLAGS
INHERITED
BRIEF_DOCS "brief-doc"
FULL_DOCS "full-doc"
)
string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type)
set_directory_properties(PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS_${_build_type}}")
set(CMAKE_CXX_FLAGS_${_build_type} "")
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set (src topology.c pio_file.c pioc_support.c pio_lists.c
pioc.c pioc_sc.c pio_spmd.c pio_rearrange.c pio_nc4.c pioc_async.c
pio_nc.c pio_put_nc.c pio_get_nc.c pio_getput_int.c pio_msg.c
pio_darray.c pio_darray_int.c pio_get_vard.c pio_put_vard.c pio_error.c parallel_sort.c)
if (NETCDF_INTEGRATION)
set (src ${src} ../ncint/nc_get_vard.c ../ncint/ncintdispatch.c ../ncint/ncint_pio.c ../ncint/nc_put_vard.c)
endif ()
# This needs to be in an IF statement. using GDAL_INTEGRATION. But haven't figured that out yet.
if (USE_GDAL)
set (src ${src} pio_gdal.c)
endif()
add_library (pioc ${src})
# Always use -fPIC
set_property(TARGET pioc PROPERTY POSITION_INDEPENDENT_CODE ON)
set_source_files_properties(
pioc_async.c
PROPERTIES
COMPILE_FLAGS -O0
)
# set up include-directories
include_directories(
"${CMAKE_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}" # to find foo/foo.h
"${PROJECT_BINARY_DIR}") # to find foo/config.h
# Include the clib source directory
target_include_directories (pioc
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# Include the ncint source directory
target_include_directories (pioc
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../ncint)
# System and compiler CPP directives
target_compile_definitions (pioc
PUBLIC ${CMAKE_SYSTEM_DIRECTIVE})
target_compile_definitions (pioc
PUBLIC ${CMAKE_C_COMPILER_DIRECTIVE})
# Compiler-specific compiler options
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
string(APPEND CMAKE_C_FLAGS " -std=gnu99 " )
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "PGI")
string(APPEND CMAKE_C_FLAGS " -c99 ")
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel")
string(APPEND CMAKE_C_FLAGS " -std=c99 -debug minimal ")
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
string(APPEND CMAKE_C_FLAGS " -std=c99 ")
endif()
#==============================================================================
# DEFINE THE INSTALL
#==============================================================================
# Library
install (TARGETS pioc DESTINATION lib)
# Include/Header Files
install (FILES pio.h uthash.h DESTINATION include)
#==============================================================================
# DEFINE THE DEPENDENCIES
#==============================================================================
# MPI test done at top level
if (MPISERIAL_C_FOUND)
target_compile_definitions (pioc
PRIVATE MPI_SERIAL)
target_include_directories (pioc
PUBLIC ${MPISERIAL_C_INCLUDE_DIRS})
target_link_libraries (pioc
PUBLIC ${MPISERIAL_C_LIBRARIES})
set (WITH_PNETCDF FALSE)
endif ()
#===== GPTL =====
if (PIO_ENABLE_TIMING)
if (GPTL_C_FOUND)
message (STATUS "Found GPTL C: ${GPTL_C_LIBRARIES}")
target_include_directories (pioc
PUBLIC ${GPTL_C_INCLUDE_DIRS})
target_link_libraries (pioc
PUBLIC ${GPTL_C_LIBRARIES})
else ()
message (STATUS "Using internal GPTL C library for timing")
target_link_libraries (pioc
PUBLIC gptl)
endif ()
target_compile_definitions (pioc
PUBLIC TIMING)
endif ()
#===== NetCDF-C =====
if (NetCDF_C_FOUND)
target_include_directories (pioc
PUBLIC ${NetCDF_C_INCLUDE_DIRS})
target_link_libraries (pioc
PUBLIC ${NetCDF_C_LIBRARIES})
if (${NetCDF_C_LOGGING_ENABLED})
# netcdf.h needs this to be defined to use netCDF logging.
target_compile_definitions (pioc
PUBLIC LOGGING)
endif()
endif ()
#===== PnetCDF-C =====
if (PnetCDF_C_FOUND)
target_include_directories (pioc
PUBLIC ${PnetCDF_C_INCLUDE_DIRS})
target_link_libraries (pioc
PUBLIC ${PnetCDF_C_LIBRARIES})
# Check library for varn functions
set (CMAKE_REQUIRED_LIBRARIES ${PnetCDF_C_LIBRARY})
endif ()
#===== Add EXTRAs =====
target_include_directories (pioc
PUBLIC ${PIO_C_EXTRA_INCLUDE_DIRS})
target_link_libraries (pioc
PUBLIC ${PIO_C_EXTRA_LIBRARIES})
target_compile_options (pioc
PRIVATE ${PIO_C_EXTRA_COMPILE_OPTIONS})
target_compile_definitions (pioc
PUBLIC ${PIO_C_EXTRA_COMPILE_DEFINITIONS})
if (PIO_C_EXTRA_LINK_FLAGS)
set_target_properties(pioc PROPERTIES
LINK_FLAGS ${PIO_C_EXTRA_LINK_FLAGS})
endif ()
#===== Check for necessities =====
if (NOT PnetCDF_C_FOUND AND NOT NetCDF_C_FOUND)
message (FATAL_ERROR "Must have PnetCDF and/or NetCDF C libraries")
endif ()
#===== MPI =====
if (PIO_USE_MPISERIAL)
if (MPISERIAL_C_FOUND)
target_compile_definitions (pioc
PRIVATE _MPISERIAL)
target_include_directories (pioc
PUBLIC ${MPISERIAL_C_INCLUDE_DIRS})
target_link_libraries (pioc
PUBLIC ${MPISERIAL_C_LIBRARIES})
set (WITH_PNETCDF FALSE)
set (MPI_C_INCLUDE_PATH ${MPISERIAL_C_INCLUDE_DIRS})
endif ()
endif ()
#===== GDAL ===== <M.Long>
if (USE_GDAL)
target_include_directories (pioc
PUBLIC ${GDAL_INCLUDE_DIR})
target_link_libraries (pioc
PUBLIC "-L${GDAL_LIBRARY_PATH} -lgdal")
endif ()
include(CheckTypeSize)
check_type_size("size_t" SIZEOF_SIZE_T)
CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
if (NOT ${SIZEOF_SIZE_T} EQUAL ${SIZEOF_LONG_LONG})
message (FATAL_ERROR "size_t and long long must be the same size!")
endif ()
set(CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}" PARENT_SCOPE)
get_target_property(cppdefs pioc COMPILE_DEFINITIONS)
get_target_property(includes pioc INCLUDE_DIRECTORIES)
foreach(x IN LISTS cppdefs)
string(APPEND CPPFLAGS " -D${x}")
endforeach()
foreach(x IN LISTS includes)
if (x)
string(APPEND CPPFLAGS " -I${x}")
endif()
endforeach()
set(CPPFLAGS ${CPPFLAGS} PARENT_SCOPE)