Skip to content

Commit

Permalink
Add Windows support in CMake build
Browse files Browse the repository at this point in the history
  • Loading branch information
Masterkatze committed Jul 22, 2024
1 parent 7f18a2b commit d21f9c3
Show file tree
Hide file tree
Showing 181 changed files with 76,453 additions and 415 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# exclude binaries and temporary files
CMakeCache.txt
CMakeSettings.json
cmake_install.cmake
cmake-build-*
install_manifest.txt
Expand Down
134 changes: 97 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cmake_policy(SET CMP0095 NEW)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include(utils)

calculate_xray_build_id(XRAY_BUILD_ID)

project(OpenXRay
Expand All @@ -18,6 +19,22 @@ project(OpenXRay
LANGUAGES CXX C
)

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(OS_LINUX TRUE)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(OS_MACOS TRUE)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(OS_WINDOWS TRUE)
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
set(OS_BSD TRUE)
else()
message(FATAL_ERROR "Unsupported CMAKE_SYSTEM_NAME \"${CMAKE_SYSTEM_NAME}\"")
endif()

if(OS_WINDOWS)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/windows")
endif()

message(STATUS "CMAKE_PROJECT_VERSION: ${CMAKE_PROJECT_VERSION}")

set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -149,11 +166,18 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT XRAY_USE_DEFAULT_CXX_LIB)
endif()
endif()

add_compile_options(-Wno-attributes)
if (APPLE)
add_compile_options(-Wl,-undefined,error)
else()
add_compile_options(-Wl,--no-undefined)
if (NOT OS_WINDOWS)
add_compile_options(-Wno-attributes)
if (APPLE)
add_compile_options(-Wl,-undefined,error)
else()
add_compile_options(-Wl,--no-undefined)
endif()
endif()

if (MASTER_GOLD AND OS_WINDOWS)
add_compile_definitions(_HAS_EXCEPTIONS=0)
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()

# TODO test
Expand Down Expand Up @@ -206,10 +230,12 @@ elseif (PROJECT_PLATFORM_PPC)
)
add_compile_definitions(NO_WARN_X86_INTRINSICS)
else()
add_compile_options(
-mfpmath=sse
-msse3
)
if (NOT OS_WINDOWS)
add_compile_options(
-mfpmath=sse
-msse3
)
endif()
endif()

if (XRAY_LINKER)
Expand All @@ -229,7 +255,28 @@ add_compile_definitions(
_CPPUNWIND
)

if (NOT WIN32)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH_TYPE x64)
else (CMAKE_SIZEOF_VOID_P EQUAL 4)
set(ARCH_TYPE x86)
endif()

list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/sdk")
list(APPEND CMAKE_LIBRARY_PATH "${CMAKE_SOURCE_DIR}/sdk/libraries/${ARCH_TYPE}")

# TODO move
if(OS_WINDOWS)
set(SDL2_DIR "${CMAKE_SOURCE_DIR}/sdk/cmake")
endif()

find_package(SDL2 REQUIRED CONFIG)
find_package(mimalloc)

if(NOT TARGET mimalloc::mimalloc)
add_library(mimalloc::mimalloc ALIAS mimalloc)
endif()

if (NOT OS_WINDOWS)
find_package(SDL2 2.0.18 REQUIRED)
# Fix to support older SDL2
# https://github.com/OpenXRay/xray-16/issues/1595
Expand All @@ -241,15 +288,22 @@ if (NOT WIN32)
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
)
endif()

find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(OpenAL REQUIRED)
find_package(JPEG)
find_package(Ogg REQUIRED)
find_package(Vorbis REQUIRED)
find_package(Theora REQUIRED)
find_package(LZO REQUIRED)
find_package(mimalloc NAMES mimalloc2 mimalloc2.0 mimalloc)

endif()

option(XRAY_USE_LUAJIT "Use LuaJIT" ON)

add_subdirectory(Externals)

# Memory allocator option
if (mimalloc_FOUND)
set(MEMORY_ALLOCATOR "mimalloc" CACHE STRING "Use specific memory allocator (mimalloc/standard)")
Expand All @@ -258,38 +312,44 @@ else()
endif()
set_property(CACHE MEMORY_ALLOCATOR PROPERTY STRINGS "mimalloc" "standard")

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

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

option(XRAY_USE_LUAJIT "Use LuaJIT" ON)

add_subdirectory(Externals)
if (OS_WINDOWS)
add_compile_options(
/nologo
)

