catalyst-macros.cmake
Go to the documentation of this file.
1 # Macros and other CMake code part of the Catalyst SDK i.e.
2 # API used to build Catalyst API implementations.
3 
4 #[==[
5 Mark a target as the Catalyst API implementation.
6 
7 ~~~{.cmake}
9  TARGET <target>
10  [LIBRARY_DESTINATION <destination>]
11  [INSTALL_EXPORT_DEFAULT]
12  )
13 ~~~
14 
15 The `TARGET` identifies the target added using an `add_library` call.
16 This function ensures that properties on the target are set up
17 appropriately so that the generated library is ABI compatible
18 with the Catalyst stub implementation.
19 
20 `LIBRARY_DESTINATION` if specified, is used to determine the install destination.
21 If not specified, no install rule is added.
22 
23 `INSTALL_EXPORT_DEFAULT` is useful in projects that include Catalyst as a
24 sub-project (instead of using it externally) to build Catalyst implementations.
25 For such projects, the Catalyst library is often built as a part of the project.
26 Providing INSTALL_EXPORT_DEFAULT ensures that the Catalyst implementation is
27 added as a part of the export set for the Catalyst targets so that
28 `find_package(catalyst ... )` can work seamlessly.
29 If `LIBRARY_DESTINATION` must be specified if `INSTALL_EXPORT_DEFAULT`
30 specified.
31 
32 
33 #]==]
35  cmake_parse_arguments(PARSE_ARGV 0 arg "INSTALL_EXPORT_DEFAULT" "TARGET;LIBRARY_DESTINATION" "")
36  if (arg_UNPARSED_ARGUMENT)
37  message(FATAL_ERROR
38  "Unknown argument(s) passed to 'catalyst_library': '${arg_UNPARSED_ARGUMENT}'")
39  endif()
40  if (arg_INSTALL_EXPORT_DEFAULT AND NOT (arg_TARGET STREQUAL "catalyst"))
41  message(WARNING
42  "Target not named 'catalyst'. find_package(catalyst .. ) may not work as "
43  "expected.")
44  endif()
45  if (arg_INSTALL_EXPORT_DEFAULT AND NOT DEFINED arg_LIBRARY_DESTINATION)
46  message(WARNING
47  "'INSTALL_EXPORT_DEFAULT' specified without 'LIBRARY_DESTINATION'."
48  "Argument has no effect.")
49  endif()
50 
51  target_link_libraries(${arg_TARGET}
52  PUBLIC
53  catalyst::core
54  catalyst::conduit_headers
55  PRIVATE
56  catalyst::conduit
57  catalyst::blueprint)
58  set_target_properties(${arg_TARGET}
59  PROPERTIES
60  VERSION "${CATALYST_ABI_VERSION}"
61  SOVERSION "${CATALYST_ABI_VERSION}"
62  OUTPUT_NAME "catalyst")
63 
64  set (_exports)
65  if (arg_INSTALL_EXPORT_DEFAULT)
66  set (_exports EXPORT Catalyst)
67  endif()
68  if (arg_LIBRARY_DESTINATION)
69  install(
70  TARGETS ${arg_TARGET}
71  ${_exports}
72  RUNTIME DESTINATION ${arg_LIBRARY_DESTINATION}
73  LIBRARY DESTINATION ${arg_LIBRARY_DESTINATION})
74  endif()
75 endfunction()
76 
77 #-------------------------------------------------------------
78 # internal macros
79 #-------------------------------------------------------------
80 macro (c_set_if_not_set variable)
81  if (NOT DEFINED "${variable}")
82  set("${variable}" ${ARGN})
83  endif()
84 endmacro()
85 
87  install(
88  TARGETS ${ARGN}
89  EXPORT Catalyst
90  ARCHIVE
91  DESTINATION "${CATALYST_INSTALL_ARCHIVE_DIR}"
92  LIBRARY
93  DESTINATION "${CATALYST_INSTALL_LIBRARY_DIR}"
94  RUNTIME
95  DESTINATION "${CATALYST_INSTALL_RUNTIME_DIR}")
96  foreach (arg IN LISTS ARGN)
97  get_property(type
98  TARGET ${arg}
99  PROPERTY TYPE)
100  # all static libraries are mangled using `catalyst_` prefix.
101  # we don't mangle shared libs since this project only builds the
102  # `catalyst` library as shared.
103  if (type STREQUAL STATIC_LIBRARY)
104  set_property(TARGET ${arg}
105  PROPERTY OUTPUT_NAME ${arg}${CATALYST_CUSTOM_LIBRARY_SUFFIX})
106  endif()
107  endforeach()
108 endfunction()
109 
110 function(c_install_headers)
111  cmake_parse_arguments(PARSE_ARGV 0 "arg" "" "SUBDIR" "HEADERS")
112  if (arg_UNPARSED_ARGUMENTS)
113  message(FATAL_ERROR
114  "unknown arguments passed to 'c_install_headers': '${arg_UNPARSED_ARGUMENTS}'")
115  endif()
116  install(
117  FILES ${arg_HEADERS}
118  DESTINATION "${CATALYST_INSTALL_INCLUDE_DIR}/${arg_SUBDIR}")
119 endfunction()
boost::graph_traits< vtkGraph *>::vertex_descriptor target(boost::graph_traits< vtkGraph *>::edge_descriptor e, vtkGraph *)
type
function catalyst_library()
Mark a target as the Catalyst API implementation.
on
macro c_set_if_not_set(variable)
EXPORT
function c_install_targets()
#define VERSION
Definition: jconfigint.h:17
function c_install_headers()