|
1 |
| -find_package(DotNetToolchain REQUIRED) |
| 1 | +find_package(Dotnet REQUIRED) |
2 | 2 |
|
3 | 3 | # Configure AssemblyInfo.cs
|
4 | 4 | set(VER_MAJOR "${Z3_VERSION_MAJOR}")
|
5 | 5 | set(VER_MINOR "${Z3_VERSION_MINOR}")
|
6 | 6 | set(VER_BUILD "${Z3_VERSION_PATCH}")
|
7 | 7 | set(VER_REVISION "${Z3_VERSION_TWEAK}")
|
8 |
| -set(Z3_DOTNET_ASSEMBLY_INFO_FILE "${CMAKE_CURRENT_BINARY_DIR}/Properties/AssemblyInfo.cs") |
9 |
| -configure_file("Properties/AssemblyInfo.cs.in" "${Z3_DOTNET_ASSEMBLY_INFO_FILE}" @ONLY) |
10 | 8 |
|
11 | 9 | # Generate Native.cs
|
12 | 10 | set(Z3_DOTNET_NATIVE_FILE "${CMAKE_CURRENT_BINARY_DIR}/Native.cs")
|
@@ -127,160 +125,64 @@ endforeach()
|
127 | 125 | list(APPEND Z3_DOTNET_ASSEMBLY_SOURCES
|
128 | 126 | "${Z3_DOTNET_CONST_FILE}"
|
129 | 127 | "${Z3_DOTNET_NATIVE_FILE}"
|
130 |
| - "${Z3_DOTNET_ASSEMBLY_INFO_FILE}" |
131 | 128 | )
|
132 | 129 |
|
133 |
| -# ``csc.exe`` doesn't like UNIX style paths so convert them |
134 |
| -# if necessary first to native paths. |
135 |
| -set(Z3_DOTNET_ASSEMBLY_SOURCES_NATIVE_PATH "") |
136 |
| -foreach (csfile_path ${Z3_DOTNET_ASSEMBLY_SOURCES}) |
137 |
| - file(TO_NATIVE_PATH "${csfile_path}" csfile_path_native) |
138 |
| - list(APPEND Z3_DOTNET_ASSEMBLY_SOURCES_NATIVE_PATH "${csfile_path_native}") |
139 |
| -endforeach() |
140 | 130 |
|
141 |
| -set(CSC_FLAGS "") |
142 |
| -if (DOTNET_TOOLCHAIN_IS_WINDOWS) |
143 |
| - # FIXME: Why use these flags? |
144 |
| - # Note these flags have been copied from the Python build system. |
145 |
| - list(APPEND CSC_FLAGS |
146 |
| - "/noconfig" |
147 |
| - "/nostdlib+" |
148 |
| - "/reference:mscorlib.dll" |
149 |
| - ) |
150 |
| -elseif (DOTNET_TOOLCHAIN_IS_MONO) |
151 |
| - # We need to give the assembly a strong name so that it can be installed |
152 |
| - # into the GAC. |
153 |
| - list(APPEND CSC_FLAGS |
154 |
| - "/keyfile:${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.Z3.snk" |
155 |
| - ) |
156 |
| -else() |
157 |
| - message(FATAL_ERROR "Unknown .NET toolchain") |
158 |
| -endif() |
159 |
| - |
160 |
| -# Common flags |
161 |
| -list(APPEND CSC_FLAGS |
162 |
| - "/unsafe+" |
163 |
| - "/nowarn:1701,1702" |
164 |
| - "/errorreport:prompt" |
165 |
| - "/warn:4" |
166 |
| - "/reference:System.Core.dll" |
167 |
| - "/reference:System.dll" |
168 |
| - "/reference:System.Numerics.dll" |
169 |
| - "/filealign:512" # Why? |
170 |
| - "/target:library" |
171 |
| -) |
| 131 | +# Generate <Compile Include="files.cs" /> items |
| 132 | +set(Z3_DOTNET_COMPILE_ITEMS "") |
| 133 | +foreach(csfile ${Z3_DOTNET_ASSEMBLY_SOURCES}) |
| 134 | + set(Z3_DOTNET_COMPILE_ITEMS "${Z3_DOTNET_COMPILE_ITEMS}\n <Compile Include=\"${csfile}\" />") |
| 135 | +endforeach() |
172 | 136 |
|
173 |
| -# Set the build type flags. The build type for the assembly roughly corresponds |
174 |
| -# with the native code build type. |
175 |
| -list(APPEND CSC_FLAGS |
176 |
| - # Debug flags, expands to nothing if we aren't doing a debug build |
177 |
| - "$<$<CONFIG:Debug>:/debug+>" |
178 |
| - "$<$<CONFIG:Debug>:/debug:full>" |
179 |
| - "$<$<CONFIG:Debug>:/optimize->" |
180 |
| - # This has to be quoted otherwise the ``;`` is interpreted as a command separator |
181 |
| - "$<$<CONFIG:Debug>:\"/define:DEBUG$<SEMICOLON>TRACE\">" |
182 |
| - # Release flags, expands to nothing if we are doing a debug build |
183 |
| - "$<$<NOT:$<CONFIG:Debug>>:/optimize+>" |
184 |
| -) |
185 | 137 |
|
186 |
| -# Mono's gacutil crashes when trying to install an assembly if we set the |
187 |
| -# platform in some cases, so only set it on Windows. This bug has been |
188 |
| -# reported at https://bugzilla.xamarin.com/show_bug.cgi?id=39955 . However mono |
189 |
| -# ignores the platform of an assembly when running it ( |
190 |
| -# http://lists.ximian.com/pipermail/mono-devel-list/2015-November/043370.html ) |
191 |
| -# so this shouldn't matter in practice. |
192 |
| -if (DOTNET_TOOLCHAIN_IS_WINDOWS) |
193 |
| - # Set platform for assembly |
194 |
| - if ("${TARGET_ARCHITECTURE}" STREQUAL "x86_64") |
195 |
| - list(APPEND CSC_FLAGS "/platform:x64") |
196 |
| - elseif ("${TARGET_ARCHITECTURE}" STREQUAL "i686") |
197 |
| - list(APPEND CSC_FLAGS "/platform:x86") |
198 |
| - endif() |
199 |
| -endif() |
| 138 | +# FindDotnet.cmake forwards CMake build type to MSBuild. |
| 139 | +# And thus we can put the conditional properties in the project file. |
| 140 | +# Note, nuget package file names do not have the ${VER_REV} part. |
200 | 141 |
|
201 |
| -# FIXME: Ideally we should emit files into a configuration specific directory |
202 |
| -# when using multi-configuration generators so that the files generated by each |
203 |
| -# configuration don't clobber each other. Unfortunately the ``get_property()`` |
204 |
| -# command only works correctly for single configuration generators so we can't |
205 |
| -# use it. We also can't use ``$<TARGET_FILE_DIR:libz3>`` because the ``OUTPUT`` |
206 |
| -# argument to ``add_custom_commands()`` won't accept it. |
207 |
| -# See http://public.kitware.com/pipermail/cmake/2016-March/063101.html |
208 |
| -# |
209 |
| -# For now just output file to the root binary directory like the Python build |
210 |
| -# system does and emit a warning when appropriate. |
211 |
| -if (DEFINED CMAKE_CONFIGURATION_TYPES) |
212 |
| - # Multi-configuration build (e.g. Visual Studio and Xcode). |
213 |
| - message(WARNING "You are using a multi-configuration generator. The build rules for" |
214 |
| - " the \".NET\" bindings currently do not emit files per configuration so previously" |
215 |
| - " generated files for other configurations will be overwritten.") |
| 142 | +set(Z3_DOTNET_NUPKG_VERSION "${VER_MAJOR}.${VER_MINOR}.${VER_BUILD}") |
| 143 | +if("${TARGET_ARCHITECTURE}" STREQUAL "i686") |
| 144 | + set(Z3_DOTNET_PLATFORM "x86") |
| 145 | +else() |
| 146 | + set(Z3_DOTNET_PLATFORM "AnyCPU") |
216 | 147 | endif()
|
217 | 148 |
|
218 |
| -set(Z3_DOTNET_ASSEMBLY_OUTPUT_DIR "${CMAKE_BINARY_DIR}") |
219 |
| -set(Z3_DOTNET_ASSEMBLY_NAME "Microsoft.Z3.dll") |
220 |
| -set(Z3_DOTNET_ASSEMBLY_DLL "${Z3_DOTNET_ASSEMBLY_OUTPUT_DIR}/${Z3_DOTNET_ASSEMBLY_NAME}") |
221 |
| -# csc.exe doesn't work with UNIX style paths so convert to native path |
222 |
| -file(TO_NATIVE_PATH "${Z3_DOTNET_ASSEMBLY_DLL}" Z3_DOTNET_ASSEMBLY_DLL_NATIVE_PATH) |
223 |
| -set(Z3_DOTNET_ASSEMBLY_DLL_DOC "${Z3_DOTNET_ASSEMBLY_OUTPUT_DIR}/Microsoft.Z3.xml") |
224 |
| -file(TO_NATIVE_PATH "${Z3_DOTNET_ASSEMBLY_DLL_DOC}" Z3_DOTNET_ASSEMBLY_DLL_DOC_NATIVE_PATH) |
225 |
| -add_custom_command(OUTPUT "${Z3_DOTNET_ASSEMBLY_DLL}" "${Z3_DOTNET_ASSEMBLY_DLL_DOC}" |
226 |
| - COMMAND |
227 |
| - "${DOTNET_CSC_EXECUTABLE}" |
228 |
| - ${CSC_FLAGS} |
229 |
| - "/out:${Z3_DOTNET_ASSEMBLY_DLL_NATIVE_PATH}" |
230 |
| - "/doc:${Z3_DOTNET_ASSEMBLY_DLL_DOC_NATIVE_PATH}" |
231 |
| - ${Z3_DOTNET_ASSEMBLY_SOURCES_NATIVE_PATH} |
232 |
| - DEPENDS |
233 |
| - ${Z3_DOTNET_ASSEMBLY_SOURCES} |
234 |
| - libz3 |
235 |
| - WORKING_DIRECTORY "${Z3_DOTNET_ASSEMBLY_OUTPUT_DIR}" |
236 |
| - COMMENT "Building \"${Z3_DOTNET_ASSEMBLY_DLL}\"" |
237 |
| -) |
| 149 | +# TODO conditional for signing. we can then enable the ``Release_delaysign`` configuration |
| 150 | + |
| 151 | +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.Z3.csproj.in ${CMAKE_CURRENT_BINARY_DIR}/build/Microsoft.Z3.csproj) |
| 152 | +ADD_DOTNET(${CMAKE_CURRENT_BINARY_DIR}/build/Microsoft.Z3.csproj |
| 153 | + VERSION ${Z3_DOTNET_NUPKG_VERSION} |
| 154 | + PLATFORM ${Z3_DOTNET_PLATFORM} |
| 155 | + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.Z3.csproj.in |
| 156 | + ${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.Z3.props |
| 157 | + ${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.Z3.targets |
| 158 | + ${Z3_DOTNET_ASSEMBLY_SOURCES} |
| 159 | + PACKAGE Microsoft.Z3 |
| 160 | + PACK_ARGUMENTS "/p:_DN_CMAKE_CONFIG=$<CONFIG>" |
| 161 | + ) |
| 162 | +add_dependencies(BUILD_Microsoft.Z3 libz3) |
238 | 163 |
|
239 | 164 | # Convenient top-level target
|
240 |
| -add_custom_target(build_z3_dotnet_bindings |
241 |
| - ALL |
242 |
| - DEPENDS |
243 |
| - "${Z3_DOTNET_ASSEMBLY_DLL}" |
244 |
| -) |
| 165 | +add_custom_target(build_z3_dotnet_bindings ALL DEPENDS BUILD_Microsoft.Z3) |
| 166 | + |
| 167 | +# Register the local nupkg repo |
| 168 | +set(Z3_DOTNET_LOCALREPO_NAME "Microsoft Z3 Local Repository") |
| 169 | +DOTNET_REGISTER_LOCAL_REPOSITORY(${Z3_DOTNET_LOCALREPO_NAME} ${CMAKE_BINARY_DIR}) |
245 | 170 |
|
246 | 171 | ###############################################################################
|
247 |
| -# Install |
| 172 | +# Install: register a local nuget repo and install our package. |
| 173 | +# the build step depends on the 'purge' target, making sure that |
| 174 | +# a user will always restore the freshly-built package. |
248 | 175 | ###############################################################################
|
249 | 176 | option(INSTALL_DOTNET_BINDINGS "Install .NET bindings when invoking install target" ON)
|
250 |
| -set(GAC_PKG_NAME "Microsoft.Z3.Sharp") |
251 |
| -set(PREFIX "${CMAKE_INSTALL_PREFIX}") |
252 |
| -set(VERSION "${Z3_VERSION}") |
253 |
| -set(Z3_DOTNET_PKGCONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/Microsoft.Z3.Sharp.pc") |
254 |
| -configure_file("Microsoft.Z3.Sharp.pc.in" "${Z3_DOTNET_PKGCONFIG_FILE}" @ONLY) |
255 |
| - |
256 |
| -if (DOTNET_TOOLCHAIN_IS_MONO) |
257 |
| - message(STATUS "Emitting install rules for .NET bindings") |
258 |
| - # Install pkgconfig file for the assembly. This is needed by Monodevelop |
259 |
| - # to find the assembly |
260 |
| - install(FILES "${Z3_DOTNET_PKGCONFIG_FILE}" DESTINATION "${CMAKE_INSTALL_PKGCONFIGDIR}") |
261 | 177 |
|
262 |
| - # Configure the install and uninstall scripts. |
263 |
| - # Note: If multi-configuration generator support is ever fixed then these |
264 |
| - # scripts will be broken. |
265 |
| - configure_file(cmake_install_gac.cmake.in cmake_install_gac.cmake @ONLY) |
266 |
| - configure_file(cmake_uninstall_gac.cmake.in cmake_uninstall_gac.cmake @ONLY) |
267 |
| - |
268 |
| - # Tell CMake to Invoke a script to install assembly to the GAC during install |
269 |
| - install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/cmake_install_gac.cmake") |
270 |
| - |
271 |
| - # Add custom target to uninstall the assembly from the GAC |
272 |
| - add_custom_target(remove_dotnet_dll_from_gac |
273 |
| - COMMAND "${CMAKE_COMMAND}" "-P" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall_gac.cmake" |
274 |
| - COMMENT "Uninstalling ${Z3_DOTNET_ASSEMBLY_NAME} from the GAC" |
275 |
| - ${ADD_CUSTOM_COMMAND_USES_TERMINAL_ARG} |
276 |
| - ) |
277 |
| - add_dependencies(uninstall remove_dotnet_dll_from_gac) |
278 |
| - |
279 |
| -elseif(DOTNET_TOOLCHAIN_IS_WINDOWS) |
280 |
| - # Don't install Z3_DOTNET_ASSEMBLY_DLL into the gac. Instead just copy into |
281 |
| - # installation directory. |
282 |
| - install(FILES "${Z3_DOTNET_ASSEMBLY_DLL}" DESTINATION "${CMAKE_INSTALL_LIBDIR}") |
283 |
| - install(FILES "${Z3_DOTNET_ASSEMBLY_DLL_DOC}" DESTINATION "${CMAKE_INSTALL_LIBDIR}") |
284 |
| -else() |
285 |
| - message(FATAL_ERROR "Unknown .NET toolchain") |
| 178 | +if(INSTALL_DOTNET_BINDINGS) |
| 179 | + install(FILES "${CMAKE_BINARY_DIR}/Microsoft.Z3/Microsoft.Z3.${Z3_DOTNET_NUPKG_VERSION}.nupkg" DESTINATION "${CMAKE_INSTALL_LIBDIR}/z3.nuget") |
| 180 | + # move the local repo to the installation directory (cancel the build-time repo) |
| 181 | + install(CODE "include(${CMAKE_CURRENT_LIST_DIR}/../../../cmake/modules/FindDotnet.cmake)\n DOTNET_REGISTER_LOCAL_REPOSITORY(\"${Z3_DOTNET_LOCALREPO_NAME}\" ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/z3.nuget)") |
| 182 | + install(FILES "${CMAKE_BINARY_DIR}/Microsoft.Z3/Microsoft.Z3.xml" DESTINATION "${CMAKE_INSTALL_LIBDIR}/z3.nuget") |
| 183 | +# TODO GAC? |
| 184 | +# set(GAC_PKG_NAME "Microsoft.Z3.Sharp") |
| 185 | +# set(PREFIX "${CMAKE_INSTALL_PREFIX}") |
| 186 | +# set(VERSION "${Z3_VERSION}") |
286 | 187 | endif()
|
| 188 | + |
0 commit comments