forked from dlrdave/activizdotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildExamples.cmake
169 lines (140 loc) · 4.72 KB
/
BuildExamples.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
macro(ADD_EXTERNAL_CSHARP_PROJECT aecp_name aecp_dir aecp_sln aecp_target_cpu aecp_out aecp_out_dir aecp_dependencies aecp_sources aecp_dependent_dlls)
add_custom_command(
OUTPUT "${aecp_out_dir}/${aecp_out}"
DEPENDS ${aecp_dir}/${aecp_sln} ${aecp_sources} ${aecp_dependent_dlls}
WORKING_DIRECTORY ${aecp_dir}
COMMAND ${CMAKE_MAKE_PROGRAM}
ARGS "${aecp_sln}" /Build "\"${CMAKE_CFG_INTDIR}|${aecp_target_cpu}\""
)
add_custom_target(
"${aecp_name}" ALL
DEPENDS "${aecp_out_dir}/${aecp_out}"
)
add_dependencies("${aecp_name}" ${aecp_dependencies})
endmacro()
macro(MODIFY_CSPROJFILE mc_csprojfile)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy
"${mc_csprojfile}"
"${mc_csprojfile}.backup"
)
# Read in the .csproj file:
#
file(READ "${mc_csprojfile}" contents)
string(REGEX REPLACE ";" "\\\\;" contents "${contents}")
string(REGEX REPLACE "\n" "E;" contents "${contents}")
# Write a new empty file:
#
file(WRITE "${mc_csprojfile}.new" "")
# Scan for "<OutputPath>.*</OutputPath>" matches:
#
foreach(line ${contents})
if(line MATCHES "^(.*)<OutputPath>.*</OutputPath>(.*)E$")
string(REGEX REPLACE "^(.*)<OutputPath>.*</OutputPath>(.*)E$" "\\1<OutputPath>..\\\\..\\\\..\\\\bin\\\\$\(Configuration\)</OutputPath>\\2" newline "${line}")
else()
string(REGEX REPLACE "^(.*)E$" "\\1" newline "${line}")
endif()
# Append to the new file:
#
file(APPEND "${mc_csprojfile}.new" "${newline}\n")
endforeach()
# Copy the new one on top of the original input (in-place replacement)
# and then get rid of the new one:
#
execute_process(COMMAND ${CMAKE_COMMAND} -E copy
"${mc_csprojfile}.new"
"${mc_csprojfile}"
)
execute_process(COMMAND ${CMAKE_COMMAND} -E remove
"${mc_csprojfile}.new"
)
endmacro()
macro(ADD_EXAMPLE ae_name ae_dir ae_sln ae_output ae_sources)
# Copy the whole example directory given to its parallel in the build tree:
#
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory
"${ActiVizDotNet_BINARY_DIR}/Examples/${ae_dir}"
"${ActiVizDotNet_BINARY_DIR}/ExamplesBuild/${ae_dir}"
)
# ae_sources is a list of source files relative to
# "${ActiVizDotNet_BINARY_DIR}/ExamplesBuild/${ae_dir}"
#
# Create a list of full path sources.
#
set(ae_full_sources "")
foreach(s ${ae_sources})
set(ae_full_sources ${ae_full_sources} "${ActiVizDotNet_BINARY_DIR}/ExamplesBuild/${ae_dir}/${s}")
if(s MATCHES "\\.csproj$")
message(STATUS "Modifying .csproj file: '${ActiVizDotNet_BINARY_DIR}/ExamplesBuild/${ae_dir}/${s}'")
MODIFY_CSPROJFILE("${ActiVizDotNet_BINARY_DIR}/ExamplesBuild/${ae_dir}/${s}")
endif()
endforeach()
# Upgrade the project to the latest version of visual studio
#
execute_process(COMMAND
"${CMAKE_MAKE_PROGRAM}" "${ActiVizDotNet_BINARY_DIR}/ExamplesBuild/${ae_dir}/${ae_sln}" "/upgrade"
)
# Add a custom target that builds the example via its .sln file:
#
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ae_target_cpu "x64")
else()
set(ae_target_cpu "x86")
endif()
ADD_EXTERNAL_CSHARP_PROJECT(
"${ae_name}"
"${ActiVizDotNet_BINARY_DIR}/ExamplesBuild/${ae_dir}"
"${ae_sln}"
"${ae_target_cpu}"
"${ae_output}"
"${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}"
"Kitware.VTK"
"${ae_full_sources}"
"${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/Kitware.VTK.dll"
)
endmacro()
message(STATUS "info: '${CMAKE_CURRENT_LIST_FILE}' included...")
set(AVDN_BUILD_SLN_FILES OFF)
if(MSVC80 OR MSVC90)
message(STATUS "info: MSVC80 OR MSVC90")
set(AVDN_BUILD_SLN_FILES ON)
endif()
if(AVDN_BUILD_SLN_FILES)
# Force a clean build of "${ActiVizDotNet_BINARY_DIR}/ExamplesBuild"
# after every CMake configure for now:
#
file(REMOVE_RECURSE "${ActiVizDotNet_BINARY_DIR}/ExamplesBuild")
set(EXAMPLES
#"BoxWidget"
#"CubeAxes"
#"Decimate"
#"DelMesh"
#"Dialog"
"EventMonitor"
"FileTree"
#"HelloVTKConsole" # can't be built by loop below: different set of files
#"HelloVTKForm" # can't be built by loop below: different set of files
#"SpherePuzzle"
#"Streamline"
#"VolumeRendering"
#"Wikipedia"
)
# As happy good luck would have it, the source list for both of the uncommented
# examples that build here is exactly the same:
#
foreach(ex ${EXAMPLES})
set(s
"Form1.cs"
"Form1.Designer.cs"
"Form1.resx"
"Program.cs"
"Properties/AssemblyInfo.cs"
"Properties/Resources.Designer.cs"
"Properties/Resources.resx"
"Properties/Settings.Designer.cs"
"Properties/Settings.settings"
"${ex}.csproj"
"${ex}.sln"
)
ADD_EXAMPLE("Build.Examples.${ex}" "${ex}/CS" "${ex}.sln" "${ex}.exe" "${s}")
endforeach()
endif()