Skip to content

Commit 84c20cd

Browse files
committed
Add Windows support in CMake build
1 parent ec2263a commit 84c20cd

File tree

187 files changed

+76609
-487
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+76609
-487
lines changed

CMakeLists.txt

+114-44
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.22)
1+
cmake_minimum_required(VERSION 3.23)
22

33
message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
44

@@ -8,6 +8,7 @@ cmake_policy(SET CMP0095 NEW)
88
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
99

1010
include(utils)
11+
1112
calculate_xray_build_id(XRAY_BUILD_ID)
1213

1314
project(OpenXRay
@@ -18,6 +19,23 @@ project(OpenXRay
1819
LANGUAGES CXX C
1920
)
2021

22+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
23+
set(OS_LINUX TRUE)
24+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
25+
set(OS_MACOS TRUE)
26+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
27+
set(OS_WINDOWS TRUE)
28+
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
29+
set(OS_BSD TRUE)
30+
else()
31+
message(FATAL_ERROR "Unsupported CMAKE_SYSTEM_NAME \"${CMAKE_SYSTEM_NAME}\"")
32+
endif()
33+
34+
if(OS_WINDOWS)
35+
# Set it this way so cmake/windows will be used first
36+
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/windows;${CMAKE_MODULE_PATH}")
37+
endif()
38+
2139
message(STATUS "CMAKE_PROJECT_VERSION: ${CMAKE_PROJECT_VERSION}")
2240

2341
set(CMAKE_CXX_STANDARD 17)
@@ -149,11 +167,18 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT XRAY_USE_DEFAULT_CXX_LIB)
149167
endif()
150168
endif()
151169

152-
add_compile_options(-Wno-attributes)
153-
if (APPLE)
154-
add_compile_options(-Wl,-undefined,error)
155-
else()
156-
add_compile_options(-Wl,--no-undefined)
170+
if (NOT OS_WINDOWS)
171+
add_compile_options(-Wno-attributes)
172+
if (APPLE)
173+
add_compile_options(-Wl,-undefined,error)
174+
else()
175+
add_compile_options(-Wl,--no-undefined)
176+
endif()
177+
endif()
178+
179+
if (MASTER_GOLD AND OS_WINDOWS)
180+
add_compile_definitions(_HAS_EXCEPTIONS=0)
181+
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
157182
endif()
158183

159184
# TODO test
@@ -206,10 +231,12 @@ elseif (PROJECT_PLATFORM_PPC)
206231
)
207232
add_compile_definitions(NO_WARN_X86_INTRINSICS)
208233
else()
209-
add_compile_options(
210-
-mfpmath=sse
211-
-msse3
212-
)
234+
if (NOT OS_WINDOWS)
235+
add_compile_options(
236+
-mfpmath=sse
237+
-msse3
238+
)
239+
endif()
213240
endif()
214241

215242
if (XRAY_LINKER)
@@ -221,15 +248,45 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
221248
DEBUG
222249
MIXED
223250
)
224-
add_compile_options(-Og)
251+
252+
if(NOT OS_WINDOWS)
253+
add_compile_options(-Og)
254+
endif()
225255
endif()
226256

227257
add_compile_definitions(
228258
_MT
229259
_CPPUNWIND
230260
)
231261

232-
if (NOT WIN32)
262+
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
263+
set(ARCH_TYPE x64)
264+
else (CMAKE_SIZEOF_VOID_P EQUAL 4)
265+
set(ARCH_TYPE x86)
266+
endif()
267+
268+
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/sdk")
269+
list(APPEND CMAKE_LIBRARY_PATH "${CMAKE_SOURCE_DIR}/sdk/libraries/${ARCH_TYPE}")
270+
271+
# TODO move
272+
if(OS_WINDOWS)
273+
set(SDL2_DIR "${CMAKE_SOURCE_DIR}/sdk/cmake")
274+
endif()
275+
276+
find_package(SDL2 REQUIRED CONFIG)
277+
find_package(mimalloc)
278+
279+
if(NOT TARGET mimalloc::mimalloc)
280+
add_library(mimalloc::mimalloc ALIAS mimalloc)
281+
endif()
282+
283+
if (OS_WINDOWS)
284+
find_package(DbgHelp)
285+
find_package(DXSDK)
286+
find_package(EAX)
287+
find_package(FaultRep)
288+
find_package(JPEG)
289+
else()
233290
find_package(SDL2 2.0.18 REQUIRED)
234291
# Fix to support older SDL2
235292
# https://github.com/OpenXRay/xray-16/issues/1595
@@ -241,15 +298,22 @@ if (NOT WIN32)
241298
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
242299
)
243300
endif()
244-
find_package(OpenAL REQUIRED)
301+
302+
find_package(OpenGL REQUIRED)
303+
find_package(GLEW REQUIRED)
245304
find_package(JPEG)
246-
find_package(Ogg REQUIRED)
247-
find_package(Vorbis REQUIRED)
248-
find_package(Theora REQUIRED)
249-
find_package(LZO REQUIRED)
250-
find_package(mimalloc NAMES mimalloc2 mimalloc2.0 mimalloc)
251305
endif()
252306

