Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: CI-CMake

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

permissions:
contents: read
actions: read
security-events: write

jobs:
build:
strategy:
fail-fast: false
matrix:
# windows-2022 ships VS 2022 (17.x); windows-2025 ships VS 2026 (18.x)
# -- each runner image only has one VS version installed, so the
# generator must be paired with its matching os, not cross-produced.
toolset:
- { os: windows-2022, generator: "Visual Studio 17 2022" }
- { os: windows-2022, generator: "Ninja Multi-Config" }
- { os: windows-2025, generator: "Visual Studio 18 2026" }
- { os: windows-2025, generator: "Ninja Multi-Config" }
arch: [x86, x64]
config: [Debug, Release]

runs-on: ${{ matrix.toolset.os }}
steps:
- name: Clone Repository
uses: actions/checkout@v6

- name: Configure MSVC Compiler
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch }}

# Runs once, on the same job/matrix leg the old NMake-driven CI-Build
# workflow used (windows-2022, Debug) -- ported here since main.yml
# (and the NMake build it drove) has been removed.
- name: Initialize CodeQL for C++
uses: github/codeql-action/init@v4
if: ${{ matrix.toolset.os == 'windows-2022' && matrix.toolset.generator == 'Ninja Multi-Config' && matrix.arch == 'x64' && matrix.config == 'Debug' }}
with:
languages: cpp
config-file: ./.github/codeql/codeql-config.yml

- name: Configure
run: |
$platformArg = @()
if ('${{ matrix.toolset.generator }}' -ne 'Ninja Multi-Config') {
$platformArg = @('-A', '${{ matrix.arch == 'x86' && 'Win32' || 'x64' }}')
}
cmake -S . -B build -G '${{ matrix.toolset.generator }}' @platformArg -DDETOURS_BUILD_INTEGRATION_TESTS=ON -DDETOURS_BUILD_SAMPLES=ON

- name: Build
run: cmake --build build --config ${{ matrix.config }} --parallel

- name: Test
run: ctest --test-dir build -C ${{ matrix.config }} --output-on-failure

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
if: ${{ matrix.toolset.os == 'windows-2022' && matrix.toolset.generator == 'Ninja Multi-Config' && matrix.arch == 'x64' && matrix.config == 'Debug' }}

# Builds and runs on real ARM64 hardware (windows-11-arm) using cl.exe's
# /arm64EC switch. CFLAGS/CXXFLAGS force /arm64EC because only the Visual
# Studio generator's "-A ARM64EC" configures this automatically -- Ninja
# has no equivalent mechanism. See:
# https://devblogs.microsoft.com/cppblog/arm64ec-support-in-visual-studio/
test-arm64ec:
strategy:
fail-fast: false
matrix:
config: [Debug, Release]
runs-on: windows-11-arm
env:
# Also needed by Test: the find_package integration test spawns its own
# nested CMake configure via ctest, which must be forced to /arm64EC too.
CFLAGS: /arm64EC
CXXFLAGS: /arm64EC
steps:
- name: Clone Repository
uses: actions/checkout@v6

- name: Configure MSVC Compiler
uses: ilammy/msvc-dev-cmd@v1
with:
arch: arm64

- name: Configure
run: |
# vcvarsarm64.bat doesn't reliably put ml64.exe on PATH (it lives in a
# Host*\x64 tools dir that the arm64-hosted dev environment doesn't add),
# so CMake's default ASM_MASM search falls back to a nonexistent "ml.exe"
# and disas/x64.asm fails with "CreateProcess failed". Locate ml64.exe
# explicitly via vswhere and hand it to CMake instead.
$vsPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath
$ml64 = Get-ChildItem -Path "$vsPath\VC\Tools\MSVC" -Recurse -Filter ml64.exe -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
cmake -S . -B build -G "Ninja Multi-Config" -DDETOURS_BUILD_INTEGRATION_TESTS=ON -DDETOURS_BUILD_SAMPLES=ON -DCMAKE_ASM_MASM_COMPILER="$ml64"

- name: Build
run: cmake --build build --config ${{ matrix.config }} --parallel

- name: Test
run: ctest --test-dir build -C ${{ matrix.config }} --output-on-failure
74 changes: 0 additions & 74 deletions .github/workflows/main.yml

This file was deleted.

11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,12 @@ obj.*
*.user
*.recipe
/bin.*
*.vcxproj.FileListAbsolute.txt
*.vcxprojAssemblyReference.cache

# CMake
build*/
CMakeFiles/
CMakeCache.txt
CMakeUserPresets.json
cmake_install.cmake
CTestTestfile.cmake
install_manifest.txt
84 changes: 84 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
##############################################################################
##
## CMakeLists.txt for Detours.
##
## Microsoft Research Detours Package
##
## Copyright (c) Microsoft Corporation. All rights reserved.
##
## This is the sole build system for Detours, covering the full build/test/sample surface.
##

cmake_minimum_required(VERSION 3.28.3)

project(DETOURS
VERSION 4.0.1
DESCRIPTION "Detours is a software package for monitoring and instrumenting API calls on Windows."
HOMEPAGE_URL "https://github.com/microsoft/Detours"
LANGUAGES CXX
)

if(NOT WIN32)
message(FATAL_ERROR "Detours only targets Windows; see https://github.com/microsoft/Detours/wiki/FAQ")
endif()

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)

# CMake's MSVC Debug default injects /RTC1 (runtime checks), which actively conflicts with
# samples that need /Zl (no default CRT lib reference) or a non-default optimization level.
# Detours' own Debug behavior is controlled separately via the DETOUR_DEBUG=1 tracing macro,
# not compiler runtime checks.
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")

option(DETOURS_BUILD_TESTS "Build the Detours unit test suite" ${PROJECT_IS_TOP_LEVEL})
option(DETOURS_BUILD_SAMPLES "Build the Detours samples" OFF)
option(DETOURS_INSTALL "Generate install/export rules for the Detours package" ${PROJECT_IS_TOP_LEVEL})

add_library(detours STATIC)
add_library(Microsoft::detours ALIAS detours)
add_subdirectory(src)

if(DETOURS_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

if(DETOURS_BUILD_SAMPLES)
add_subdirectory(samples)
endif()

if(DETOURS_INSTALL)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

install(TARGETS detours
EXPORT DetoursTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(EXPORT DetoursTargets
FILE DetoursTargets.cmake
NAMESPACE Microsoft::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Detours
)

configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/DetoursConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/DetoursConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Detours
)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/DetoursConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/DetoursConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/DetoursConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Detours
)
endif()
63 changes: 0 additions & 63 deletions Makefile

This file was deleted.

5 changes: 5 additions & 0 deletions cmake/DetoursConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/DetoursTargets.cmake")

check_required_components(Detours)
Loading