-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
64 lines (54 loc) · 2.48 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
cmake_minimum_required(VERSION 3.13)
project(Graphics C)
# set compiler standard to c99
set(CMAKE_C_STANDARD 99)
# set include dir and library dir to specific path
if (WIN32)
set(SDL2_INCLUDE_DIR include)
set(SDL2_LIBRARY_DIR lib/x64)
elseif (APPLE)
set(SDL2_INCLUDE_DIR /opt/homebrew/include)
set(SDL2_LIBRARY_DIR /opt/homebrew/lib)
endif ()
# add include and library dir to every add_executable
include_directories(${SDL2_INCLUDE_DIR})
link_directories(${SDL2_LIBRARY_DIR})
# add special compiler flags for better cross paltform code
set(CMAKE_C_FLAGS "-Wall -pedantic")
# add all headers
file(GLOB headers CONFIGURE_DEPENDS "header/*.h" "header/*.c")
# add executable
add_executable(heart ${headers} examples/heart.c)
add_executable(times_tables ${headers} examples/times_tables.c)
add_executable(tree ${headers} examples/tree.c)
add_executable(mandelbroatset_v2 ${headers} examples/mandelbroatset_v2.c)
add_executable(tic_tac_toe ${headers} examples/tic_tac_toe.c)
add_executable(ttf_test ${headers} examples/ttf_test.c)
if (WIN32)
set(library_dependencies SDL2main SDL2 SDL2_ttf SDL2_image SDL2_mixer)
elseif (APPLE)
set(library_dependencies SDL2 SDL2_ttf SDL2_image SDL2_mixer)
endif()
# link libraries during linking phase
target_link_libraries(heart ${library_dependencies})
target_link_libraries(times_tables ${library_dependencies})
target_link_libraries(tree ${library_dependencies})
target_link_libraries(mandelbroatset_v2 ${library_dependencies})
target_link_libraries(tic_tac_toe ${library_dependencies})
target_link_libraries(ttf_test ${library_dependencies})
if (WIN32)
# copy dlls to executable directory
add_custom_target(copy_dll
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/${SDL2_LIBRARY_DIR}/SDL2.dll ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/${SDL2_LIBRARY_DIR}/SDL2_image.dll ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/${SDL2_LIBRARY_DIR}/SDL2_ttf.dll ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_SOURCE_DIR}/${SDL2_LIBRARY_DIR}/SDL2_mixer.dll ${CMAKE_BINARY_DIR}
)
# add the copy_dll to every executable as a dependency
add_dependencies(heart copy_dll)
add_dependencies(times_tables copy_dll)
add_dependencies(tree copy_dll)
add_dependencies(mandelbroatset_v2 copy_dll)
add_dependencies(tic_tac_toe copy_dll)
add_dependencies(ttf_test copy_dll)
endif (WIN32)