-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
84 lines (67 loc) · 2.25 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
cmake_minimum_required(VERSION 3.10)
project(atto C)
set(OpenGL_GL_PREFERENCE GLVND)
if(WIN32)
set(ATTO_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/app_windows.c)
elseif(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
set(ATTO_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/app_linux.c)
set(ATTO_PRIVATE_LIBS m)
option(ATTO_APP_KMS "Use no-desktop raw libdrm KMS" OFF)
option(ATTO_APP_EGL "Use EGL for OpenGL context creation" ON)
if (ATTO_APP_KMS)
# KMS implies EGL
set(ATTO_APP_EGL YES)
# TODO OpenGL flavor selection
set(ATTO_APP_GLES YES)
set(ATTO_DEFS ${ATTO_DEFS} ATTO_KMS)
set(ATTO_SOURCES ${ATTO_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src/app_main.c)
find_package(PkgConfig REQUIRED)
pkg_check_modules(libdrm REQUIRED IMPORTED_TARGET libdrm)
pkg_check_modules(gbm REQUIRED IMPORTED_TARGET gbm)
set(ATTO_PRIVATE_LIBS ${ATTO_PRIVATE_LIBS} PkgConfig::libdrm PkgConfig::gbm)
else()
find_package(X11 REQUIRED)
set(ATTO_PRIVATE_LIBS
${ATTO_PRIVATE_LIBS}
${X11_LIBRARIES}
${X11_Xext_LIB}
${X11_Xfixes_LIB}
)
set(ATTO_SOURCES ${ATTO_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src/app_x11.c)
endif()
else()
message(FATAL_ERROR "Not ported")
endif()
add_library(atto STATIC ${ATTO_SOURCES})
if (ATTO_APP_GLES)
set(ATTO_DEFS ${ATTO_DEFS} ATTO_GLES)
set(OPENGL_USE_GLES2 YES)
endif()
if (ATTO_APP_EGL)
target_compile_definitions(atto PUBLIC ${ATTO_DEFS} ATTO_EGL)
set(OPENGL_USE_EGL YES)
find_package(OpenGL REQUIRED EGL)
set(ATTO_PUBLIC_LIBS ${ATTO_PUBLIC_LIBS} OpenGL::GL)
set(ATTO_PRIVATE_LIBS ${ATTO_PRIVATE_LIBS} OpenGL::EGL)
else()
find_package(OpenGL REQUIRED)
set(ATTO_PUBLIC_LIBS OpenGL::GL)
endif()
target_include_directories(atto PUBLIC include)
target_link_libraries(atto
PUBLIC ${ATTO_PUBLIC_LIBS}
PRIVATE ${ATTO_PRIVATE_LIBS})
set_target_properties(atto PROPERTIES
C_STANDARD 99
C_STANDARD_REQUIRED TRUE
C_EXTENSIONS TRUE)
message("C compiler ID: " ${CMAKE_C_COMPILER_ID})
target_compile_options(atto PRIVATE
$<$<C_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<C_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic -Werror>
$<$<C_COMPILER_ID:Clang>:-Wno-gnu-zero-variadic-macro-arguments>
)
# Also build examples if current cmake is root (not included from other cmake)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
add_subdirectory(examples)
endif()