-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
79 lines (65 loc) · 2.84 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
cmake_minimum_required(VERSION 3.16)
set(CMAKE_GENERATOR_PLATFORM Win32 CACHE STRING "" FORCE)
set(CMAKE_CONFIGURATION_TYPES Release CACHE STRING "" FORCE)
project(G3Dll)
# Gothic 3 installation folder
set(GOTHIC3_DIR "C:/Program Files (x86)/Steam/steamapps/common/Gothic 3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Gz")
# All header files (needed to be listed in Visual Studio)
set(HEADERS
include/framework.h
include/old.h
include/pch.h
include/Engine.dll.h
include/types.h
include/commontypes.h
include/formatters.h
)
# All source files
set(SOURCES
src/dllmain.cpp
src/framework.cpp
src/commontypes.cpp
)
# The DLL library
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS} "detours/CMakeLists.txt")
target_include_directories(${PROJECT_NAME} PUBLIC "include")
# How to group the files in the Solution Explorer
source_group(TREE "${CMAKE_CURRENT_LIST_DIR}/src" PREFIX "src" FILES ${SOURCES})
source_group(TREE "${CMAKE_CURRENT_LIST_DIR}/include" PREFIX "include" FILES ${HEADERS})
source_group(TREE "${CMAKE_CURRENT_LIST_DIR}/detours" PREFIX "detours" FILES "detours/CMakeLists.txt")
# Import the loader DLL to be also built
add_subdirectory(loader)
# Import the Microsoft Detours library (MIT License)
add_subdirectory(detours)
target_link_libraries(${PROJECT_NAME} detours)
# Import the spdlog library (MIT License)
add_subdirectory(spdlog)
target_link_libraries(${PROJECT_NAME} spdlog::spdlog)
# Import the GLFW library (Zlib License)
set(GLFW_BUILD_EXAMPLES OFF)
set(GLFW_BUILD_TESTS OFF)
set(GLFW_BUILD_DOCS OFF)
set(GLFW_INSTALL OFF)
add_subdirectory(glfw)
target_link_libraries(${PROJECT_NAME} glfw)
# Import gothic3sdk
add_subdirectory(gothic3sdk)
target_link_libraries(${PROJECT_NAME} gothic3sdk)
# Properties of the DLL
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17) # C++17
target_compile_options(${PROJECT_NAME} PUBLIC /Od) # Disable optimizations to make Detours work
#target_compile_options(${PROJECT_NAME} PUBLIC /Zc:preprocessor) # Force the standards-compliant preprocessor
target_precompile_headers(${PROJECT_NAME} PRIVATE "include/pch.h") # Precompiled headers to speed up compilation
add_dependencies(${PROJECT_NAME} G3Loader) # Make it depend on the other DLL
target_link_libraries(${PROJECT_NAME} dbghelp) # Link to dbghelp.lib
# How to handle CMake-generated targets
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(PREDEFINED_TARGETS_FOLDER "CMakePredefinedTargets")
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
# Where the DLL is written to
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE "${GOTHIC3_DIR}")
# Catch wrong compilers
if (NOT WIN32 OR NOT MSVC)
message(FATAL_ERROR "This project can only built using Visual Studio on Windows!")
endif ()