add_compile_options(
-Wall
#-Werror
-Wextra
#-pedantic
-Wno-unknown-pragmas
-Wno-strict-aliasing
-Wno-parentheses
-Wno-unused-label
-Wno-unused-parameter
-Wno-switch
#-Wno-padded
#-Wno-c++98-compat
#-Wno-c++98-compat-pedantic
#-Wno-c++11-compat
#-Wno-c++11-compat-pedantic
#-Wno-c++14-compat
#-Wno-c++14-compat-pedantic
#-Wno-newline-eof
$<$<CXX_COMPILER_ID:GNU>:$<$<COMPILE_LANGUAGE:CXX>:-Wno-class-memaccess>>
$<$<CXX_COMPILER_ID:GNU>:$<$<COMPILE_LANGUAGE:CXX>:-Wno-interference-size>>
)
add_link_options(
/nologo
)
else()
add_compile_options(
-Wall
#-Werror
-Wextra
#-pedantic
-Wno-unknown-pragmas
-Wno-strict-aliasing
-Wno-parentheses
-Wno-unused-label
-Wno-unused-parameter
-Wno-switch
#-Wno-padded
#-Wno-c++98-compat
#-Wno-c++98-compat-pedantic
#-Wno-c++11-compat
#-Wno-c++11-compat-pedantic
#-Wno-c++14-compat
#-Wno-c++14-compat-pedantic
#-Wno-newline-eof
$<$<CXX_COMPILER_ID:GNU>:$<$<COMPILE_LANGUAGE:CXX>:-Wno-class-memaccess>>
$<$<CXX_COMPILER_ID:GNU>:$<$<COMPILE_LANGUAGE:CXX>:-Wno-interference-size>>
)
endif()

add_subdirectory(src)
add_subdirectory(res)
Expand Down
168 changes: 168 additions & 0 deletions Externals/BugTrap-proj/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
add_library(bugtrap_bugtrap SHARED)

add_library(BugTrap::BugTrap ALIAS bugtrap_bugtrap)

target_include_directories(bugtrap_bugtrap
PRIVATE
#../BugTrap/include
../zlib
../zlib/include
../zlib/contrib/minizip
"${CMAKE_BINARY_DIR}/Externals/zlib"
)

target_compile_definitions(bugtrap_bugtrap
PUBLIC
_USRDLL
BUGTRAP_EXPORTS
WIN64
_WINDOWS

)

target_link_libraries(bugtrap_bugtrap
PRIVATE
zlib::zlib
ws2_32.lib
comctl32.lib
shlwapi.lib
version.lib
wininet.lib
vfw32.lib
)

target_link_options(bugtrap_bugtrap
PRIVATE
/DEF:../BugTrap/source/Client/BugTrap.def
nothrownew.obj
)

#TODO add unity build

