Skip to content

Commit 42f4397

Browse files
authored
Further work to upgrade the custom supplment for GMT 6.1 (#4)
* Update the root CMakeLists.txt * Add CMake codes for building the custom library * Copy FindGMT and FindNETCDF from the GMT repository * Add gmt_gule.c, generated by gmt --new-glue * GMT_Get_Value was renamed to GMT_Get_Values and has one more parameter * custom_version.h was removed * GMT_STR16 was renamed to GMT_VF_LEN * GMT_GRD_HEADER nx and ny was renamed to n_columns and n_rows * Fix GMT_Get_Values in gmtparser.c
1 parent 4c0d42a commit 42f4397

9 files changed

Lines changed: 371 additions & 40 deletions

File tree

CMakeLists.txt

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#
2-
# $Id: CMakeLists.txt 11803 2013-06-24 23:06:22Z pwessel $
3-
#
4-
# Copyright (c) 1991-2017 by P. Wessel, W. H. F. Smith, R. Scharroo, J. Luis, and F. Wobbe
2+
# Copyright (c) 1991-2020 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
53
# See LICENSE.TXT file for copying and redistribution conditions.
64
#
75
# This program is free software; you can redistribute it and/or modify
@@ -13,11 +11,9 @@
1311
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1412
# GNU Lesser General Public License for more details.
1513
#
16-
# Contact info: gmt.soest.hawaii.edu
14+
# Contact info: www.generic-mapping-tools.org
1715
#-------------------------------------------------------------------------------
1816
#
19-
# To modify the cmake process: Edit your cmake/ConfigUser.cmake file
20-
#
2117
# To build out-of-source do (for example):
2218
#
2319
# mkdir build
@@ -26,14 +22,10 @@
2622
#
2723
# CMAKE_BUILD_TYPE can be: empty, Debug, Release, RelWithDebInfo or MinSizeRel
2824
#
29-
# cmake creates a new file cmake/ConfigUser.cmake if it does not already
30-
# exist. You can configure additional options there.
31-
#
3225

33-
## Section 0: Define project name. Change this to what your plugin should be named.
26+
## Define project name. Change this to what your plugin should be named.
3427
project (custom)
3528

36-
#------------------------------------------------------------------------
3729
# Make sure the user doesn't play dirty with symlinks
3830
get_filename_component (srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
3931
get_filename_component (bindir "${CMAKE_BINARY_DIR}" REALPATH)
@@ -54,16 +46,14 @@ cmake_minimum_required (VERSION 2.8.5)
5446
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/"
5547
CACHE INTERNAL "Location of our custom CMake modules." FORCE)
5648

57-
# Include configuration options (default options and options overridden by user).
58-
include (ConfigCMake)
59-
60-
# Find UNIX commands
61-
include (FindUnixCommands)
62-
6349
# Add subdirectories
6450
add_subdirectory (src)
65-
get_property(GMT_CUSTOM_LIB_PATH TARGET customlib PROPERTY LOCATION)
66-
GET_FILENAME_COMPONENT (GMT_CUSTOM_LIB_NAME ${GMT_CUSTOM_LIB_PATH} NAME)
51+
52+
# Get name of the custom supplemental library
53+
get_directory_property (_suppl_lib_name DIRECTORY "src" DEFINITION "SUPPL_LIB_NAME")
54+
get_target_property (_name ${_suppl_lib_name} OUTPUT_NAME)
55+
get_target_property (_prefix ${_suppl_lib_name} PREFIX)
56+
set (GMT_CUSTOM_LIB_NAME ${_prefix}${_name}${CMAKE_SHARED_MODULE_SUFFIX})
6757

6858
# Configuration done
6959
message(
@@ -76,5 +66,3 @@ message(
7666
"* CUSTOM library : ${GMT_CUSTOM_LIB_NAME}\n"
7767
"* Installing CUSTOM in : ${CMAKE_INSTALL_PREFIX}\n"
7868
"* CUSTOM_SHARE_PATH : ${CMAKE_INSTALL_PREFIX}/${CUSTOM_SHARE_PATH}")
79-
80-
# vim: textwidth=78 noexpandtab tabstop=2 softtabstop=2 shiftwidth=2

cmake/modules/FindGMT.cmake

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#
2+
#
3+
# Locate GMT
4+
#
5+
# This module accepts the following environment variables:
6+
#
7+
# GMT_DIR or GMT_ROOT - Specify the location of GMT
8+
#
9+
# This module defines the following CMake variables:
10+
#
11+
# GMT_FOUND - True if libgmt is found
12+
# GMT_LIBRARY - A variable pointing to the GMT library
13+
# GMT_INCLUDE_DIR - Where to find the headers
14+
# GMT_INCLUDE_DIRS - Where to find the headers
15+
# GMT_DEFINITIONS - Extra compiler flags
16+
17+
#=============================================================================
18+
# Inspired by FindGDAL
19+
#
20+
# Distributed under the OSI-approved bsd license (the "License")
21+
#
22+
# This software is distributed WITHOUT ANY WARRANTY; without even the
23+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24+
# See COPYING-CMAKE-SCRIPTS for more information.
25+
#=============================================================================
26+
27+
# This makes the presumption that you include gmt.h like
28+
#
29+
#include "gmt.h"
30+
31+
if (UNIX AND NOT GMT_FOUND)
32+
# Use gmt-config to obtain the libraries
33+
find_program (GMT_CONFIG gmt-config
34+
HINTS
35+
${GMT_DIR}
36+
${GMT_ROOT}
37+
$ENV{GMT_DIR}
38+
$ENV{GMT_ROOT}
39+
PATH_SUFFIXES bin
40+
PATHS
41+
/sw # Fink
42+
/opt/local # DarwinPorts
43+
/opt/csw # Blastwave
44+
/opt
45+
/usr/local
46+
)
47+
48+
if (GMT_CONFIG)
49+
execute_process (COMMAND ${GMT_CONFIG} --cflags
50+
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
51+
OUTPUT_VARIABLE GMT_CONFIG_CFLAGS)
52+
if (GMT_CONFIG_CFLAGS)
53+
string (REGEX MATCHALL "(^| )-I[^ ]+" _gmt_dashI ${GMT_CONFIG_CFLAGS})
54+
string (REGEX REPLACE "(^| )-I" "" _gmt_includepath "${_gmt_dashI}")
55+
string (REGEX REPLACE "(^| )-I[^ ]+" "" _gmt_cflags_other ${GMT_CONFIG_CFLAGS})
56+
endif (GMT_CONFIG_CFLAGS)
57+
execute_process (COMMAND ${GMT_CONFIG} --libs
58+
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
59+
OUTPUT_VARIABLE GMT_CONFIG_LIBS)
60+
if (GMT_CONFIG_LIBS)
61+
# Ensure -l is precedeced by whitespace to not match
62+
# '-l' in '-L/usr/lib/x86_64-linux-gnu/hdf5/serial'
63+
string (REGEX MATCHALL "(^| )-l[^ ]+" _gmt_dashl ${GMT_CONFIG_LIBS})
64+
string (REGEX REPLACE "(^| )-l" "" _gmt_lib "${_gmt_dashl}")
65+
string (REGEX MATCHALL "(^| )-L[^ ]+" _gmt_dashL ${GMT_CONFIG_LIBS})
66+
string (REGEX REPLACE "(^| )-L" "" _gmt_libpath "${_gmt_dashL}")
67+
endif (GMT_CONFIG_LIBS)
68+
endif (GMT_CONFIG)
69+
if (_gmt_lib)
70+
list (REMOVE_DUPLICATES _gmt_lib)
71+
list (REMOVE_ITEM _gmt_lib gmt)
72+
endif (_gmt_lib)
73+
endif (UNIX AND NOT GMT_FOUND)
74+
75+
find_path (GMT_INCLUDE_DIR gmt.h
76+
HINTS
77+
${_gmt_includepath}
78+
${GMT_DIR}
79+
${GMT_ROOT}
80+
$ENV{GMT_DIR}
81+
$ENV{GMT_ROOT}
82+
PATH_SUFFIXES
83+
include/gmt
84+
include
85+
PATHS
86+
/sw # Fink
87+
/opt/local # DarwinPorts
88+
/opt/csw # Blastwave
89+
/opt
90+
/usr/local
91+
)
92+
93+
find_library (GMT_LIBRARY
94+
NAMES gmt
95+
HINTS
96+
${_gmt_libpath}
97+
${GMT_DIR}
98+
${GMT_ROOT}
99+
$ENV{GMT_DIR}
100+
$ENV{GMT_ROOT}
101+
PATH_SUFFIXES lib
102+
PATHS
103+
/sw
104+
/opt/local
105+
/opt/csw
106+
/opt
107+
/usr/local
108+
)
109+
110+
# find all libs that gmt-config reports
111+
foreach (_extralib ${_gmt_lib})
112+
find_library (_found_lib_${_extralib}
113+
NAMES ${_extralib}
114+
PATHS ${_gmt_libpath})
115+
list (APPEND GMT_LIBRARY ${_found_lib_${_extralib}})
116+
endforeach (_extralib)
117+
118+
include (FindPackageHandleStandardArgs)
119+
find_package_handle_standard_args (GMT
120+
DEFAULT_MSG GMT_LIBRARY GMT_INCLUDE_DIR)
121+
122+
set (GMT_LIBRARIES ${GMT_LIBRARY})
123+
set (GMT_INCLUDE_DIRS ${GMT_INCLUDE_DIR})
124+
string (REPLACE "-DNDEBUG" "" GMT_DEFINITIONS "${_gmt_cflags_other}")

cmake/modules/FindNETCDF.cmake

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#
2+
#
3+
# Locate netcdf
4+
#
5+
# This module accepts the following environment variables:
6+
#
7+
# NETCDF_DIR or NETCDF_ROOT - Specify the location of NetCDF
8+
#
9+
# This module defines the following CMake variables:
10+
#
11+
# NETCDF_FOUND - True if libnetcdf is found
12+
# NETCDF_LIBRARY - A variable pointing to the NetCDF library
13+
# NETCDF_INCLUDE_DIR - Where to find the headers
14+
# NETCDF_INCLUDE_DIRS - Where to find the headers
15+
# NETCDF_DEFINITIONS - Extra compiler flags
16+
17+
#=============================================================================
18+
# Inspired by FindGDAL
19+
#
20+
# Distributed under the OSI-approved bsd license (the "License")
21+
#
22+
# This software is distributed WITHOUT ANY WARRANTY; without even the
23+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24+
# See COPYING-CMAKE-SCRIPTS for more information.
25+
#=============================================================================
26+
27+
# This makes the presumption that you are include netcdf.h like
28+
#
29+
#include "netcdf.h"
30+
31+
if (UNIX AND NOT NETCDF_FOUND)
32+
# Use nc-config to obtain the libraries
33+
find_program (NETCDF_CONFIG nc-config
34+
HINTS
35+
${NETCDF_DIR}
36+
${NETCDF_ROOT}
37+
$ENV{NETCDF_DIR}
38+
$ENV{NETCDF_ROOT}
39+
PATH_SUFFIXES bin
40+
PATHS
41+
/sw # Fink
42+
/opt/local # DarwinPorts
43+
/opt/csw # Blastwave
44+
/opt
45+
/usr/local
46+
)
47+
48+
if (NETCDF_CONFIG)
49+
execute_process (COMMAND ${NETCDF_CONFIG} --cflags
50+
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
51+
OUTPUT_VARIABLE NETCDF_CONFIG_CFLAGS)
52+
if (NETCDF_CONFIG_CFLAGS)
53+
string (REGEX MATCHALL "(^| )-I[^ ]+" _netcdf_dashI ${NETCDF_CONFIG_CFLAGS})
54+
string (REGEX REPLACE "(^| )-I" "" _netcdf_includepath "${_netcdf_dashI}")
55+
string (REGEX REPLACE "(^| )-I[^ ]+" "" _netcdf_cflags_other ${NETCDF_CONFIG_CFLAGS})
56+
endif (NETCDF_CONFIG_CFLAGS)
57+
execute_process (COMMAND ${NETCDF_CONFIG} --libs
58+
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
59+
OUTPUT_VARIABLE NETCDF_CONFIG_LIBS)
60+
if (NETCDF_CONFIG_LIBS)
61+
# Ensure -l is precedeced by whitespace to not match
62+
# '-l' in '-L/usr/lib/x86_64-linux-gnu/hdf5/serial'
63+
string (REGEX MATCHALL "(^| )-l[^ ]+" _netcdf_dashl ${NETCDF_CONFIG_LIBS})
64+
string (REGEX REPLACE "(^| )-l" "" _netcdf_lib "${_netcdf_dashl}")
65+
string (REGEX MATCHALL "(^| )-L[^ ]+" _netcdf_dashL ${NETCDF_CONFIG_LIBS})
66+
string (REGEX REPLACE "(^| )-L" "" _netcdf_libpath "${_netcdf_dashL}")
67+
endif (NETCDF_CONFIG_LIBS)
68+
endif (NETCDF_CONFIG)
69+
if (_netcdf_lib)
70+
list (REMOVE_DUPLICATES _netcdf_lib)
71+
list (REMOVE_ITEM _netcdf_lib netcdf)
72+
endif (_netcdf_lib)
73+
endif (UNIX AND NOT NETCDF_FOUND)
74+
75+
find_path (NETCDF_INCLUDE_DIR netcdf.h
76+
HINTS
77+
${_netcdf_includepath}
78+
${NETCDF_DIR}
79+
${NETCDF_ROOT}
80+
$ENV{NETCDF_DIR}
81+
$ENV{NETCDF_ROOT}
82+
PATH_SUFFIXES
83+
include/netcdf
84+
include/netcdf-4
85+
include/netcdf-3
86+
include
87+
PATHS
88+
/sw # Fink
89+
/opt/local # DarwinPorts
90+
/opt/csw # Blastwave
91+
/opt
92+
/usr/local
93+
)
94+
95+
find_library (NETCDF_LIBRARY
96+
NAMES netcdf
97+
HINTS
98+
${_netcdf_libpath}
99+
${NETCDF_DIR}
100+
${NETCDF_ROOT}
101+
$ENV{NETCDF_DIR}
102+
$ENV{NETCDF_ROOT}
103+
PATH_SUFFIXES lib
104+
PATHS
105+
/sw
106+
/opt/local
107+
/opt/csw
108+
/opt
109+
/usr/local
110+
)
111+
112+
# find all libs that nc-config reports
113+
foreach (_extralib ${_netcdf_lib})
114+
find_library (_found_lib_${_extralib}
115+
NAMES ${_extralib}
116+
PATHS ${_netcdf_libpath})
117+
list (APPEND NETCDF_LIBRARY ${_found_lib_${_extralib}})
118+
endforeach (_extralib)
119+
120+
if (NETCDF_LIBRARY AND NETCDF_INCLUDE_DIR AND NOT HAVE_NETCDF4)
121+
# Ensure that NetCDF with version 4 extensions is installed
122+
include (CMakePushCheckState)
123+
include (CheckSymbolExists)
124+
cmake_push_check_state() # save state of CMAKE_REQUIRED_*
125+
set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${NETCDF_INCLUDE_DIR})
126+
set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${NETCDF_LIBRARY})
127+
set (HAVE_NETCDF4 HAVE_NETCDF4) # to force check_symbol_exists again
128+
check_symbol_exists (nc_def_var_deflate netcdf.h HAVE_NETCDF4)
129+
cmake_pop_check_state() # restore state of CMAKE_REQUIRED_*
130+
if (NOT HAVE_NETCDF4)
131+
message (SEND_ERROR "Library found but netCDF-4/HDF5 format unsupported. Do not configure netCDF-4 with --disable-netcdf-4.")
132+
endif (NOT HAVE_NETCDF4)
133+
endif (NETCDF_LIBRARY AND NETCDF_INCLUDE_DIR AND NOT HAVE_NETCDF4)
134+
135+
include (FindPackageHandleStandardArgs)
136+
find_package_handle_standard_args (NETCDF
137+
DEFAULT_MSG NETCDF_LIBRARY NETCDF_INCLUDE_DIR HAVE_NETCDF4)
138+
139+
set (NETCDF_LIBRARIES ${NETCDF_LIBRARY})
140+
set (NETCDF_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR})
141+
string (REPLACE "-DNDEBUG" "" NETCDF_DEFINITIONS "${_netcdf_cflags_other}")

