forked from KindDragon/vld
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
109 lines (92 loc) · 4.05 KB
/
CMakeLists.txt
File metadata and controls
109 lines (92 loc) · 4.05 KB
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
cmake_minimum_required(VERSION 3.16)
# Read version from version.txt (single source of truth)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" VLD_VERSION_RAW)
string(STRIP "${VLD_VERSION_RAW}" VLD_VERSION_STRING)
project(VLD
VERSION ${VLD_VERSION_STRING}
DESCRIPTION "Visual Leak Detector for Visual C++"
LANGUAGES CXX C
)
# Generate version.h from version.txt
set(VLD_VERSION_COMMA "${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},0")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/setup/version.h.in"
"${CMAKE_CURRENT_SOURCE_DIR}/setup/version.h"
@ONLY
)
# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Option to enable/disable MFC support
option(VLD_USE_MFC "Build with MFC support (includes MFC test projects)" OFF)
# Configure output directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Per-configuration output directories
foreach(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${CONFIG_TYPE} CONFIG_TYPE_UPPER)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_TYPE_UPPER} ${CMAKE_BINARY_DIR}/lib/${CONFIG_TYPE})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONFIG_TYPE_UPPER} ${CMAKE_BINARY_DIR}/bin/${CONFIG_TYPE})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFIG_TYPE_UPPER} ${CMAKE_BINARY_DIR}/bin/${CONFIG_TYPE})
endforeach()
# Platform detection
# Use CMAKE_VS_PLATFORM_NAME for reliable ARM64 detection in Visual Studio generator
# NOTE: This requires Visual Studio generators. For other generators (Ninja, NMake, etc.),
# you would need to detect platform using CMAKE_SYSTEM_PROCESSOR and CMAKE_SIZEOF_VOID_P:
# - Check CMAKE_SYSTEM_PROCESSOR for "ARM64" or "aarch64"
# - Fall back to CMAKE_SIZEOF_VOID_P to distinguish x64 (8 bytes) from Win32 (4 bytes)
if(DEFINED CMAKE_VS_PLATFORM_NAME)
if(CMAKE_VS_PLATFORM_NAME STREQUAL "ARM64")
set(VLD_PLATFORM "ARM64")
set(VLD_PLATFORM_DEFINE "WIN64")
elseif(CMAKE_VS_PLATFORM_NAME STREQUAL "x64")
set(VLD_PLATFORM "x64")
set(VLD_PLATFORM_DEFINE "WIN64")
else()
set(VLD_PLATFORM "Win32")
set(VLD_PLATFORM_DEFINE "WIN32")
endif()
else()
message(FATAL_ERROR "VLD requires Visual Studio generator. CMAKE_VS_PLATFORM_NAME is not defined.")
endif()
# MSVC specific settings
if(MSVC)
# Default to DLL runtime for tests (they need it for GetProcAddress tests)
# VLD core library overrides this to use static runtime
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
# Common compile options - use highest warning level and treat warnings as errors
add_compile_options(/W4 /WX)
add_link_options(/WX)
add_compile_definitions(
_CRT_SECURE_NO_WARNINGS
_VARIADIC_MAX=10
$<$<CONFIG:Debug>:_DEBUG>
$<$<NOT:$<CONFIG:Debug>>:NDEBUG>
)
endif()
# Status messages
message(STATUS "Configuring Visual Leak Detector v${PROJECT_VERSION}")
message(STATUS "Platform: ${VLD_PLATFORM}")
message(STATUS "MFC Support: ${VLD_USE_MFC}")
# Enable testing
enable_testing()
# Google Test configuration - use DLL runtime to match tests
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
# Add subdirectories
add_subdirectory(lib/gtest)
add_subdirectory(lib/cppformat)
add_subdirectory(src)
add_subdirectory(src/tests)
# Third-party libraries: don't treat warnings as errors and use static runtime
if(MSVC)
target_compile_options(fmt PRIVATE /W3 /WX-)
set_property(TARGET fmt PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
# IDE folder organization
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_target_properties(gtest PROPERTIES FOLDER "Libraries")
set_target_properties(fmt PROPERTIES FOLDER "Libraries")
set_target_properties(vld PROPERTIES FOLDER "VLD")