307+
find_package(Ogg REQUIRED)
308+
find_package(OpenAL)
309+
find_package(LZO REQUIRED)
310+
find_package(Theora REQUIRED)
311+
find_package(Vorbis REQUIRED)
312+
313+
option(XRAY_USE_LUAJIT "Use LuaJIT" ON)
314+
315+
add_subdirectory(Externals)
316+
253317
# Memory allocator option
254318
if (mimalloc_FOUND)
255319
set(MEMORY_ALLOCATOR "mimalloc" CACHE STRING "Use specific memory allocator (mimalloc/standard)")
@@ -258,38 +322,44 @@ else()
258322
endif()
259323
set_property(CACHE MEMORY_ALLOCATOR PROPERTY STRINGS "mimalloc" "standard")
260324

261-
if (MEMORY_ALLOCATOR STREQUAL "mimalloc" AND NOT mimalloc_FOUND)
325+
if (MEMORY_ALLOCATOR STREQUAL "mimalloc" AND NOT (mimalloc_FOUND OR TARGET mimalloc::mimalloc))
262326
message(FATAL_ERROR "mimalloc allocator requested but not found. Please, install mimalloc package or select standard allocator.")
263327
endif()
264328

265329
message("Using ${MEMORY_ALLOCATOR} memory allocator")
266330

267-
option(XRAY_USE_LUAJIT "Use LuaJIT" ON)
268-
269-
add_subdirectory(Externals)
331+
if (OS_WINDOWS)
332+
add_compile_options(
333+
/nologo
334+
)
270335

271-
add_compile_options(
272-
-Wall
273-
#-Werror
274-
-Wextra
275-
#-pedantic
276-
-Wno-unknown-pragmas
277-
-Wno-strict-aliasing
278-
-Wno-parentheses
279-
-Wno-unused-label
280-
-Wno-unused-parameter
281-
-Wno-switch
282-
#-Wno-padded
283-
#-Wno-c++98-compat
284-
#-Wno-c++98-compat-pedantic
285-
#-Wno-c++11-compat
286-
#-Wno-c++11-compat-pedantic
287-
#-Wno-c++14-compat
288-
#-Wno-c++14-compat-pedantic
289-
#-Wno-newline-eof
290-
$<$<CXX_COMPILER_ID:GNU>:$<$<COMPILE_LANGUAGE:CXX>:-Wno-class-memaccess>>
291-
$<$<CXX_COMPILER_ID:GNU>:$<$<COMPILE_LANGUAGE:CXX>:-Wno-interference-size>>
292-
)
336+
add_link_options(
337+
/nologo
338+
)
339+
else()
340+
add_compile_options(
341+
-Wall
342+
#-Werror
343+
-Wextra
344+
#-pedantic
345+
-Wno-unknown-pragmas
346+
-Wno-strict-aliasing
347+
-Wno-parentheses
348+
-Wno-unused-label
349+
-Wno-unused-parameter
350+
-Wno-switch
351+
#-Wno-padded
352+
#-Wno-c++98-compat
353+
#-Wno-c++98-compat-pedantic
354+
#-Wno-c++11-compat
355+
#-Wno-c++11-compat-pedantic
356+
#-Wno-c++14-compat
357+
#-Wno-c++14-compat-pedantic
358+
#-Wno-newline-eof
359+
$<$<CXX_COMPILER_ID:GNU>:$<$<COMPILE_LANGUAGE:CXX>:-Wno-class-memaccess>>
360+
$<$<CXX_COMPILER_ID:GNU>:$<$<COMPILE_LANGUAGE:CXX>:-Wno-interference-size>>
361+
)
362+
endif()
293363

294364
add_subdirectory(src)
295365
add_subdirectory(res)

