forked from Farama-Foundation/ViZDoom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
175 lines (132 loc) · 5.86 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
172
173
174
175
cmake_minimum_required(VERSION 3.12)
# Project + versions
#-----------------------------------------------------------------------------------------------------------------------
project(ViZDoom VERSION 1.2.2)
set(ViZDoom_VERSION_STR ${ViZDoom_VERSION_MAJOR}.${ViZDoom_VERSION_MINOR}.${ViZDoom_VERSION_PATCH})
set(ViZDoom_VERSION_ID ${ViZDoom_VERSION_MAJOR}${ViZDoom_VERSION_MINOR}${ViZDoom_VERSION_PATCH})
# Building options
#-----------------------------------------------------------------------------------------------------------------------
option(BUILD_PYTHON "Build ViZDoom Python (3) binding/module" ON)
option(BUILD_ENGINE "Build ViZDoom Engine (required to build Python package)" ON)
# CMake options
#-----------------------------------------------------------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_LINK)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif()
# Add cmake_modules to module
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")
# Set the release mode if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# System dependent settings
#-----------------------------------------------------------------------------------------------------------------------
if(UNIX)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
endif()
if(WIN32)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
macro(get_WIN32_WINNT version)
if(WIN32 AND CMAKE_SYSTEM_VERSION)
set(ver ${CMAKE_SYSTEM_VERSION})
string(REPLACE "10" "A" ver ${ver})
string(REPLACE "." "" ver ${ver})
string(REGEX REPLACE "([A-F0-9])" "0\\1" ver ${ver})
string(SUBSTRING ${ver} 0 4 ver)
set(${version} "0x${ver}")
endif()
endmacro()
get_WIN32_WINNT(ver)
add_definitions(-D_WIN32_WINNT=${ver})
endif()
if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
endif(APPLE)
# Compiler dependent settings
#-----------------------------------------------------------------------------------------------------------------------
if(CMAKE_COMPILER_IS_GNUCXX)
add_definitions("-fPIC")
# Explicitly silence some warnings
add_definitions("-Wno-implicit-fallthrough -Wno-shift-negative-value -Wno-stringop-truncation")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-class-memaccess -Wno-deprecated-copy") # C++ only
endif()
if(MSVC)
string(REPLACE "/MD " "/MT " CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
string(REPLACE "/MD " "/MT " CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL})
string(REPLACE "/MD " "/MT " CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
string(REPLACE "/MDd " "/MTd " CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
endif()
# Main library
#-----------------------------------------------------------------------------------------------------------------------
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(VIZDOOM_OUTPUT_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(VIZDOOM_SCRIPTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts)
set(VIZDOOM_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(VIZDOOM_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(VIZDOOM_LIB_SRC_DIR ${VIZDOOM_SRC_DIR}/lib)
set(VIZDOOM_LIB_INCLUDE_DIR ${VIZDOOM_INCLUDE_DIR} ${VIZDOOM_LIB_SRC_DIR})
set(VIZDOOM_OUTPUT_NAME vizdoom)
find_package(Boost 1.53 COMPONENTS filesystem thread system date_time chrono regex iostreams REQUIRED)
find_package(Threads REQUIRED)
include_directories(${VIZDOOM_LIB_INCLUDE_DIR} ${Boost_INCLUDE_DIR})
set(VIZDOOM_LIBS
${Boost_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT})
if(UNIX AND NOT APPLE)
set(VIZDOOM_LIBS ${VIZDOOM_LIBS} rt)
endif()
configure_file(
"${VIZDOOM_LIB_SRC_DIR}/ViZDoomVersion.h.in"
"${VIZDOOM_LIB_SRC_DIR}/ViZDoomVersion.h"
)
configure_file(
"${VIZDOOM_SRC_DIR}/vizdoom/src/viz_version.h.in"
"${VIZDOOM_SRC_DIR}/vizdoom/src/viz_version.h"
)
file(GLOB VIZDOOM_LIB_SOURCES
${VIZDOOM_INCLUDE_DIR}/*.h
${VIZDOOM_LIB_SRC_DIR}/*.h
${VIZDOOM_LIB_SRC_DIR}/*.cpp)
add_library(libvizdoom_static STATIC ${VIZDOOM_LIB_SOURCES})
target_link_libraries(libvizdoom_static PRIVATE ${VIZDOOM_LIBS})
add_library(libvizdoom_shared SHARED ${VIZDOOM_LIB_SOURCES})
target_link_libraries(libvizdoom_shared PRIVATE ${VIZDOOM_LIBS})
set_target_properties(libvizdoom_static libvizdoom_shared
PROPERTIES
LINKER_LANGUAGE CXX
LIBRARY_OUTPUT_DIRECTORY ${VIZDOOM_OUTPUT_DIR}
LIBRARY_OUTPUT_DIRECTORY_RELEASE ${VIZDOOM_OUTPUT_DIR}
LIBRARY_OUTPUT_DIRECTORY_DEBUG ${VIZDOOM_OUTPUT_DIR}
LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${VIZDOOM_OUTPUT_DIR}
LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${VIZDOOM_OUTPUT_DIR}
ARCHIVE_OUTPUT_DIRECTORY ${VIZDOOM_OUTPUT_DIR}
ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${VIZDOOM_OUTPUT_DIR}
ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${VIZDOOM_OUTPUT_DIR}
ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL ${VIZDOOM_OUTPUT_DIR}
ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${VIZDOOM_OUTPUT_DIR}
OUTPUT_NAME ${VIZDOOM_OUTPUT_NAME})
set_target_properties(libvizdoom_static
PROPERTIES
PROJECT_LABEL "Core static library")
set_target_properties(libvizdoom_shared
PROPERTIES
PROJECT_LABEL "Core shared library")
# ViZDoom Engine
#-----------------------------------------------------------------------------------------------------------------------
if(BUILD_ENGINE)
add_subdirectory(${VIZDOOM_SRC_DIR}/vizdoom)
endif()
# Python bindings
#-----------------------------------------------------------------------------------------------------------------------
if(BUILD_PYTHON)
add_subdirectory(${VIZDOOM_SRC_DIR}/lib_python)
endif()