Skip to content

Further work to upgrade the custom supplment for GMT 6.1 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#
# $Id: CMakeLists.txt 11803 2013-06-24 23:06:22Z pwessel $
#
# Copyright (c) 1991-2017 by P. Wessel, W. H. F. Smith, R. Scharroo, J. Luis, and F. Wobbe
# Copyright (c) 1991-2020 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
# See LICENSE.TXT file for copying and redistribution conditions.
#
# This program is free software; you can redistribute it and/or modify
Expand All @@ -13,11 +11,9 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# Contact info: gmt.soest.hawaii.edu
# Contact info: www.generic-mapping-tools.org
#-------------------------------------------------------------------------------
#
# To modify the cmake process: Edit your cmake/ConfigUser.cmake file
#
# To build out-of-source do (for example):
#
# mkdir build
Expand All @@ -26,14 +22,10 @@
#
# CMAKE_BUILD_TYPE can be: empty, Debug, Release, RelWithDebInfo or MinSizeRel
#
# cmake creates a new file cmake/ConfigUser.cmake if it does not already
# exist. You can configure additional options there.
#

## Section 0: Define project name. Change this to what your plugin should be named.
## Define project name. Change this to what your plugin should be named.
project (custom)

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

# Include configuration options (default options and options overridden by user).
include (ConfigCMake)

# Find UNIX commands
include (FindUnixCommands)

# Add subdirectories
add_subdirectory (src)
get_property(GMT_CUSTOM_LIB_PATH TARGET customlib PROPERTY LOCATION)
GET_FILENAME_COMPONENT (GMT_CUSTOM_LIB_NAME ${GMT_CUSTOM_LIB_PATH} NAME)

# Get name of the custom supplemental library
get_directory_property (_suppl_lib_name DIRECTORY "src" DEFINITION "SUPPL_LIB_NAME")
get_target_property (_name ${_suppl_lib_name} OUTPUT_NAME)
get_target_property (_prefix ${_suppl_lib_name} PREFIX)
set (GMT_CUSTOM_LIB_NAME ${_prefix}${_name}${CMAKE_SHARED_MODULE_SUFFIX})

