From c0d77b160dfa513e7a3362dd63935e077b8b593d Mon Sep 17 00:00:00 2001 From: Michael Uleysky Date: Sun, 27 Sep 2015 12:00:56 +1000 Subject: [PATCH] Gmt module: CMake build system for gmt module --- cmake/modules/FindGMT.cmake | 114 ++++++++++++++++++++++++++++++ modules/gmt/CMakeLists.txt | 3 + modules/gmt/ModuleSetup.cmake | 9 +++ modules/gmt/gmt_filter_headfoot.l | 2 - modules/gmt/makemod | 2 +- 5 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 cmake/modules/FindGMT.cmake create mode 100644 modules/gmt/CMakeLists.txt create mode 100644 modules/gmt/ModuleSetup.cmake diff --git a/cmake/modules/FindGMT.cmake b/cmake/modules/FindGMT.cmake new file mode 100644 index 0000000..29678f4 --- /dev/null +++ b/cmake/modules/FindGMT.cmake @@ -0,0 +1,114 @@ +# 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 + +# Created by Michael Uleysky. Based on FindGDAL.cmake created by Eric Wing. +# This makes the presumption that you are include gmt.h like +# +#include "gmt.h" + +if (DEFINED GMT_ROOT AND NOT GMT_ROOT) + set (GMT_LIBRARY "" CACHE INTERNAL "") + set (GMT_INCLUDE_DIR "" CACHE INTERNAL "") + return() +endif (DEFINED GMT_ROOT AND NOT GMT_ROOT) + +if (UNIX AND NOT GMT_FOUND) + # Use gmt-config to obtain the library version (this should hopefully + # allow us to -lGMT5.x.y where x.y are correct version) + 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/gmt + /opt/GMT + /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) + 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) +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/GMT + include + PATHS + ~/Library/Frameworks/GMT.framework/Headers + /Library/Frameworks/GMT.framework/Headers + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt/gmt + /opt/GMT + /opt + /usr/local +) + +find_library (GMT_LIBRARY + NAMES ${_GMT_lib} gmt gmt5.1 gmt5.1.2 gmt5.1.3 + HINTS + ${GMT_DIR} + ${GMT_ROOT} + $ENV{GMT_DIR} + $ENV{GMT_ROOT} + ${_GMT_libpath} + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks/GMT.framework + /Library/Frameworks/GMT.framework + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt/gmt + /opt/GMT + /opt + /usr/local +) + +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}) + diff --git a/modules/gmt/CMakeLists.txt b/modules/gmt/CMakeLists.txt new file mode 100644 index 0000000..88d13d4 --- /dev/null +++ b/modules/gmt/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.5) + +include(BuildModule) diff --git a/modules/gmt/ModuleSetup.cmake b/modules/gmt/ModuleSetup.cmake new file mode 100644 index 0000000..299146b --- /dev/null +++ b/modules/gmt/ModuleSetup.cmake @@ -0,0 +1,9 @@ +find_package(FLEX REQUIRED) +FLEX_TARGET(GMT_hfScanner ${moddir}/gmt_filter_headfoot.l ${CMAKE_CURRENT_BINARY_DIR}/gmt_filter_headfoot.cpp COMPILE_FLAGS "--header-file=${CMAKE_CURRENT_BINARY_DIR}/gmt_filter_headfoot.h") +set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES gmt_filter_headfoot.h) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +find_package(GMT REQUIRED) +set(MODULE_ADDITIONAL_SOURCES ${FLEX_GMT_hfScanner_OUTPUTS}) +set(MODULE_ADDITIONAL_INCLUDES ${GMT_INCLUDE_DIR}) +set(MODULE_ADDITIONAL_LIBRARIES ${GMT_LIBRARIES}) diff --git a/modules/gmt/gmt_filter_headfoot.l b/modules/gmt/gmt_filter_headfoot.l index 0262f2c..e5b5a0a 100644 --- a/modules/gmt/gmt_filter_headfoot.l +++ b/modules/gmt/gmt_filter_headfoot.l @@ -2,8 +2,6 @@ %option warn %option yylineno %option noyywrap -%option header-file="gmt_filter_headfoot.h" -%option outfile="gmt_filter_headfoot.cpp" %option prefix="gmt_filter_headfoot" %option extra-type="std::string*" %option nounput diff --git a/modules/gmt/makemod b/modules/gmt/makemod index c52a527..831bc10 100644 --- a/modules/gmt/makemod +++ b/modules/gmt/makemod @@ -13,7 +13,7 @@ ifdef MODULE filters.d: gmt_filter_headfoot.h gmt_filter_headfoot.cpp: gmt_filter_headfoot.l - flex $< + flex -o $@ --header-file=gmt_filter_headfoot.h $< [ -f gmt_filter_headfoot.h ] && touch gmt_filter_headfoot.h gmt_filter_headfoot.h: gmt_filter_headfoot.l gmt_filter_headfoot.cpp