-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
73 lines (58 loc) · 2.4 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
cmake_minimum_required(VERSION 3.1)
project(ryuuk)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release."
FORCE)
endif(NOT CMAKE_BUILD_TYPE)
set(BUILD_STATIC FALSE CACHE STRING "Set this to link external libraries statically")
if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -g -pthread")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -pthread")
endif()
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1)
set(LIBS stdc++fs)
endif()
# Add directory containing FindSFML.cmake to module path
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/;${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}")
# Add sources
file(GLOB SOURCES
"${PROJECT_SOURCE_DIR}/src/*.cpp"
)
# Copy resources
file(COPY ryuuk.conf DESTINATION .)
# Will add __FILENAME__ macros for all source files, which is the filename without full find_path
# Courtesy of SO
function(define_file_basename_for_sources targetname)
get_target_property(source_files "${targetname}" SOURCES)
foreach(sourcefile ${source_files})
# Get source file's current list of compile definitions.
get_property(defs SOURCE "${sourcefile}"
PROPERTY COMPILE_DEFINITIONS)
# Add the FILE_BASENAME=filename compile definition to the list.
get_filename_component(basename "${sourcefile}" NAME)
list(APPEND defs "__FILENAME__=\"${basename}\"")
# Set the updated compile definitions on the source file.
set_property(
SOURCE "${sourcefile}"
PROPERTY COMPILE_DEFINITIONS ${defs})
endforeach()
endfunction()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DLOG_LEVEL=DEBUG)
endif()
# Specify include Directory
include_directories("${PROJECT_SOURCE_DIR}/include")
# Set static if BUILD_STATIC is set
if (BUILD_STATIC)
set(SFML_STATIC_LIBRARIES TRUE)
# Link libgcc and libstc++ statically as well
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc")
endif()
endif()
add_executable(ryuuk ${SOURCES})
set_property(TARGET ryuuk PROPERTY CXX_STANDARD 17)
set_property(TARGET ryuuk PROPERTY CXX_STANDARD_REQUIRED ON)
target_link_libraries(ryuuk ${LIBS})
define_file_basename_for_sources(ryuuk)