-
-
Notifications
You must be signed in to change notification settings - Fork 472
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
117 lines (99 loc) · 4.41 KB
/
Copy pathCMakeLists.txt
File metadata and controls
117 lines (99 loc) · 4.41 KB
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
cmake_minimum_required (VERSION 3.14)
# Build the C++ shared library
option(BUILD_CPP_LIB "Build C++ Interface" ON)
# Build the native Python bindings using pybind11
option(BUILD_PYTHON_LIB "Build Python Interface" ON)
# Enable SDL for screen and audio support
option(SDL_SUPPORT "Enable SDL support" OFF)
# Append VCPKG manifest feature
if(SDL_SUPPORT)
list(APPEND VCPKG_MANIFEST_FEATURES "sdl")
endif()
option(BUILD_VECTOR_LIB "Build Vector Interface" OFF)
if (BUILD_VECTOR_LIB)
list(APPEND VCPKG_MANIFEST_FEATURES "vector")
endif()
option(BUILD_VECTOR_XLA_LIB "Build with Vector XLA Support" OFF)
option(BUILD_WASM_LIB "Build WebAssembly Interface" OFF)
if (BUILD_WASM_LIB)
add_definitions(-DBUILD_WASM_LIB)
# WASM builds disable incompatible features
set(BUILD_PYTHON_LIB OFF CACHE BOOL "Python not supported in WASM build" FORCE)
set(BUILD_VECTOR_LIB OFF CACHE BOOL "Vector lib requires threading not well-supported in WASM" FORCE)
set(BUILD_CPP_LIB OFF CACHE BOOL "Building WASM interface instead" FORCE)
set(BUILD_VECTOR_XLA_LIB OFF CACHE BOOL "XLA not supported in WASM build" FORCE)
# SDL is required for WASM (Emscripten provides SDL2 compatibility layer)
set(SDL_SUPPORT ON CACHE BOOL "SDL required for WASM" FORCE)
list(APPEND VCPKG_MANIFEST_FEATURES "sdl")
endif()
# Sanitizer support for debugging (thread, address, undefined)
# Usage: -DENABLE_SANITIZER=thread or -DENABLE_SANITIZER=address
set(ENABLE_SANITIZER "" CACHE STRING "Enable sanitizer (thread, address, or empty to disable)")
set_property(CACHE ENABLE_SANITIZER PROPERTY STRINGS "" "thread" "address")
if(ENABLE_SANITIZER)
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU")
message(WARNING "Sanitizers are best supported with Clang or GCC. Current compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()
if(ENABLE_SANITIZER STREQUAL "thread")
message(STATUS "Building with Thread Sanitizer (TSan)")
add_compile_options(-fsanitize=thread -g -O1)
add_link_options(-fsanitize=thread)
elseif(ENABLE_SANITIZER STREQUAL "address")
message(STATUS "Building with Address Sanitizer (ASan) + Undefined Behavior Sanitizer (UBSan)")
# Drop vptr/function UBSan checks: they require libclang_rt.ubsan_standalone_cxx,
# which is static-only. When the instrumented .so is loaded by an uninstrumented
# Python, __ubsan_vptr_type_cache and friends end up undefined at import time.
add_compile_options(-fsanitize=address -fsanitize=undefined -fno-sanitize=vptr,function -fno-omit-frame-pointer -g -O1)
add_link_options(-fsanitize=address -fsanitize=undefined -fno-sanitize=vptr,function)
else()
message(FATAL_ERROR "Invalid sanitizer '${ENABLE_SANITIZER}'. Choose 'thread' or 'address'.")
endif()
endif()
# Set cmake module path
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
# Overlay VCPKG custom triplets
if(NOT DEFINED VCPKG_OVERLAY_TRIPLETS)
set(VCPKG_OVERLAY_TRIPLETS
"${CMAKE_MODULE_PATH}/custom-triplets"
CACHE STRING "")
endif()
# Discover VCPKG default triplet
if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET
"$ENV{VCPKG_DEFAULT_TRIPLET}"
CACHE STRING "")
endif()
# Discover VCPKG toolchain
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
# VCPKG_ROOT is what Microsoft recommends,
# VCPKG_INSTALLATION_ROOT is what's defined on Azure
if(DEFINED ENV{VCPKG_ROOT})
set(CMAKE_TOOLCHAIN_FILE
"$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
elseif(DEFINED ENV{VCPKG_INSTALLATION_ROOT})
set(CMAKE_TOOLCHAIN_FILE
"$ENV{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
endif()
endif()
# Don't allow running cmake in root directory
if (CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
message(FATAL_ERROR [=[
Source and build directories cannot be the same.
You should probably also remove CMakeFiles/ and CMakeCache.txt.
]=])
endif()
include(ParseVersion)
parse_version("version.txt" PREFIX ALE)
project(ale VERSION ${ALE_DEFAULT_VERSION}
DESCRIPTION "The Arcade Learning Environment (ALE) - a platform for AI research."
HOMEPAGE_URL "http://www.arcadelearningenvironment.org"
LANGUAGES CXX)
# Main ALE src directory
add_subdirectory(src/ale)
# Only include tests in the main project
# if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
# enable_testing()
# add_subdirectory(tests)
# endif()