forked from jrfonseca/drmingw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
171 lines (129 loc) · 5.12 KB
/
CMakeLists.txt
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
cmake_minimum_required (VERSION 3.16)
project (drmingw)
set (CPACK_PACKAGE_VERSION_MAJOR "0")
set (CPACK_PACKAGE_VERSION_MINOR "9")
set (CPACK_PACKAGE_VERSION_PATCH "4")
option (ENABLE_COVERAGE "Enable code coverage." OFF)
##############################################################################
# Dependencies
if (NOT MINGW OR CYGWIN)
message (FATAL_ERROR "MinGW toolchain required")
endif ()
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package (WinDbg)
include_directories (
${CMAKE_SOURCE_DIR}/thirdparty/elf
${CMAKE_SOURCE_DIR}/thirdparty/libiberty
)
add_subdirectory (thirdparty)
##############################################################################
# Set global build options
set (CMAKE_C_STANDARD 11)
set (CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_STANDARD 17)
set (CXX_STANDARD_REQUIRED ON)
include (CheckCXXCompilerFlag)
macro (add_compiler_flags)
string (REPLACE ";" " " _FLAGS "${ARGV}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_FLAGS}")
endmacro ()
macro (add_linker_flags)
string (REPLACE ";" " " _FLAGS "${ARGV}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_FLAGS}")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${_FLAGS}")
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${_FLAGS}")
endmacro ()
# Adjust warnings
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror=implicit-function-declaration -Werror=missing-prototypes")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
# Disable strict aliasing rules
add_compiler_flags (-fno-strict-aliasing)
include (StaticCRT)
# Avoid Posix threads
execute_process (
COMMAND "${CMAKE_COMMAND}" -E echo "#include <thread>\n#ifdef _GLIBCXX_HAS_GTHREADS\n#error _GLIBCXX_HAS_GTHREADS\n#endif"
COMMAND "${CMAKE_CXX_COMPILER}" -x c++ -E -
RESULT_VARIABLE STATUS_CXX11_THREADS
OUTPUT_QUIET
ERROR_QUIET
)
if (NOT STATUS_CXX11_THREADS EQUAL 0)
message (SEND_ERROR "Win32 threads recommended.")
endif ()
# Enable stack protection
# XXX: Broken on https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86832
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0" OR
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "8.3")
add_compiler_flags (-fstack-protector-all)
# MinGW doesn't link against libssp automatically, and furthermore
# we want static linking.
set (SSP_LIBRARY "-Wl,-Bstatic -lssp -Wl,-Bdynamic")
set (CMAKE_C_STANDARD_LIBRARIES "${SSP_LIBRARY} ${CMAKE_C_STANDARD_LIBRARIES}")
set (CMAKE_CXX_STANDARD_LIBRARIES "${SSP_LIBRARY} ${CMAKE_CXX_STANDARD_LIBRARIES}")
endif ()
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
add_definitions (-DHAVE_WIN64=1)
else ()
add_linker_flags (-Wl,--enable-stdcall-fixup)
add_definitions (-DHAVE_WIN64=0)
endif ()
# Put all executables into top-level bin subdirectory
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
add_definitions (
# minimum required OS version
-D_WIN32_WINNT=0x0601
-DWINVER=0x0601
# https://msdn.microsoft.com/en-gb/library/windows/desktop/ms683198.aspx
-DPSAPI_VERSION=1
# version
-DPACKAGE_VERSION_MAJOR=${CPACK_PACKAGE_VERSION_MAJOR}
-DPACKAGE_VERSION_MINOR=${CPACK_PACKAGE_VERSION_MINOR}
-DPACKAGE_VERSION_PATCH=${CPACK_PACKAGE_VERSION_PATCH}
)
# Macro to force using debug flags, regardless of the current build type
macro (force_debug)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS_DEBUG}")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
foreach (build_type DEBUG RELEASE MINSIZEREL RELWITHDEBINFO)
set (CMAKE_C_FLAGS_${build_type} "")
set (CMAKE_CXX_FLAGS_${build_type} "")
set (CMAKE_EXE_LINKER_FLAGS_${build_type} "")
set (CMAKE_MODULE_LINKER_FLAGS_${build_type} "")
set (CMAKE_SHARED_LINKER_FLAGS_${build_type} "")
endforeach ()
endmacro ()
##############################################################################
# Targets
enable_testing ()
add_custom_target (check
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
USES_TERMINAL
)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
install (FILES include/exchndl.h DESTINATION include)
set (MGWHELP_IMPLIB ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libmgwhelp.a)
set (EXCHNDL_IMPLIB ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libexchndl.a)
add_subdirectory (src)
add_subdirectory (sample)
add_subdirectory (tests)
##############################################################################
# Packaging
install (
FILES
LICENSE.txt
README.md
DESTINATION doc
)
# cpack mistakenly detects Mingw-w64 as win32
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set (CPACK_SYSTEM_NAME win64)
endif ()
set (CPACK_GENERATOR "7Z")
set (CPACK_STRIP_FILES ON)
include(CPack)