-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
124 lines (96 loc) · 2.74 KB
/
Copy pathCMakeLists.txt
File metadata and controls
124 lines (96 loc) · 2.74 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
118
119
120
121
122
123
124
cmake_minimum_required(VERSION 3.16)
# =========================
# Project
# =========================
# Note: Can rename the project
project(sfml-bouncing-balls LANGUAGES CXX)
include(FetchContent)
# =========================
# User options
# =========================
# App name
set(APP_NAME "app")
# Build type (only set if not provided by user)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
endif()
# C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Export compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Resource directory
set(RES_DIR "${CMAKE_SOURCE_DIR}/res")
# =========================
# SFML options
# =========================
set(SFML_VERSION "2.6.2")
option(USE_SFML_AUDIO "Enable SFML Audio module" OFF)
option(USE_SFML_NETWORK "Enable SFML Network module" OFF)
set(BUILD_SHARED_LIBS TRUE)
# =========================
# Sources
# =========================
# Note: You can use glob recurse to get the files (But anytime you add new scripts, you gotta rerun cmake)
set(SOURCES
src/main.cpp
)
set(HEADERS_DIR
src
)
# =========================
# Dependencies
# =========================
# Disable unused SFML modules at build time
set(SFML_BUILD_AUDIO ${USE_SFML_AUDIO})
set(SFML_BUILD_NETWORK ${USE_SFML_NETWORK})
FetchContent_Declare(
SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG ${SFML_VERSION}
GIT_SHALLOW ON
EXCLUDE_FROM_ALL
SYSTEM
)
FetchContent_MakeAvailable(SFML)
# =========================
# Target
# =========================
add_executable(${APP_NAME})
target_sources(${APP_NAME} PRIVATE ${SOURCES})
target_include_directories(${APP_NAME}
PRIVATE
${HEADERS_DIR}
)
# Core SFML dependency
target_link_libraries(${APP_NAME}
PRIVATE
sfml-graphics
)
# Optional SFML modules
if (USE_SFML_AUDIO)
target_link_libraries(${APP_NAME} PRIVATE sfml-audio)
endif()
if (USE_SFML_NETWORK)
target_link_libraries(${APP_NAME} PRIVATE sfml-network)
endif()
# Organize files nicely in IDEs
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${SOURCES})
# =========================
# Copy resources
# =========================
if(EXISTS ${RES_DIR})
# // Source - https://stackoverflow.com/a # // Posted by Fraser, modified by community. See post 'Timeline' for change history
# // Retrieved 2026-01-23, License - CC BY-SA 4.0
add_custom_command(
TARGET ${APP_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${RES_DIR}
$<TARGET_FILE_DIR:${APP_NAME}>
COMMENT "Copying resources from ${RES_DIR}"
)
else()
message(STATUS "Resource directory ${RES_DIR} not found - skipping copy")
endif()