-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
87 lines (77 loc) · 2.87 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
cmake_minimum_required(VERSION 3.21)
include(CMakeDependentOption)
include(FetchContent)
project(nkui
VERSION 0.1.0
DESCRIPTION "Nuklear integration made easy"
LANGUAGES C
)
## manage build options
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
# on top project, lets build everything
set(NKUI_DEFAULT_STATIC ON CACHE INTERNAL "")
else()
set(NKUI_DEFAULT_STATIC OFF CACHE INTERNAL "")
endif()
option(NKUI_BUILD_STATIC "Build a static library instead of an interface target" ${NKUI_DEFAULT_STATIC})
option(NKUI_OPENGL "Use OpenGL for drawing" OFF)
option(NKUI_IMAGE_LOADER "Include the image loading functions" ON)
cmake_dependent_option(NKUI_NO_INCLUDE_STBIMAGE "Do not include self contained stb_image" OFF "NKUI_IMAGE_LOADER" OFF)
cmake_dependent_option(NKUI_NO_STBIMAGE_IMPL "Do not implement stb_image" OFF "NKUI_IMAGE_LOADER;NOT NKUI_NO_INCLUDE_STBIMAGE" OFF)
option(NKUI_NO_NK_IMPL "Do not implement Nuklear" OFF)
if(NKUI_BUILD_STATIC)
set(NKUI_BACKEND "" CACHE STRING "Set backend for a static build (xlib, gdip, sdl, glfw)")
endif()
include(cmake/nuklear.cmake)
if(NKUI_OPENGL)
list(APPEND NKUI_OPTIONS NKUI_OPENGL)
endif()
if(NKUI_IMAGE_LOADER)
list(APPEND NKUI_OPTIONS NKUI_IMAGE_LOADER)
endif()
if(NKUI_NO_INCLUDE_STBIMAGE)
list(APPEND NKUI_PRIV_OPTIONS NKUI_NO_INCLUDE_STBIMAGE)
endif()
if(NKUI_NO_STBIMAGE_IMPL)
list(APPEND NKUI_PRIV_OPTIONS NKUI_NO_STBIMAGE_IMPL)
endif()
if(NKUI_NO_NK_IMPL)
list(APPEND NKUI_PRIV_OPTIONS NKUI_NO_NK_IMPLEMENTATION)
endif()
if(NKUI_BUILD_STATIC)
set(NKUI_PRIVATE PRIVATE)
set(NKUI_PUBLIC PUBLIC)
add_library(nkui STATIC nkui.h nkui.c)
target_compile_definitions(nkui PRIVATE ${NKUI_PRIV_OPTIONS})
target_compile_definitions(nkui PUBLIC ${NKUI_OPTIONS})
# add backend specific rules
if(NKUI_BACKEND STREQUAL "")
message(FATAL_ERROR "No NKUI_BACKEND defined")
endif()
if(NKUI_BACKEND STREQUAL "xlib")
include(cmake/nkui_xlib.cmake)
endif()
else()
set(NKUI_PRIVATE INTERFACE)
set(NKUI_PUBLIC INTERFACE)
add_library(nkui INTERFACE nkui.h)
target_compile_definitions(nkui INTERFACE ${NKUI_OPTIONS})
endif()
set(NKUI_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(nkui ${NKUI_PUBLIC} "${NKUI_INCLUDE_DIR}")
target_link_libraries(nkui ${NKUI_PUBLIC} nuklear)
target_compile_features(nkui ${NKUI_PRIVATE} c_std_90)
if(MSVC)
target_compile_options(nkui ${NKUI_PRIVATE} /W4 /WX)
else()
target_compile_options(nkui ${NKUI_PRIVATE} -Wall -Wextra -pedantic)
if(NOT NKUI_NO_INCLUDE_STBIMAGE)
# should check bad code and propose a PR to nothings/stb
target_compile_options(nkui ${NKUI_PUBLIC} -Wno-misleading-indentation -Wno-shift-negative-value)
endif()
endif()
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(CMAKE_C_EXTENSIONS OFF)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_subdirectory(examples)
endif()