forked from katajakasa/SDL_kitchensink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
191 lines (158 loc) · 6.15 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
cmake_minimum_required(VERSION 3.7)
project(SDL_kitchensink C)
include(GNUInstallDirs)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(KIT_VERSION_MAJOR "1")
set(KIT_VERSION_MINOR "0")
set(KIT_VERSION_PATCH "12")
set(KIT_VERSION ${KIT_VERSION_MAJOR}.${KIT_VERSION_MINOR}.${KIT_VERSION_PATCH})
add_definitions(
-DKIT_VERSION_MAJOR=${KIT_VERSION_MAJOR}
-DKIT_VERSION_MINOR=${KIT_VERSION_MINOR}
-DKIT_VERSION_PATCH=${KIT_VERSION_PATCH}
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb -Werror -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ggdb -O2 -fno-omit-frame-pointer -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -DNDEBUG")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -Os -DNDEBUG")
option(BUILD_EXAMPLES "Build examples" OFF)
option(USE_DYNAMIC_LIBASS "Use dynamically loaded libass" OFF)
option(USE_ASAN "Use AddressSanitizer" OFF)
option(USE_TIDY "Use clang-tidy" OFF)
option(BUILD_SHARED "Build shared library" ON)
option(BUILD_STATIC "Build static library" ON)
if(NOT BUILD_SHARED AND NOT BUILD_STATIC)
message(FATAL_ERROR "Nothing to build, set BUILD_SHARED and/or BUILD_STATIC.")
endif()
if(BUILD_SHARED)
message(STATUS "Building shared libraries")
else()
message(STATUS "NOT building shared libraries")
endif()
if(BUILD_STATIC)
message(STATUS "Building static libraries")
else()
message(STATUS "NOT building static libraries")
endif()
if(USE_ASAN)
message(STATUS "DEVELOPMENT: AddressSanitizer enabled!")
endif()
find_package(PkgConfig REQUIRED)
pkg_search_module(SDL2 REQUIRED sdl2)
pkg_search_module(AVCODEC REQUIRED libavcodec)
pkg_search_module(AVFORMAT REQUIRED libavformat)
pkg_search_module(AVUTIL REQUIRED libavutil)
pkg_search_module(SWSCALE REQUIRED libswscale)
pkg_search_module(SWRESAMPLE REQUIRED libswresample)
set(LIBRARIES
${SDL2_LIBRARIES}
${AVCODEC_LIBRARIES}
${AVFORMAT_LIBRARIES}
${AVUTIL_LIBRARIES}
${SWSCALE_LIBRARIES}
${SWRESAMPLE_LIBRARIES}
)
set(INCLUDES
include/
${SDL2_INCLUDE_DIRS}
${AVCODEC_INCLUDE_DIRS}
${AVFORMAT_INCLUDE_DIRS}
${AVUTIL_INCLUDE_DIRS}
${SWSCALE_INCLUDE_DIRS}
${SWRESAMPLE_INCLUDE_DIRS}
)
if(USE_DYNAMIC_LIBASS)
if(WIN32 OR MINGW OR MSYS)
set(DYNAMIC_LIBASS_NAME "\"libass-9.dll\"")
else()
set(DYNAMIC_LIBASS_NAME "\"libass.so\"")
endif()
add_definitions(-DUSE_DYNAMIC_LIBASS)
add_definitions(-DDYNAMIC_LIBASS_NAME=${DYNAMIC_LIBASS_NAME})
else()
# find_package(ass)
# set(LIBRARIES ${LIBRARIES} ${ASS_LIBRARIES})
# set(INCLUDES ${INCLUDES} ${ASS_INCLUDE_DIRS})
endif()
FILE(GLOB_RECURSE SOURCES "src/*.c")
FILE(GLOB INSTALL_HEADERS "include/kitchensink/*.h")
include_directories(${INCLUDES})
set(INSTALL_TARGETS "")
if(BUILD_SHARED)
add_library(SDL_kitchensink SHARED ${SOURCES})
if(USE_ASAN)
target_compile_options(SDL_kitchensink PRIVATE "-fsanitize=address")
target_link_libraries(SDL_kitchensink asan)
endif()
target_link_libraries(SDL_kitchensink ${LIBRARIES})
set_target_properties(SDL_kitchensink PROPERTIES VERSION ${KIT_VERSION})
set_target_properties(SDL_kitchensink PROPERTIES SOVERSION ${KIT_VERSION_MAJOR})
set_target_properties(SDL_kitchensink PROPERTIES DEBUG_POSTFIX "d")
target_compile_definitions(SDL_kitchensink PRIVATE "KIT_DLL;KIT_DLL_EXPORTS")
target_compile_options(SDL_kitchensink PRIVATE "-fvisibility=hidden")
set_property(TARGET SDL_kitchensink PROPERTY C_STANDARD 99)
set(INSTALL_TARGETS SDL_kitchensink ${INSTALL_TARGETS})
endif()
if(BUILD_STATIC)
add_library(SDL_kitchensink_static STATIC ${SOURCES})
if(USE_ASAN)
target_compile_options(SDL_kitchensink_static PRIVATE "-fsanitize=address")
endif()
set_target_properties(SDL_kitchensink_static PROPERTIES DEBUG_POSTFIX "d")
set_property(TARGET SDL_kitchensink_static PROPERTY C_STANDARD 99)
set(INSTALL_TARGETS SDL_kitchensink_static ${INSTALL_TARGETS})
endif()
if(USE_TIDY)
if(BUILD_STATIC)
set_target_properties(SDL_kitchensink_static PROPERTIES C_CLANG_TIDY "clang-tidy")
else()
set_target_properties(SDL_kitchensink PROPERTIES C_CLANG_TIDY "clang-tidy")
endif()
message(STATUS "Development: clang-tidy enabled")
else()
message(STATUS "Development: clang-tidy disabled")
endif()
set(PKG_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/SDL_kitchensink.pc")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/pkg-config.pc.in"
${PKG_CONFIG_FILE}
@ONLY
)
if(BUILD_EXAMPLES)
list(APPEND EXAMPLE_TARGETS audio complex simple custom rwops)
# If we are building static, just link all libraries (ffmpeg, sdl, etc.)
# If building shared, link shared kitchensink + SDL2 (ffmpeg gets pulled by kitchensink)
if(BUILD_STATIC)
set(EXAMPLE_LIBRARIES SDL_kitchensink_static ${LIBRARIES})
else()
set(EXAMPLE_LIBRARIES SDL_kitchensink ${SDL2_LIBRARIES})
endif()
if(USE_ASAN)
set(EXAMPLE_LIBRARIES asan ${EXAMPLE_LIBRARIES})
endif()
foreach(TARGET ${EXAMPLE_TARGETS})
add_executable(${TARGET} examples/example_${TARGET}.c)
set_property(TARGET ${TARGET} PROPERTY C_STANDARD 99)
target_link_libraries(${TARGET} ${EXAMPLE_LIBRARIES})
if(MINGW)
# If we are compiling with mingw, remember to link in mingw libs and set console mode
# This way stdout/stderr are handled correctly.
target_link_libraries(${TARGET} mingw32)
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "-mconsole")
endif()
if(USE_ASAN)
target_compile_options(${TARGET} PRIVATE "-fsanitize=address")
endif()
endforeach()
endif()
# documentation target
add_custom_target(docs COMMAND doxygen WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
# Installation
INSTALL(FILES ${PKG_CONFIG_FILE} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
INSTALL(FILES ${INSTALL_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/kitchensink)
INSTALL(TARGETS ${INSTALL_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)