target_sources(bugtrap_bugtrap
PRIVATE
../BugTrap/source/Client/AboutDlg.cpp
../BugTrap/source/Client/AboutDlg.h
../BugTrap/source/Client/AnimProgressBar.cpp
../BugTrap/source/Client/AnimProgressBar.h
../BugTrap/source/Client/Array.h
../BugTrap/source/Client/AssemblyInfo.cpp
../BugTrap/source/Client/BTAtlWindow.h
../BugTrap/source/Client/BTMfcWindow.h
../BugTrap/source/Client/BTTrace.h
../BugTrap/source/Client/BaseStream.h
../BugTrap/source/Client/Buffer.h
../BugTrap/source/Client/BugTrap.cpp
../BugTrap/source/Client/BugTrap.h
../BugTrap/source/Client/BugTrapNet.cpp
../BugTrap/source/Client/BugTrapNet.h
../BugTrap/source/Client/BugTrapUI.cpp
../BugTrap/source/Client/BugTrapUI.h
../BugTrap/source/Client/BugTrapUtils.cpp
../BugTrap/source/Client/BugTrapUtils.h
../BugTrap/source/Client/CMapi.cpp
../BugTrap/source/Client/CMapi.h
../BugTrap/source/Client/ColHelper.cpp
../BugTrap/source/Client/ColHelper.h
../BugTrap/source/Client/DescribeErrorDlg.cpp
../BugTrap/source/Client/DescribeErrorDlg.h
../BugTrap/source/Client/Encoding.cpp
../BugTrap/source/Client/Encoding.h
../BugTrap/source/Client/EnumProcess.cpp
../BugTrap/source/Client/EnumProcess.h
../BugTrap/source/Client/FileStream.cpp
../BugTrap/source/Client/FileStream.h
../BugTrap/source/Client/Globals.cpp
../BugTrap/source/Client/Globals.h
../BugTrap/source/Client/Hash.h
../BugTrap/source/Client/HexView.cpp
../BugTrap/source/Client/HexView.h
../BugTrap/source/Client/HyperLink.cpp
../BugTrap/source/Client/HyperLink.h
../BugTrap/source/Client/ImageView.cpp
../BugTrap/source/Client/ImageView.h
../BugTrap/source/Client/InMemLogFile.cpp
../BugTrap/source/Client/InMemLogFile.h
../BugTrap/source/Client/InputStream.cpp
../BugTrap/source/Client/InputStream.h
../BugTrap/source/Client/InterfacePtr.h
../BugTrap/source/Client/LayoutManager.cpp
../BugTrap/source/Client/LayoutManager.h
../BugTrap/source/Client/LeakWatcher.h
../BugTrap/source/Client/List.h
../BugTrap/source/Client/LogFile.cpp
../BugTrap/source/Client/LogFile.h
../BugTrap/source/Client/LogLink.h
../BugTrap/source/Client/LogStream.cpp
../BugTrap/source/Client/LogStream.h
../BugTrap/source/Client/MachineInfoDlg.cpp
../BugTrap/source/Client/MachineInfoDlg.h
../BugTrap/source/Client/MachineStateDlg.cpp
../BugTrap/source/Client/MachineStateDlg.h
../BugTrap/source/Client/MainDlg.cpp
../BugTrap/source/Client/MainDlg.h
../BugTrap/source/Client/MemStream.cpp
../BugTrap/source/Client/MemStream.h
../BugTrap/source/Client/ModuleImportTable.cpp
../BugTrap/source/Client/ModuleImportTable.h
../BugTrap/source/Client/NetThunks.cpp
../BugTrap/source/Client/NetThunks.h
../BugTrap/source/Client/OutputStream.cpp
../BugTrap/source/Client/OutputStream.h
../BugTrap/source/Client/PreviewDlg.cpp
../BugTrap/source/Client/PreviewDlg.h
../BugTrap/source/Client/ResManager.cpp
../BugTrap/source/Client/ResManager.h
../BugTrap/source/Client/SendMailDlg.cpp
../BugTrap/source/Client/SendMailDlg.h
../BugTrap/source/Client/SimpleDlg.cpp
../BugTrap/source/Client/SimpleDlg.h
../BugTrap/source/Client/SmartPtr.h
../BugTrap/source/Client/Splitter.cpp
../BugTrap/source/Client/Splitter.h
../BugTrap/source/Client/StrHolder.cpp
../BugTrap/source/Client/StrHolder.h
../BugTrap/source/Client/StrStream.cpp
../BugTrap/source/Client/StrStream.h
../BugTrap/source/Client/Stream.h
../BugTrap/source/Client/SymEngine.cpp
../BugTrap/source/Client/SymEngine.h
../BugTrap/source/Client/SymEngineNet.cpp
../BugTrap/source/Client/SymEngineNet.h
../BugTrap/source/Client/TextFormat.cpp
../BugTrap/source/Client/TextFormat.h
../BugTrap/source/Client/TextLogFile.cpp
../BugTrap/source/Client/TextLogFile.h
../BugTrap/source/Client/TextView.cpp
../BugTrap/source/Client/TextView.h
../BugTrap/source/Client/ThemeXP.cpp
../BugTrap/source/Client/ThemeXP.h
../BugTrap/source/Client/TransferProgressDlg.cpp
../BugTrap/source/Client/TransferProgressDlg.h
../BugTrap/source/Client/VersionInfo.h
../BugTrap/source/Client/VersionInfoString.h
../BugTrap/source/Client/WaitCursor.cpp
../BugTrap/source/Client/WaitCursor.h
../BugTrap/source/Client/WaitDlg.cpp
../BugTrap/source/Client/WaitDlg.h
../BugTrap/source/Client/XmlLogFile.cpp
../BugTrap/source/Client/XmlLogFile.h
../BugTrap/source/Client/XmlReader.cpp
../BugTrap/source/Client/XmlReader.h
../BugTrap/source/Client/XmlWriter.cpp
../BugTrap/source/Client/XmlWriter.h
../BugTrap/source/Client/resource.h
../BugTrap/source/Client/stdafx.cpp
../BugTrap/source/Client/stdafx.h

../BugTrap/source/Client/res/Bug.ico
../BugTrap/source/Client/res/CheckMark.bmp
../BugTrap/source/Client/res/ImageToolbar.bmp
../BugTrap/source/Client/res/SortArrows.bmp

../BugTrap/source/Client/BugTrap.def
../BugTrap/source/Client/res/KeyPair.snk
../BugTrap/source/Client/res/Upload.avi

../BugTrap/source/Client/BugTrap.rc
)
Loading

0 comments on commit d21f9c3

Please sign in to comment.