Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

GmtHelperMacros.cmake 5.3 KB

You have to be logged in to leave a comment. Sign In
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
  1. #
  2. # $Id$
  3. #
  4. # - Useful CMake macros
  5. #
  6. # Copyright (c) 1991-2015 by P. Wessel, W. H. F. Smith, R. Scharroo, J. Luis and F. Wobbe
  7. # See LICENSE.TXT file for copying and redistribution conditions.
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU Lesser General Public License as published by
  11. # the Free Software Foundation; version 3 or any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Lesser General Public License for more details.
  17. #
  18. # Contact info: gmt.soest.hawaii.edu
  19. #-------------------------------------------------------------------------------
  20. # tag_from_current_source_dir (TAG [PREFIX])
  21. # add_depend_to_target (TARGET DEPEND [ DEPEND [ DEPEND ... ]])
  22. # add_file_to_cached_list (LIST [ FILE [ FILE ... ]])
  23. # get_subdir_var (VARIABLE VAR_NAME DIR [ DIR ... ])
  24. # get_subdir_var_files (VARIABLE VAR_NAME DIR [ DIR ... ])
  25. # install_module_symlink (MODULE [ MODULE ... ])
  26. if(NOT DEFINED _GMT_HELPER_MACROS_CMAKE_)
  27. set(_GMT_HELPER_MACROS_CMAKE_ "DEFINED")
  28. # tag_from_current_source_dir (TAG [PREFIX])
  29. # example: tag_from_current_source_dir (_tag "_")
  30. macro (TAG_FROM_CURRENT_SOURCE_DIR _TAG)
  31. get_filename_component (_basename ${CMAKE_CURRENT_SOURCE_DIR} NAME_WE)
  32. string(COMPARE NOTEQUAL "${_basename}" "src" _in_subtree)
  33. set (${_TAG})
  34. if (_in_subtree)
  35. set (${_TAG} "${ARGN}${_basename}")
  36. endif (_in_subtree)
  37. endmacro (TAG_FROM_CURRENT_SOURCE_DIR)
  38. # add_depend_to_target (TARGET DEPEND [ DEPEND [ DEPEND ... ]])
  39. # example: add_depend_to_target (main_target custom_target)
  40. macro (ADD_DEPEND_TO_TARGET _TARGET)
  41. if(NOT TARGET ${_TARGET})
  42. add_custom_target (${_TARGET}
  43. WORKING_DIRECTORY ${GMT_BINARY_DIR})
  44. endif(NOT TARGET ${_TARGET})
  45. add_dependencies(${_TARGET} ${ARGN})
  46. endmacro (ADD_DEPEND_TO_TARGET)
  47. # add_file_to_cached_list (LIST [ FILE [ FILE ... ]])
  48. # if FILE is omitted then the list is cleared
  49. # if FILE is not absolute then it is assumed to be in CMAKE_CURRENT_SOURCE_DIR
  50. # example: add_file_to_cached_list (list file)
  51. macro (ADD_FILE_TO_CACHED_LIST _LIST)
  52. set (_files ${ARGN})
  53. if (_files)
  54. set (_files_abs)
  55. foreach (_file ${_files})
  56. if (_file MATCHES "^[^/]")
  57. # make absolute path
  58. file(RELATIVE_PATH _file / ${CMAKE_CURRENT_SOURCE_DIR}/${_file})
  59. endif ()
  60. list(APPEND _files_abs /${_file})
  61. endforeach (_file ${_files})
  62. # append to list
  63. set (${_LIST} ${${_LIST}} ${_files_abs}
  64. CACHE INTERNAL "Global list of files")
  65. else (_theList)
  66. # clear list
  67. set (${_LIST} "" CACHE INTERNAL "Global list of files cleared")
  68. endif (_files)
  69. endmacro (ADD_FILE_TO_CACHED_LIST)
  70. # get_subdir_var (VARIABLE VAR_NAME DIR [ DIR ... ])
  71. # example: get_subdir_var (SUB_TARGETS PROGS ${SUB_DIRS})
  72. macro (GET_SUBDIR_VAR VARIABLE VAR_NAME DIR_NAME)
  73. set (${VARIABLE}) # clear VARIABLE
  74. foreach (_dir ${DIR_NAME} ${ARGN})
  75. # get value of variable ${VAR_NAME} in dir ${_dir}:
  76. get_directory_property (_value DIRECTORY ${_dir} DEFINITION ${VAR_NAME})
  77. list (APPEND ${VARIABLE} "${_value}")
  78. endforeach(_dir)
  79. endmacro (GET_SUBDIR_VAR VARIABLE VAR_NAME DIR_NAME)
  80. # get_subdir_var_files (VARIABLE VAR_NAME DIR [ DIR ... ])
  81. # example: get_subdir_var_files (SUB_LIB_SRCS LIB_SRCS ${SUB_DIRS})
  82. macro (GET_SUBDIR_VAR_FILES VARIABLE VAR_NAME DIR_NAME)
  83. set (${VARIABLE}) # clear VARIABLE
  84. foreach (_dir ${DIR_NAME} ${ARGN})
  85. # get value of variable ${VAR_NAME} in dir ${_dir}:
  86. get_directory_property (_files DIRECTORY ${_dir} DEFINITION ${VAR_NAME})
  87. foreach (_file ${_files})
  88. # prepend dirname:
  89. list (APPEND ${VARIABLE} "${_dir}/${_file}")
  90. endforeach (_file)
  91. endforeach(_dir)
  92. endmacro (GET_SUBDIR_VAR_FILES VARIABLE VAR_NAME DIR_NAME)
  93. # install_module_symlink (MODULE [ MODULE ... ])
  94. # example: install_module_symlink (grdimage psxy)
  95. if (NOT DEFINED GMT_INSTALL_MODULE_LINKS)
  96. # If not defined or set to TRUE
  97. set (GMT_INSTALL_MODULE_LINKS TRUE)
  98. endif ()
  99. macro (INSTALL_MODULE_SYMLINK)
  100. if (WIN32 AND GMT_INSTALL_MODULE_LINKS)
  101. # create build targets
  102. foreach (_gmtmodule ${ARGV})
  103. add_executable (${_gmtmodule} ${GMT_PROGRAM})
  104. string (TOUPPER "${_gmtmodule}" UCASEname)
  105. set_target_properties (${_gmtmodule} PROPERTIES
  106. COMPILE_DEFINITIONS "MODULE=\"${_gmtmodule}\"")
  107. target_link_libraries (${_gmtmodule} gmtlib)
  108. endforeach (_gmtmodule)
  109. # add the install targets
  110. install (TARGETS ${ARGV}
  111. RUNTIME DESTINATION ${GMT_BINDIR}
  112. COMPONENT Runtime)
  113. # add to gmt_suppl target
  114. add_depend_to_target (gmt_module_progs ${ARGV})
  115. elseif (UNIX AND GMT_INSTALL_MODULE_LINKS)
  116. # create gmt module symlinks to gmt
  117. foreach (_gmtmodule ${ARGV})
  118. install (CODE "
  119. execute_process (COMMAND ${CMAKE_COMMAND} -E remove -f
  120. \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${GMT_BINDIR}/${_gmtmodule})
  121. execute_process (COMMAND ${CMAKE_COMMAND} -E create_symlink
  122. gmt${GMT_INSTALL_NAME_SUFFIX}
  123. \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${GMT_BINDIR}/${_gmtmodule})
  124. " COMPONENT Runtime)
  125. endforeach (_gmtmodule)
  126. endif (WIN32 AND GMT_INSTALL_MODULE_LINKS)
  127. endmacro (INSTALL_MODULE_SYMLINK)
  128. endif(NOT DEFINED _GMT_HELPER_MACROS_CMAKE_)
  129. # vim: textwidth=78 noexpandtab tabstop=2 softtabstop=2 shiftwidth=2
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...