# Configuration done
message(
Expand All @@ -76,5 +66,3 @@ message(
"* CUSTOM library : ${GMT_CUSTOM_LIB_NAME}\n"
"* Installing CUSTOM in : ${CMAKE_INSTALL_PREFIX}\n"
"* CUSTOM_SHARE_PATH : ${CMAKE_INSTALL_PREFIX}/${CUSTOM_SHARE_PATH}")

# vim: textwidth=78 noexpandtab tabstop=2 softtabstop=2 shiftwidth=2
124 changes: 124 additions & 0 deletions cmake/modules/FindGMT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#
#
# Locate GMT
#
# This module accepts the following environment variables:
#
# GMT_DIR or GMT_ROOT - Specify the location of GMT
#
# This module defines the following CMake variables:
#
# GMT_FOUND - True if libgmt is found
# GMT_LIBRARY - A variable pointing to the GMT library
# GMT_INCLUDE_DIR - Where to find the headers
# GMT_INCLUDE_DIRS - Where to find the headers
# GMT_DEFINITIONS - Extra compiler flags

#=============================================================================
# Inspired by FindGDAL
#
# Distributed under the OSI-approved bsd license (the "License")
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See COPYING-CMAKE-SCRIPTS for more information.
#=============================================================================

# This makes the presumption that you include gmt.h like
#
#include "gmt.h"

if (UNIX AND NOT GMT_FOUND)
# Use gmt-config to obtain the libraries
find_program (GMT_CONFIG gmt-config
HINTS
${GMT_DIR}
${GMT_ROOT}
$ENV{GMT_DIR}
$ENV{GMT_ROOT}
PATH_SUFFIXES bin
PATHS
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
/usr/local
)

if (GMT_CONFIG)
execute_process (COMMAND ${GMT_CONFIG} --cflags
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE GMT_CONFIG_CFLAGS)
if (GMT_CONFIG_CFLAGS)
string (REGEX MATCHALL "(^| )-I[^ ]+" _gmt_dashI ${GMT_CONFIG_CFLAGS})
string (REGEX REPLACE "(^| )-I" "" _gmt_includepath "${_gmt_dashI}")
string (REGEX REPLACE "(^| )-I[^ ]+" "" _gmt_cflags_other ${GMT_CONFIG_CFLAGS})
endif (GMT_CONFIG_CFLAGS)
execute_process (COMMAND ${GMT_CONFIG} --libs
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE GMT_CONFIG_LIBS)
if (GMT_CONFIG_LIBS)
# Ensure -l is precedeced by whitespace to not match
# '-l' in '-L/usr/lib/x86_64-linux-gnu/hdf5/serial'
string (REGEX MATCHALL "(^| )-l[^ ]+" _gmt_dashl ${GMT_CONFIG_LIBS})
string (REGEX REPLACE "(^| )-l" "" _gmt_lib "${_gmt_dashl}")
string (REGEX MATCHALL "(^| )-L[^ ]+" _gmt_dashL ${GMT_CONFIG_LIBS})
string (REGEX REPLACE "(^| )-L" "" _gmt_libpath "${_gmt_dashL}")
endif (GMT_CONFIG_LIBS)
endif (GMT_CONFIG)
if (_gmt_lib)
list (REMOVE_DUPLICATES _gmt_lib)
list (REMOVE_ITEM _gmt_lib gmt)
endif (_gmt_lib)
endif (UNIX AND NOT GMT_FOUND)

find_path (GMT_INCLUDE_DIR gmt.h
HINTS
${_gmt_includepath}
${GMT_DIR}
${GMT_ROOT}
$ENV{GMT_DIR}
$ENV{GMT_ROOT}
PATH_SUFFIXES
include/gmt
include
PATHS
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
/usr/local
)

find_library (GMT_LIBRARY
NAMES gmt
HINTS
${_gmt_libpath}
${GMT_DIR}
${GMT_ROOT}
$ENV{GMT_DIR}
$ENV{GMT_ROOT}
PATH_SUFFIXES lib
PATHS
/sw
/opt/local
/opt/csw
/opt
/usr/local
)

# find all libs that gmt-config reports
foreach (_extralib ${_gmt_lib})
find_library (_found_lib_${_extralib}
NAMES ${_extralib}
PATHS ${_gmt_libpath})
list (APPEND GMT_LIBRARY ${_found_lib_${_extralib}})
endforeach (_extralib)

include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (GMT
DEFAULT_MSG GMT_LIBRARY GMT_INCLUDE_DIR)

set (GMT_LIBRARIES ${GMT_LIBRARY})
set (GMT_INCLUDE_DIRS ${GMT_INCLUDE_DIR})
string (REPLACE "-DNDEBUG" "" GMT_DEFINITIONS "${_gmt_cflags_other}")
141 changes: 141 additions & 0 deletions cmake/modules/FindNETCDF.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#
#
# Locate netcdf
#
# This module accepts the following environment variables:
#
# NETCDF_DIR or NETCDF_ROOT - Specify the location of NetCDF
#
# This module defines the following CMake variables:
#
# NETCDF_FOUND - True if libnetcdf is found
# NETCDF_LIBRARY - A variable pointing to the NetCDF library
# NETCDF_INCLUDE_DIR - Where to find the headers
# NETCDF_INCLUDE_DIRS - Where to find the headers
# NETCDF_DEFINITIONS - Extra compiler flags

#=============================================================================
# Inspired by FindGDAL
#
# Distributed under the OSI-approved bsd license (the "License")
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See COPYING-CMAKE-SCRIPTS for more information.
#=============================================================================

# This makes the presumption that you are include netcdf.h like
#
#include "netcdf.h"

if (UNIX AND NOT NETCDF_FOUND)
# Use nc-config to obtain the libraries
find_program (NETCDF_CONFIG nc-config
HINTS
${NETCDF_DIR}
${NETCDF_ROOT}
$ENV{NETCDF_DIR}
$ENV{NETCDF_ROOT}
PATH_SUFFIXES bin
PATHS
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
/usr/local
)

if (NETCDF_CONFIG)
execute_process (COMMAND ${NETCDF_CONFIG} --cflags
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE NETCDF_CONFIG_CFLAGS)
if (NETCDF_CONFIG_CFLAGS)
string (REGEX MATCHALL "(^| )-I[^ ]+" _netcdf_dashI ${NETCDF_CONFIG_CFLAGS})
string (REGEX REPLACE "(^| )-I" "" _netcdf_includepath "${_netcdf_dashI}")
string (REGEX REPLACE "(^| )-I[^ ]+" "" _netcdf_cflags_other ${NETCDF_CONFIG_CFLAGS})
endif (NETCDF_CONFIG_CFLAGS)
execute_process (COMMAND ${NETCDF_CONFIG} --libs
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE NETCDF_CONFIG_LIBS)
if (NETCDF_CONFIG_LIBS)
# Ensure -l is precedeced by whitespace to not match
# '-l' in '-L/usr/lib/x86_64-linux-gnu/hdf5/serial'
string (REGEX MATCHALL "(^| )-l[^ ]+" _netcdf_dashl ${NETCDF_CONFIG_LIBS})
string (REGEX REPLACE "(^| )-l" "" _netcdf_lib "${_netcdf_dashl}")
string (REGEX MATCHALL "(^| )-L[^ ]+" _netcdf_dashL ${NETCDF_CONFIG_LIBS})
string (REGEX REPLACE "(^| )-L" "" _netcdf_libpath "${_netcdf_dashL}")
endif (NETCDF_CONFIG_LIBS)
endif (NETCDF_CONFIG)
if (_netcdf_lib)
list (REMOVE_DUPLICATES _netcdf_lib)
list (REMOVE_ITEM _netcdf_lib netcdf)
endif (_netcdf_lib)
endif (UNIX AND NOT NETCDF_FOUND)

find_path (NETCDF_INCLUDE_DIR netcdf.h
HINTS
${_netcdf_includepath}
${NETCDF_DIR}
${NETCDF_ROOT}
$ENV{NETCDF_DIR}
$ENV{NETCDF_ROOT}
PATH_SUFFIXES
include/netcdf
include/netcdf-4
include/netcdf-3
include
PATHS
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
/usr/local
)

find_library (NETCDF_LIBRARY
NAMES netcdf
HINTS
${_netcdf_libpath}
${NETCDF_DIR}
${NETCDF_ROOT}
$ENV{NETCDF_DIR}
$ENV{NETCDF_ROOT}
PATH_SUFFIXES lib
PATHS
/sw
/opt/local
/opt/csw
/opt
/usr/local
)

# find all libs that nc-config reports
foreach (_extralib ${_netcdf_lib})
find_library (_found_lib_${_extralib}
NAMES ${_extralib}
PATHS ${_netcdf_libpath})
list (APPEND NETCDF_LIBRARY ${_found_lib_${_extralib}})
endforeach (_extralib)

if (NETCDF_LIBRARY AND NETCDF_INCLUDE_DIR AND NOT HAVE_NETCDF4)
# Ensure that NetCDF with version 4 extensions is installed
include (CMakePushCheckState)
include (CheckSymbolExists)
cmake_push_check_state() # save state of CMAKE_REQUIRED_*
set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${NETCDF_INCLUDE_DIR})
set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${NETCDF_LIBRARY})
set (HAVE_NETCDF4 HAVE_NETCDF4) # to force check_symbol_exists again
check_symbol_exists (nc_def_var_deflate netcdf.h HAVE_NETCDF4)
cmake_pop_check_state() # restore state of CMAKE_REQUIRED_*
if (NOT HAVE_NETCDF4)
message (SEND_ERROR "Library found but netCDF-4/HDF5 format unsupported. Do not configure netCDF-4 with --disable-netcdf-4.")
endif (NOT HAVE_NETCDF4)
endif (NETCDF_LIBRARY AND NETCDF_INCLUDE_DIR AND NOT HAVE_NETCDF4)

