forked from Slicer/Slicer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlicerConfigureDisplayableManagerObjectFactory.cmake
122 lines (107 loc) · 3.52 KB
/
SlicerConfigureDisplayableManagerObjectFactory.cmake
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
#
# Configure Slicer displayable manager VTK object factory
#
# Given a list of displayable manager source files, this function will
# generate sources responsible for registering the classes with the
# vtkObjectFactory.
#
# This function set the variable "${TARGET_NAME}_AUTOINIT" to 1 in the parent
# scope. This tells SlicerMacroBuildModuleLogic to set Slicer_EXPORT_HEADER_CUSTOM_CONTENT
# and define the associated ${TARGET_NAME}_AUTOINIT compilation flag.
#
function(SlicerConfigureDisplayableManagerObjectFactory)
set(options
NO_EXPORT
)
set(oneValueArgs
TARGET_NAME
EXPORT_MACRO
EXPORT_HEADER
OUTPUT_SRCS_VAR
)
set(multiValueArgs
SRCS
)
cmake_parse_arguments(DM_OBJECT_FACTORY
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
# Sanity checks
if(DM_OBJECT_FACTORY_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown keywords given to SlicerConfigureDisplayableManagerObjectFactory(): \"${DM_OBJECT_FACTORY_UNPARSED_ARGUMENTS}\"")
endif()
set(expected_nonempty_vars
TARGET_NAME
OUTPUT_SRCS_VAR
SRCS
)
if(NOT DM_OBJECT_FACTORY_NO_EXPORT)
list(APPEND expected_nonempty_vars
EXPORT_MACRO
EXPORT_HEADER
)
endif()
foreach(var ${expected_nonempty_vars})
if("${DM_OBJECT_FACTORY_${var}}" STREQUAL "")
message(FATAL_ERROR "error: ${var} CMake variable is empty !")
endif()
endforeach()
# Initialize local variables
set(_vtk_override_includes)
set(_vtk_override_creates )
# For each class
foreach(FILE ${DM_OBJECT_FACTORY_SRCS})
# what is the filename without the extension
get_filename_component(TMP_FILENAME ${FILE} NAME_WE)
set(_class ${TMP_FILENAME})
set(_override ${_class})
set(_vtk_override_includes
"${_vtk_override_includes}#include \"${_override}.h\"\n")
set(_vtk_override_creates "${_vtk_override_creates}
VTK_CREATE_CREATE_FUNCTION(${_override})")
set(_vtk_override_do "${_vtk_override_do}
this->RegisterOverride(\"${_class}\",
\"${_override}\",
\"Override for ${vtk-module} module\", 1,
vtkObjectFactoryCreate${_override});")
endforeach()
set(vtk-module ${DM_OBJECT_FACTORY_TARGET_NAME})
if(DM_OBJECT_FACTORY_NO_EXPORT)
string(TOUPPER ${DM_OBJECT_FACTORY_TARGET_NAME} VTK-MODULE)
set(_export_header "#define ${VTK-MODULE}_EXPORT")
else()
string(REPLACE "_EXPORT" "" VTK-MODULE "${DM_OBJECT_FACTORY_EXPORT_MACRO}")
set(_export_header "#include \"${DM_OBJECT_FACTORY_EXPORT_HEADER}\"")
endif()
set(CMAKE_CONFIGURABLE_FILE_CONTENT "
#ifndef __${vtk-module}Module_h
#define __${vtk-module}Module_h
${_export_header}
#endif
")
configure_file(
${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}Module.h
)
configure_file(
${Slicer_CMAKE_DIR}/vtkSlicerObjectFactory.h.in
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.h
)
configure_file(
${Slicer_CMAKE_DIR}/vtkSlicerObjectFactory.cxx.in
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.cxx
)
set_source_files_properties(
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.cxx
PROPERTIES GENERATED 1 WRAP_EXCLUDE 1 ABSTRACT 0
)
# add the source file to the source list
set(${DM_OBJECT_FACTORY_OUTPUT_SRCS_VAR}
${${DM_OBJECT_FACTORY_OUTPUT_SRCS_VAR}}
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.cxx
PARENT_SCOPE
)
set(${DM_OBJECT_FACTORY_TARGET_NAME}_AUTOINIT 1 PARENT_SCOPE)
endfunction()