src/CMakeLists.txt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#
2-
# $Id: CMakeLists.txt 11838 2013-06-28 06:49:32Z pwessel $
3-
#
42
# Copyright (c) 1991-2020 by GMT Team (https://www.generic-mapping-tools.org/team.html)
53
# See LICENSE.TXT file for copying and redistribution conditions.
64
#
@@ -48,3 +46,29 @@ set (SUPPL_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/custom_config.h)
4846
set (CUSTOM_PACKAGE_VERSION "6.1.0")
4947

5048
configure_file (custom_config.h.in custom_config.h)
49+
50+
find_package (GMT REQUIRED)
51+
include_directories (${GMT_INCLUDE_DIR})
52+
53+
find_package (NETCDF REQUIRED)
54+
include_directories (${NETCDF_INCLUDE_DIR})
55+
56+
add_library (${SUPPL_LIB_NAME} MODULE
57+
${SUPPL_LIB_SRCS}
58+
${CMAKE_CURRENT_BINARY_DIR}/custom_config.h
59+
gmt_custom_glue.c
60+
)
61+
62+
target_link_libraries (${SUPPL_LIB_NAME}
63+
${GMT_LIBRARIES}
64+
${NETCDF_LIBRARIES}
65+
)
66+
67+
set_target_properties (${SUPPL_LIB_NAME}
68+
PROPERTIES
69+
OUTPUT_NAME ${SUPPL_LIB_NAME}
70+
RUNTIME_OUTPUT_NAME ${SUPPL_LIB_NAME}
71+
LIBRARY_OUTPUT_DIRECTORY plugins
72+
RUNTIME_OUTPUT_DIRECTORY plugins
73+
PREFIX ""
74+
DEFINE_SYMBOL "LIBRARY_EXPORTS")

0 commit comments

Comments
 (0)