1# 2# 3# Useful CMake variables. 4# 5# There are five configuration files: 6# 7# 1) "ConfigDefault.cmake" - is version controlled and used to add new default 8# variables and set defaults for everyone. 9# 2) "ConfigUser.cmake" in the source tree - is not version controlled 10# (currently listed in .gitignore) and used to override basic default settings on 11# a per-user basis. 12# 3) "ConfigUser.cmake" in the build tree - is used to override 13# "ConfigUser.cmake" in the source tree. 14# 4) "ConfigUserAdvanced.cmake" in the source tree - is not version controlled 15# (currently listed in .gitignore) and used to override advanced default settings on 16# a per-user basis. 17# 5) "ConfigUserAdvanced.cmake" in the build tree - is used to override 18# "ConfigUserAdvanced.cmake" in the source tree. 19# 20# NOTE: If you want to change CMake behaviour just for yourself, 21# copy "ConfigUserTemplate.cmake" to "ConfigUser.cmake" and then edit 22# "ConfigUser.cmake" for basic settings. For advanced settings, 23# copy "ConfigUserAdvancedTemplate.cmake" to "ConfigUserAdvanced.cmake" and edit it. 24# DO NOT EDIT "ConfigDefault.cmake" or the CMake template files. 25# 26include ("${CMAKE_SOURCE_DIR}/cmake/ConfigDefault.cmake") 27 28# A "ConfigUser.cmake" in the source tree overrides the advanced defaults. 29if (EXISTS "${CMAKE_SOURCE_DIR}/cmake/ConfigUser.cmake") 30 include ("${CMAKE_SOURCE_DIR}/cmake/ConfigUser.cmake") 31endif (EXISTS "${CMAKE_SOURCE_DIR}/cmake/ConfigUser.cmake") 32 33# If you've got a 'ConfigUser.cmake' in the build tree then that overrides the 34# one in the source tree. 35if (EXISTS "${CMAKE_BINARY_DIR}/cmake/ConfigUser.cmake") 36 include ("${CMAKE_BINARY_DIR}/cmake/ConfigUser.cmake") 37endif (EXISTS "${CMAKE_BINARY_DIR}/cmake/ConfigUser.cmake") 38 39# A "ConfigUserAdvanced.cmake" in the source tree overrides the advanced defaults. 40if (EXISTS "${CMAKE_SOURCE_DIR}/cmake/ConfigUserAdvanced.cmake") 41 include ("${CMAKE_SOURCE_DIR}/cmake/ConfigUserAdvanced.cmake") 42endif (EXISTS "${CMAKE_SOURCE_DIR}/cmake/ConfigUserAdvanced.cmake") 43 44# If you've got a 'ConfigUserAdvanced.cmake' in the build tree then that overrides the 45# one in the source tree. 46if (EXISTS "${CMAKE_BINARY_DIR}/cmake/ConfigUserAdvanced.cmake") 47 include ("${CMAKE_BINARY_DIR}/cmake/ConfigUserAdvanced.cmake") 48endif (EXISTS "${CMAKE_BINARY_DIR}/cmake/ConfigUserAdvanced.cmake") 49 50########################################################### 51# Do any needed processing of the configuration variables # 52########################################################### 53 54# Set default build type to 'Release' 55if (NOT CMAKE_BUILD_TYPE) 56 set (CMAKE_BUILD_TYPE Release) 57endif (NOT CMAKE_BUILD_TYPE) 58 59# Here we change it to add the git commit hash for non-public releases 60set (GMT_PACKAGE_VERSION_WITH_GIT_REVISION ${GMT_PACKAGE_VERSION}) 61 62# Check if it's a git repository or not 63if (EXISTS ${GMT_SOURCE_DIR}/.git) 64 set (HAVE_GIT_VERSION TRUE) 65endif (EXISTS ${GMT_SOURCE_DIR}/.git) 66 67# Add the last git commit hash and date to the package version if this is a non-public release. 68# A non-public release has a FALSE 'GMT_PUBLIC_RELEASE' variable in 'ConfigDefault.cmake'. 69if (GIT_FOUND AND HAVE_GIT_VERSION AND NOT GMT_PUBLIC_RELEASE) 70 # Get the last git commit hash 71 execute_process ( 72 COMMAND ${GIT_EXECUTABLE} describe --abbrev=7 --always --dirty 73 WORKING_DIRECTORY ${GMT_SOURCE_DIR} 74 RESULT_VARIABLE GIT_RETURN_CODE 75 OUTPUT_VARIABLE GIT_COMMIT_HASH 76 OUTPUT_STRIP_TRAILING_WHITESPACE) 77 78 if (GIT_RETURN_CODE) 79 message (STATUS "Unable to determine git commit hash for non-public release - ignoring.") 80 else (GIT_RETURN_CODE) 81 if (GIT_COMMIT_HASH) 82 # For non-public release, add the last git commit hash and date 83 execute_process ( 84 COMMAND ${GIT_EXECUTABLE} log -1 --date=short --pretty=format:%cd 85 WORKING_DIRECTORY ${GMT_SOURCE_DIR} 86 RESULT_VARIABLE GIT_DATE_RETURN_CODE 87 OUTPUT_VARIABLE GIT_COMMIT_DATE 88 OUTPUT_STRIP_TRAILING_WHITESPACE) 89 string(REPLACE "-" "." GIT_COMMIT_DATE "${GIT_COMMIT_DATE}") 90 set (GMT_PACKAGE_VERSION_WITH_GIT_REVISION "${GMT_PACKAGE_VERSION}_${GIT_COMMIT_HASH}_${GIT_COMMIT_DATE}") 91 endif (GIT_COMMIT_HASH) 92 endif (GIT_RETURN_CODE) 93endif (GIT_FOUND AND HAVE_GIT_VERSION AND NOT GMT_PUBLIC_RELEASE) 94 95# apply license restrictions 96if (LICENSE_RESTRICTED) # on 97 if (LICENSE_RESTRICTED STREQUAL GPL) 98 # restrict to GPL 99 elseif (LICENSE_RESTRICTED STREQUAL LGPL) 100 # restrict to LGPL 101 else (LICENSE_RESTRICTED STREQUAL GPL) 102 # unknown license 103 message (WARNING "unknown license: ${LICENSE_RESTRICTED}") 104 endif (LICENSE_RESTRICTED STREQUAL GPL) 105 # restrictions that apply to any of the above licenses 106else (LICENSE_RESTRICTED) # off 107 # no restrictions at all 108endif (LICENSE_RESTRICTED) 109 110# reset list of extra license files 111set (GMT_EXTRA_LICENSE_FILES) 112 113# location of GNU license files 114set (COPYING_GPL ${GMT_SOURCE_DIR}/COPYINGv3) 115set (COPYING_LGPL ${GMT_SOURCE_DIR}/COPYING.LESSERv3) 116 117# GMT paths used in the code 118if (NOT GMT_DATADIR) 119 # do not reset user setting 120 if (GMT_INSTALL_TRADITIONAL_FOLDERNAMES) 121 set (GMT_DATADIR "share") 122 else(GMT_INSTALL_TRADITIONAL_FOLDERNAMES) 123 set (GMT_DATADIR "share/gmt${GMT_INSTALL_NAME_SUFFIX}") 124 endif(GMT_INSTALL_TRADITIONAL_FOLDERNAMES) 125endif (NOT GMT_DATADIR) 126 127# Install path GMT_DOCDIR 128if (NOT GMT_DOCDIR) 129 # do not reset user setting 130 if (GMT_INSTALL_TRADITIONAL_FOLDERNAMES) 131 set (GMT_DOCDIR "${GMT_DATADIR}/doc") 132 else(GMT_INSTALL_TRADITIONAL_FOLDERNAMES) 133 set (GMT_DOCDIR "share/doc/gmt${GMT_INSTALL_NAME_SUFFIX}") 134 endif(GMT_INSTALL_TRADITIONAL_FOLDERNAMES) 135endif (NOT GMT_DOCDIR) 136 137# Install path GMT_MANDIR 138if (NOT GMT_MANDIR) 139 # do not reset user setting 140 if (GMT_INSTALL_TRADITIONAL_FOLDERNAMES) 141 set (GMT_MANDIR "${GMT_DATADIR}/man") 142 else(GMT_INSTALL_TRADITIONAL_FOLDERNAMES) 143 set (GMT_MANDIR "${GMT_DOCDIR}/man") 144 endif(GMT_INSTALL_TRADITIONAL_FOLDERNAMES) 145endif (NOT GMT_MANDIR) 146 147# Install path for GMT binaries, headers and libraries 148include (GNUInstallDirs) # defines CMAKE_INSTALL_LIBDIR (lib/lib64) 149if (NOT GMT_LIBDIR) 150 set (GMT_LIBDIR ${CMAKE_INSTALL_LIBDIR}) 151endif(NOT GMT_LIBDIR) 152 153if (NOT GMT_BINDIR) 154 set (GMT_BINDIR bin) 155endif(NOT GMT_BINDIR) 156 157if (NOT GMT_INCLUDEDIR) 158 set (GMT_INCLUDEDIR include/gmt${GMT_INSTALL_NAME_SUFFIX}) 159endif(NOT GMT_INCLUDEDIR) 160 161if (GMT_DATA_URL) # Backwards compatibility with old ConfigUser.cmake files 162 message (WARNING "CMake variable GMT_DATA_URL is deprecated and will be removed in the future releases. Use GMT_DATA_SERVER instead.") 163 set (GMT_DATA_SERVER ${GMT_DATA_URL}) 164endif (GMT_DATA_URL) 165 166# use, i.e. don't skip the full RPATH for the build tree 167set (CMAKE_SKIP_BUILD_RPATH FALSE) 168 169# when building, don't use the install RPATH already 170# (but later on when installing) 171set (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) 172 173# set the RPATH to be used when installing 174if (NOT DEFINED GMT_INSTALL_RELOCATABLE) 175 set (GMT_INSTALL_RELOCATABLE FALSE) 176endif (NOT DEFINED GMT_INSTALL_RELOCATABLE) 177if (GMT_INSTALL_RELOCATABLE) 178 # make executables relocatable on supported platforms (relative RPATH) 179 if (UNIX AND NOT CYGWIN) 180 # find relative libdir from executable dir 181 file (RELATIVE_PATH _rpath /${GMT_BINDIR} /${GMT_LIBDIR}) 182 # remove trailing / 183 string (REGEX REPLACE "/$" "" _rpath "${_rpath}") 184 if (APPLE) 185 # relative RPATH on osx 186 # CMP0042: CMake 3.0: MACOSX_RPATH is enabled by default 187 set (CMAKE_MACOSX_RPATH ON) 188 set (CMAKE_INSTALL_NAME_DIR @rpath) 189 set (CMAKE_INSTALL_RPATH "@rpath;@executable_path/${_rpath}") 190 else (APPLE) 191 # relative RPATH on Linux, Solaris, etc. 192 set (CMAKE_INSTALL_RPATH "\$ORIGIN/${_rpath}") 193 endif (APPLE) 194 endif (UNIX AND NOT CYGWIN) 195else (GMT_INSTALL_RELOCATABLE) 196 # set absolute RPATH 197 if (APPLE) 198 # CMP0042: CMake 3.0: MACOSX_RPATH is enabled by default 199 set (CMAKE_MACOSX_RPATH OFF) 200 set (CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${GMT_LIBDIR}") 201 else (APPLE) 202 # the RPATH to be used when installing, but only if it's not a 203 # system directory 204 list (FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES 205 "${CMAKE_INSTALL_PREFIX}/${GMT_LIBDIR}" isSystemDir) 206 if ("${isSystemDir}" STREQUAL "-1") 207 set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${GMT_LIBDIR}") 208 endif ("${isSystemDir}" STREQUAL "-1") 209 endif (APPLE) 210endif (GMT_INSTALL_RELOCATABLE) 211 212# add the automatically determined parts of the RPATH 213# which point to directories outside the build tree to the install RPATH 214set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 215 216# When running examples/tests with CTest (out-of-source) we need support for 217# running GMT programs from within ${GMT_BINARY_DIR}: 218if (DO_EXAMPLES OR DO_TESTS AND NOT SUPPORT_EXEC_IN_BINARY_DIR) 219 message (WARNING "Enabling SUPPORT_EXEC_IN_BINARY_DIR (required for " 220 "testing). Please disable testing on release builds.") 221 set (SUPPORT_EXEC_IN_BINARY_DIR ON) 222endif (DO_EXAMPLES OR DO_TESTS AND NOT SUPPORT_EXEC_IN_BINARY_DIR) 223 224# Some tests are known to fail, and can be excluded from the test by adding 225# the comment "# GMT_KNOWN_FAILURE". 226if (NOT DEFINED GMT_ENABLE_KNOWN2FAIL) 227 set (GMT_ENABLE_KNOWN2FAIL ON) 228endif (NOT DEFINED GMT_ENABLE_KNOWN2FAIL) 229 230# Make GNU, Intel, Clang and AppleClang compilers default to C99 231if (CMAKE_C_COMPILER_ID MATCHES "(GNU|Intel|Clang)" AND NOT CMAKE_C_FLAGS MATCHES "-std=") 232 set (CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}") 233endif () 234 235# Suppress MSVC deprecation and security warnings 236if (MSVC) 237 set (CMAKE_C_FLAGS "/D_CRT_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_DEPRECATE ${CMAKE_C_FLAGS}") 238 set (CMAKE_C_FLAGS "/D_CRT_NONSTDC_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE ${CMAKE_C_FLAGS}") 239endif (MSVC) 240 241# Handle the special developer option GMT_DOCS_DEPEND_ON_GMT 242# Normally this is ON. 243if (NOT DEFINED GMT_DOCS_DEPEND_ON_GMT) 244 set (GMT_DOCS_DEPEND_ON_GMT TRUE) 245endif (NOT DEFINED GMT_DOCS_DEPEND_ON_GMT) 246if (GMT_DOCS_DEPEND_ON_GMT) 247 add_custom_target (gmt_for_img_convert DEPENDS gmt) 248else (GMT_DOCS_DEPEND_ON_GMT) 249 add_custom_target (gmt_for_img_convert) 250endif (GMT_DOCS_DEPEND_ON_GMT) 251