From 7f05974956be22e9ae06f6918c28f0e81bcaf1d3 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Sun, 3 Jul 2022 20:26:04 -0400 Subject: [PATCH] build: ensure `zydis` statically links when we want it to (#1599) * build: ensure `zydis` statically links when we want it to * test * test-static * revert the static test commit * build: don't generate cmake twice on release builds --- .github/workflows/linux-workflow.yaml | 2 +- .github/workflows/windows-workflow.yaml | 2 +- CMakeLists.txt | 11 ++++++----- CMakePresets.json | 7 +++++-- third-party/zydis/CMakeLists.txt | 1 + 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/linux-workflow.yaml b/.github/workflows/linux-workflow.yaml index 1408986643..08bf125694 100644 --- a/.github/workflows/linux-workflow.yaml +++ b/.github/workflows/linux-workflow.yaml @@ -49,7 +49,7 @@ jobs: # TODO - CMake - replace with presets! - name: CMake Generation - Clang - ASAN - if: matrix.compiler == 'clang' + if: matrix.compiler == 'clang' && startsWith(github.ref, 'refs/tags/') == false env: CC: clang CXX: clang++ diff --git a/.github/workflows/windows-workflow.yaml b/.github/workflows/windows-workflow.yaml index 9a9fdb0a6c..8582c0c375 100644 --- a/.github/workflows/windows-workflow.yaml +++ b/.github/workflows/windows-workflow.yaml @@ -53,7 +53,7 @@ jobs: - name: CMake Generation - Clang shell: cmd - if: matrix.compiler == 'clang' + if: matrix.compiler == 'clang' && startsWith(github.ref, 'refs/tags/') == false run: cmake -B build --preset=Release-clang -DCMAKE_C_COMPILER_LAUNCHER=${{ github.workspace }}/buildcache/bin/buildcache.exe -DCMAKE_CXX_COMPILER_LAUNCHER=${{ github.workspace }}/buildcache/bin/buildcache.exe . - name: CMake Generation - Clang - Statically Linked diff --git a/CMakeLists.txt b/CMakeLists.txt index da4f6b8b01..7a54ca9640 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,9 +15,8 @@ endif() # Potentially statically build the project option(STATICALLY_LINK "Build for release purposes (statically link everything)" OFF) - +message(STATUS "Statically Link? ${STATICALLY_LINK}") if(STATICALLY_LINK) - message(STATUS "Statically linking project") set(BUILD_SHARED_LIBS OFF) else() set(BUILD_SHARED_LIBS ON) @@ -206,10 +205,12 @@ add_subdirectory(third-party/discord-rpc EXCLUDE_FROM_ALL) option(ZYDIS_BUILD_TOOLS "Zydis: Build tools" OFF) option(ZYDIS_BUILD_EXAMPLES "Zydis: Build examples" OFF) -if(BUILD_SHARED_LIBS) - option(ZYDIS_BUILD_SHARED_LIB "Zydis: Build shared library" ON) -else() +if(STATICALLY_LINK) + message(STATUS "Statically linking zydis") option(ZYDIS_BUILD_SHARED_LIB "Zydis: Build shared library" OFF) +else() + message(STATUS "dynamically linking zydis") + option(ZYDIS_BUILD_SHARED_LIB "Zydis: Build shared library" ON) endif() add_subdirectory(third-party/zydis EXCLUDE_FROM_ALL) diff --git a/CMakePresets.json b/CMakePresets.json index bb0365cf60..c195ee918e 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -12,7 +12,9 @@ "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", "INSTALL_GTEST": "True", - "ASAN_BUILD": "OFF" + "ASAN_BUILD": "OFF", + "STATICALLY_LINK": "OFF", + "ZYDIS_BUILD_SHARED_LIB": "ON" } }, { @@ -82,7 +84,8 @@ "description": "Build with Clang as Release but statically linked", "inherits": ["base-release", "base-clang"], "cacheVariables": { - "STATICALLY_LINK": "true" + "STATICALLY_LINK": "true", + "ZYDIS_BUILD_SHARED_LIB": "OFF" } }, { diff --git a/third-party/zydis/CMakeLists.txt b/third-party/zydis/CMakeLists.txt index db33f4ee7a..b3949b79cd 100644 --- a/third-party/zydis/CMakeLists.txt +++ b/third-party/zydis/CMakeLists.txt @@ -97,6 +97,7 @@ endif () # Library configuration # # =============================================================================================== # +message(STATUS "zydis: dynamically link? ${ZYDIS_BUILD_SHARED_LIB}") if (ZYDIS_BUILD_SHARED_LIB) add_library("Zydis" SHARED) else ()