-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCMakeLists.txt
178 lines (146 loc) · 5.68 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
cmake_minimum_required(VERSION 3.20)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
project(AbyssEngine)
enable_testing()
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_C_STANDARD 99)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
function(setup_source_groups curdir)
file(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/${curdir} ${curdir}/*)
foreach (child ${children})
if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${curdir}/${child})
setup_source_groups(${curdir}/${child})
else ()
string(REPLACE "/" "\\" group_name ${curdir})
source_group(${group_name} FILES ${curdir}/${child})
endif ()
endforeach ()
endfunction()
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, defaulting to Release")
set(CMAKE_BUILD_TYPE Release)
endif ()
#turn on all warnings
if (CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic")
endif ()
if (CMAKE_C_COMPILER_ID MATCHES "MSVC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
endif ()
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-gnu-zero-variadic-macro-arguments")
endif ()
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Homebrew ships libarchive keg only, include dirs have to be set manually
execute_process(
COMMAND brew --prefix libarchive
OUTPUT_VARIABLE LIBARCHIVE_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY
)
set(LibArchive_INCLUDE_DIR "${LIBARCHIVE_PREFIX}/include")
endif ()
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
find_package(LibArchive REQUIRED)
include_directories(${LibArchive_INCLUDE_DIR})
find_package(FFMPEG COMPONENTS AVCODEC AVFORMAT AVUTIL SWSCALE SWRESAMPLE REQUIRED)
include_directories(${FFMPEG_INCLUDE_DIRS})
#add_compile_options(-fsanitize=address -g)
#add_link_options(-fsanitize=address)
add_executable(${PROJECT_NAME} WIN32)
target_sources(${PROJECT_NAME} PRIVATE src/AbyssEngine.c)
add_subdirectory(src)
setup_source_groups(src)
# if WIN32 then SDL2::SDL2main needs to be linked
if (WIN32)
set(ADDITIONAL_LIBRARIES SDL2::SDL2 SDL2::SDL2main)
endif ()
if (APPLE)
find_library(OSX_VIDEOTOOLBOX VideoToolbox)
find_library(OSX_COREMEDIA CoreMedia)
find_library(OSX_SECURITY Security)
set(ADDITIONAL_LIBRARIES
${OSX_VIDEOTOOLBOX}
${OSX_COREMEDIA}
${OSX_SECURITY}
)
elseif (UNIX)
set(ADDITIONAL_LIBRARIES "m")
endif ()
target_link_libraries(AbyssEngine
${SDL2_LIBRARIES}
${ZLIB_LIBRARIES}
${LibArchive_LIBRARIES}
${FFMPEG_LIBRARIES}
${ADDITIONAL_LIBRARIES}
)
if (NOT DEFINED GITHUB_ACTIONS)
if (UNIX)
# Find clang-format executable
find_program(CLANG_FORMAT_EXECUTABLE NAMES clang-format)
# Check if clang-format executable is found
if (NOT CLANG_FORMAT_EXECUTABLE)
message(FATAL_ERROR "clang-format not found. Please install clang-format or specify its path manually.")
endif ()
# Find all C and H files in the src directory
file(GLOB_RECURSE ALL_SOURCE_FILES "${CMAKE_SOURCE_DIR}/src/*.c" "${CMAKE_SOURCE_DIR}/src/*.h")
# Define a custom target and command to run clang-format
add_custom_target(
clang-format
COMMAND ${CLANG_FORMAT_EXECUTABLE} -i ${ALL_SOURCE_FILES}
COMMENT "Running clang-format on all C and H files"
VERBATIM
)
endif ()
endif ()
if (APPLE)
if (NOT DEFINED GITHUB_ACTIONS)
# Add the clang-format target as a dependency for Xcode
add_dependencies(${PROJECT_NAME} clang-format)
endif ()
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/extra/macos/" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/AbyssEngine.app/Contents/Resources")
set_target_properties(AbyssEngine PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_BUNDLE_NAME "Abyss Engine"
MACOSX_BUNDLE_BUNDLE_VERSION "0.1"
PRODUCT_BUNDLE_IDENTIFIER "com.abyssengine"
MACOSX_BUNDLE_GUI_IDENTIFIER "com.abyssengine"
MACOSX_BUNDLE_ICON_FILE "icon.icns"
#MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/extra/macos/MacOSXBundleInfo.plist.in"
MACOSX_BUNDLE_COPYRIGHT "(c) 2023 Timothy Sarbin"
)
set_source_files_properties("extra/macos/icon.icns" PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources"
)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Install path prefix, prepended onto install directories" FORCE)
else ()
add_custom_command(TARGET AbyssEngine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/content $<TARGET_FILE_DIR:AbyssEngine>)
endif ()
add_subdirectory(tests)
#include(InstallRequiredSystemLibraries)
#
#install(TARGETS AbyssEngine
# RUNTIME DESTINATION dist
# BUNDLE DESTINATION ../MacOS
#)
#
#set(CPACK_PACKAGE_NAME "AbyssEngine")
#set(CPACK_BUNDLE_NAME "AbyssEngine")
#set(CPACK_BUNDLE_PLIST "${CMAKE_SOURCE_DIR}/extra/macos/MacOSXBundleInfo.plist.in")
#set(CPACK_BUNDLE_ICON "${CMAKE_SOURCE_DIR}/extra/macos/icon.icns")
#set(CPACK_PACKAGE_VENDOR "AbyssEngine Developers")
#set(CPACK_PACKAGE_VERSION_MAJOR 0)
#set(CPACK_PACKAGE_VERSION_MINOR 1)
#set(CPACK_PACKAGE_VERSION_PATCH 0)
#set(CPACK_NSIS_MUI_ICON "@CMake_SOURCE_DIR@/extra/icon.ico")
#include(CPack)