forked from SFML/cmake-sfml-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
42 lines (33 loc) · 1.59 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
cmake_minimum_required(VERSION 3.15)
project(CMakeSFMLProject LANGUAGES CXX)
# Set options
option(CMAKESFMLPROJECT_STATIC_LIBS "Link SFML libraries statically?" OFF)
option(CMAKESFMLPROJECT_STATIC_STD_LIBS "Use statically linked standard/runtime libraries? This option must match the one used for SFML." OFF)
# Tell CMake to build a executable
add_executable(${PROJECT_NAME} src/main.cpp)
# CMake SFML Project uses C++17 features
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS NO CXX_STANDARD_REQUIRED YES)
# Make sure that the runtime library gets linked statically
if(CMAKESFMLPROJECT_STATIC_STD_LIBS)
if(NOT CMAKESFMLPROJECT_STATIC_LIBS)
message("\n-> If you check CMAKESFMLPROJECT_STATIC_STD_LIBS, you also need to check CMAKESFMLPROJECT_STATIC_LIBS.")
message("-> It would lead to multiple runtime environments which results in undefined behavior.\n")
elseif(WIN32 AND MSVC)
set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
elseif(CMAKE_COMPILER_IS_GNUCXX)
# Note: Doesn't work for TDM compiler, since it's compiling the runtime libs statically by default
target_compile_options(${PROJECT_NAME} PRIVATE -static)
endif()
endif()
# Request static SFML libraries when building statically
if(CMAKESFMLPROJECT_STATIC_LIBS)
set(SFML_STATIC_LIBRARIES TRUE)
endif()
# Find SFML
find_package(SFML 2.5 COMPONENTS graphics REQUIRED)
# Link SFML
target_link_libraries(${PROJECT_NAME} sfml-graphics)
# Install executable
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION .)