3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-06 01:24:08 +00:00

Add option 'MSVC_STATIC' (#6358)

* Add option 'MSVC_STATIC'

* Update CMakeLists.txt

* Update CMakeLists.txt

* Upload msvc-static-build.yml
This commit is contained in:
gmh5225 2022-09-23 04:55:40 +08:00 committed by GitHub
parent 00cf5ed4c7
commit b0d0c36b11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 0 deletions

20
.github/workflows/msvc-static-build.yml vendored Normal file
View file

@ -0,0 +1,20 @@
name: MSVC Static Build
on:
push:
pull_request:
jobs:
build:
runs-on: windows-2019
env:
BUILD_TYPE: Release
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Build
run: |
cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DZ3_BUILD_LIBZ3_SHARED=OFF -DZ3_BUILD_LIBZ3_MSVC_STATIC=ON
cmake --build build --config ${{ env.BUILD_TYPE }} --parallel

View file

@ -304,6 +304,7 @@ endif()
# Option to control what type of library we build # Option to control what type of library we build
################################################################################ ################################################################################
option(Z3_BUILD_LIBZ3_SHARED "Build libz3 as a shared library if true, otherwise build a static library" ON) option(Z3_BUILD_LIBZ3_SHARED "Build libz3 as a shared library if true, otherwise build a static library" ON)
option(Z3_BUILD_LIBZ3_MSVC_STATIC "Build libz3 as a statically-linked runtime library" OFF)
################################################################################ ################################################################################

View file

@ -115,6 +115,27 @@ if (Z3_BUILD_LIBZ3_SHARED)
else() else()
set(lib_type "STATIC") set(lib_type "STATIC")
endif() endif()
# Enable static msvc runtime.
if (MSVC AND Z3_BUILD_LIBZ3_MSVC_STATIC)
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELWITHDEBINFO
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
string(REPLACE "/MDd" "/MTd" ${CompilerFlag} "${${CompilerFlag}}")
set(${CompilerFlag} "${${CompilerFlag}}" CACHE STRING "msvc compiler flags" FORCE)
message("MSVC flags: ${CompilerFlag}:${${CompilerFlag}}")
endforeach()
endif(MSVC)
add_library(libz3 ${lib_type} ${object_files}) add_library(libz3 ${lib_type} ${object_files})
target_include_directories(libz3 INTERFACE target_include_directories(libz3 INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/api> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/api>