Externals/BugTrap-proj/CMakeLists.txt

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
add_library(bugtrap_bugtrap SHARED)
2+
3+
add_library(BugTrap::BugTrap ALIAS bugtrap_bugtrap)
4+
5+
target_include_directories(bugtrap_bugtrap
6+
PRIVATE
7+
#../BugTrap/include
8+
../zlib
9+
../zlib/include
10+
../zlib/contrib/minizip
11+
"${CMAKE_BINARY_DIR}/Externals/zlib"
12+
)
13+
14+
target_compile_definitions(bugtrap_bugtrap
15+
PUBLIC
16+
_USRDLL
17+
BUGTRAP_EXPORTS
18+
WIN64
19+
_WINDOWS
20+
21+
)
22+
23+
target_link_libraries(bugtrap_bugtrap
24+
PRIVATE
25+
zlib::zlib
26+
ws2_32.lib
27+
comctl32.lib
28+
shlwapi.lib
29+
version.lib
30+
wininet.lib
31+
vfw32.lib
32+
)
33+
34+
target_link_options(bugtrap_bugtrap
35+
PRIVATE
36+
/DEF:../BugTrap/source/Client/BugTrap.def
37+
nothrownew.obj
38+
)
39+
40+
#TODO add unity build
41+
42+
target_sources(bugtrap_bugtrap
43+
PRIVATE
44+
../BugTrap/source/Client/AboutDlg.cpp
45+
../BugTrap/source/Client/AboutDlg.h
46+
../BugTrap/source/Client/AnimProgressBar.cpp
47+
../BugTrap/source/Client/AnimProgressBar.h
48+
../BugTrap/source/Client/Array.h
49+
../BugTrap/source/Client/AssemblyInfo.cpp
50+
../BugTrap/source/Client/BTAtlWindow.h
51+
../BugTrap/source/Client/BTMfcWindow.h
52+
../BugTrap/source/Client/BTTrace.h
53+
../BugTrap/source/Client/BaseStream.h
54+
../BugTrap/source/Client/Buffer.h
55+
../BugTrap/source/Client/BugTrap.cpp
56+
../BugTrap/source/Client/BugTrap.h
57+
../BugTrap/source/Client/BugTrapNet.cpp
58+
../BugTrap/source/Client/BugTrapNet.h
59+
../BugTrap/source/Client/BugTrapUI.cpp
60+
../BugTrap/source/Client/BugTrapUI.h
61+
../BugTrap/source/Client/BugTrapUtils.cpp
62+
../BugTrap/source/Client/BugTrapUtils.h
63+
../BugTrap/source/Client/CMapi.cpp
64+
../BugTrap/source/Client/CMapi.h
65+
../BugTrap/source/Client/ColHelper.cpp
66+
../BugTrap/source/Client/ColHelper.h
67+
../BugTrap/source/Client/DescribeErrorDlg.cpp
68+
../BugTrap/source/Client/DescribeErrorDlg.h
69+
../BugTrap/source/Client/Encoding.cpp
70+
../BugTrap/source/Client/Encoding.h
71+
../BugTrap/source/Client/EnumProcess.cpp
72+
../BugTrap/source/Client/EnumProcess.h
73+
../BugTrap/source/Client/FileStream.cpp
74+
../BugTrap/source/Client/FileStream.h
75+
../BugTrap/source/Client/Globals.cpp
76+
../BugTrap/source/Client/Globals.h
77+
../BugTrap/source/Client/Hash.h
78+
../BugTrap/source/Client/HexView.cpp
79+
../BugTrap/source/Client/HexView.h
80+
../BugTrap/source/Client/HyperLink.cpp
81+
../BugTrap/source/Client/HyperLink.h
82+
../BugTrap/source/Client/ImageView.cpp
83+
../BugTrap/source/Client/ImageView.h
84+
../BugTrap/source/Client/InMemLogFile.cpp
85+
../BugTrap/source/Client/InMemLogFile.h
86+
../BugTrap/source/Client/InputStream.cpp
87+
../BugTrap/source/Client/InputStream.h
88+
../BugTrap/source/Client/InterfacePtr.h
89+
../BugTrap/source/Client/LayoutManager.cpp
90+
../BugTrap/source/Client/LayoutManager.h
91+
../BugTrap/source/Client/LeakWatcher.h
92+
../BugTrap/source/Client/List.h
93+
../BugTrap/source/Client/LogFile.cpp
94+
../BugTrap/source/Client/LogFile.h
95+
../BugTrap/source/Client/LogLink.h
96+
../BugTrap/source/Client/LogStream.cpp
97+
../BugTrap/source/Client/LogStream.h
98+
../BugTrap/source/Client/MachineInfoDlg.cpp
99+
../BugTrap/source/Client/MachineInfoDlg.h
100+
../BugTrap/source/Client/MachineStateDlg.cpp
101+
../BugTrap/source/Client/MachineStateDlg.h
102+
../BugTrap/source/Client/MainDlg.cpp
103+
../BugTrap/source/Client/MainDlg.h
104+
../BugTrap/source/Client/MemStream.cpp
105+
../BugTrap/source/Client/MemStream.h
106+
../BugTrap/source/Client/ModuleImportTable.cpp
107+
../BugTrap/source/Client/ModuleImportTable.h
108+
../BugTrap/source/Client/NetThunks.cpp
109+
../BugTrap/source/Client/NetThunks.h
110+
../BugTrap/source/Client/OutputStream.cpp
111+
../BugTrap/source/Client/OutputStream.h
112+
../BugTrap/source/Client/PreviewDlg.cpp
113+
../BugTrap/source/Client/PreviewDlg.h
114+
../BugTrap/source/Client/ResManager.cpp
115+
../BugTrap/source/Client/ResManager.h
116+
../BugTrap/source/Client/SendMailDlg.cpp
117+
../BugTrap/source/Client/SendMailDlg.h
118+
../BugTrap/source/Client/SimpleDlg.cpp
119+
../BugTrap/source/Client/SimpleDlg.h
120+
../BugTrap/source/Client/SmartPtr.h
121+
../BugTrap/source/Client/Splitter.cpp
122+
../BugTrap/source/Client/Splitter.h
123+
../BugTrap/source/Client/StrHolder.cpp
124+
../BugTrap/source/Client/StrHolder.h
125+
../BugTrap/source/Client/StrStream.cpp
126+
../BugTrap/source/Client/StrStream.h
127+
../BugTrap/source/Client/Stream.h
128+
../BugTrap/source/Client/SymEngine.cpp
129+
../BugTrap/source/Client/SymEngine.h
130+
../BugTrap/source/Client/SymEngineNet.cpp
131+
../BugTrap/source/Client/SymEngineNet.h
132+
../BugTrap/source/Client/TextFormat.cpp
133+
../BugTrap/source/Client/TextFormat.h
134+
../BugTrap/source/Client/TextLogFile.cpp
135+
../BugTrap/source/Client/TextLogFile.h
136+
../BugTrap/source/Client/TextView.cpp
137+
../BugTrap/source/Client/TextView.h
138+
../BugTrap/source/Client/ThemeXP.cpp
139+
../BugTrap/source/Client/ThemeXP.h
140+
../BugTrap/source/Client/TransferProgressDlg.cpp
141+
../BugTrap/source/Client/TransferProgressDlg.h
142+
../BugTrap/source/Client/VersionInfo.h
143+
../BugTrap/source/Client/VersionInfoString.h
144+
../BugTrap/source/Client/WaitCursor.cpp
145+
../BugTrap/source/Client/WaitCursor.h
146+
../BugTrap/source/Client/WaitDlg.cpp
147+
../BugTrap/source/Client/WaitDlg.h
148+
../BugTrap/source/Client/XmlLogFile.cpp
149+
../BugTrap/source/Client/XmlLogFile.h
150+
../BugTrap/source/Client/XmlReader.cpp
151+
../BugTrap/source/Client/XmlReader.h
152+
../BugTrap/source/Client/XmlWriter.cpp
153+
../BugTrap/source/Client/XmlWriter.h
154+
../BugTrap/source/Client/resource.h
155+
../BugTrap/source/Client/stdafx.cpp
156+
../BugTrap/source/Client/stdafx.h
157+
158+
../BugTrap/source/Client/res/Bug.ico
159+
../BugTrap/source/Client/res/CheckMark.bmp
160+
../BugTrap/source/Client/res/ImageToolbar.bmp
161+
../BugTrap/source/Client/res/SortArrows.bmp
162+
163+
../BugTrap/source/Client/BugTrap.def
164+
../BugTrap/source/Client/res/KeyPair.snk
165+
../BugTrap/source/Client/res/Upload.avi
166+
167+
../BugTrap/source/Client/BugTrap.rc
168+
)

0 commit comments

Comments
 (0)