include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (NETCDF
DEFAULT_MSG NETCDF_LIBRARY NETCDF_INCLUDE_DIR HAVE_NETCDF4)

set (NETCDF_LIBRARIES ${NETCDF_LIBRARY})
set (NETCDF_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR})
string (REPLACE "-DNDEBUG" "" NETCDF_DEFINITIONS "${_netcdf_cflags_other}")
28 changes: 26 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#
# $Id: CMakeLists.txt 11838 2013-06-28 06:49:32Z pwessel $
#
# Copyright (c) 1991-2020 by GMT Team (https://www.generic-mapping-tools.org/team.html)
# See LICENSE.TXT file for copying and redistribution conditions.
#
Expand Down Expand Up @@ -48,3 +46,29 @@ set (SUPPL_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/custom_config.h)
set (CUSTOM_PACKAGE_VERSION "6.1.0")

configure_file (custom_config.h.in custom_config.h)

find_package (GMT REQUIRED)
include_directories (${GMT_INCLUDE_DIR})

find_package (NETCDF REQUIRED)
include_directories (${NETCDF_INCLUDE_DIR})

add_library (${SUPPL_LIB_NAME} MODULE
${SUPPL_LIB_SRCS}
${CMAKE_CURRENT_BINARY_DIR}/custom_config.h
gmt_custom_glue.c
)

target_link_libraries (${SUPPL_LIB_NAME}
${GMT_LIBRARIES}
${NETCDF_LIBRARIES}
)

set_target_properties (${SUPPL_LIB_NAME}
PROPERTIES
OUTPUT_NAME ${SUPPL_LIB_NAME}
RUNTIME_OUTPUT_NAME ${SUPPL_LIB_NAME}
LIBRARY_OUTPUT_DIRECTORY plugins
RUNTIME_OUTPUT_DIRECTORY plugins
PREFIX ""
DEFINE_SYMBOL "LIBRARY_EXPORTS")
Loading