summaryrefslogtreecommitdiff
path: root/src/CMakeLists.txt
blob: e721bffeab1b9f7878f75e616af50af25e3b26cc (plain)
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
# Set global include dirs
set(DAW_INCLUDE_DIRS
  ${CMAKE_CURRENT_LIST_DIR}/include
  ${CMAKE_CURRENT_LIST_DIR}/rendering/include
  ${CMAKE_BINARY_DIR}/include
  )

add_custom_command(
  OUTPUT ${GLAD_HEADER}
  COMMAND
  glad
  --api gl:core=4.6
  --out-path ${CMAKE_BINARY_DIR}
  --reproducible
  c
  --header-only
  --mx
  )


# DAW Engine compilation spec
add_library(${PROJECT_NAME}
  # User facing API
  api/daw.h

  # Types and (internal) interfaces
  include/daw/types.h

  # Utility algorithms & datastructures
  include/daw/utils.h
                    include/daw/utils/list.h
  btree.c           include/daw/utils/btree.h
  fov.c             include/daw/utils/fov.h
  hashmap.c         include/daw/utils/hashmap.h
  misc.c
  stack.c           include/daw/utils/stack.h

  # Core functionality
  daw.c             include/daw/daw.h
  dltools.c         include/daw/dltools.h
  logging.c         include/daw/logging.h
  memory.c          include/daw/memory.h
  state.c           include/daw/state.h

  # Peripheral IO
  input.c           include/daw/input.h
                    include/daw/keycodes.h
                    include/daw/scancodes.h

  # The rendering & presentation mess
  gl.c
  platform_glfw.c   include/daw/platform_glfw.h
  rendering.c       include/daw/rendering.h
  textures.c        include/daw/texture.h
  window.c          include/daw/window.h

  # Resource handling
  model.c           include/daw/model.h
  resources.c       include/daw/resources.h

  # Autogenerated header
  ${GLAD_HEADER}
  )

set_property(SOURCE src/window.c APPEND PROPERTY OBJECT_DEPENDS ${GLAD_HEADER})
set_property(SOURCE src/rendering.c APPEND PROPERTY OBJECT_DEPENDS ${GLAD_HEADER})

set_target_properties(${PROJECT_NAME} PROPERTIES
  LINKER_LANGUAGE C
  C_STANDARD 99
)

target_include_directories(${PROJECT_NAME} PUBLIC
  include
  ${CMAKE_BINARY_DIR}/include
  )

target_link_libraries(${PROJECT_NAME}
  glfw
  OpenGL::GL
  assimp
  cglm
  $<$<NOT:$<PLATFORM_ID:Windows>>:m>
  $<$<BOOL:${DAW_BUILD_HOTRELOAD}>:dl>
  $<$<AND:$<NOT:$<C_COMPILER_ID:MSVC>>,$<BOOL:${DAW_BUILD_UBSAN}>>:ubsan>
)

target_compile_features(${PROJECT_NAME} PRIVATE c_std_99)

if(DAW_BUILD_ASAN AND NOT C_COMPILER_ID STREQUAL MSVC)
  add_compile_options(-fsanitize=address -fsanitize=leak -fsanitize-address-use-after-scope)
  add_link_options(-fsanitize=address -fsanitize=leak -fsanitize-address-use-after-scope)
endif()

if(DAW_BUILD_UBSAN AND NOT C_COMPILER_ID STREQUAL MSVC)
  add_compile_options(-fsanitize=undefined -fsanitize-undefined-trap-on-error -fno-sanitize-recover)
  add_link_options(-fsanitize=undefined -fsanitize-undefined-trap-on-error -fno-sanitize-recover)
endif()

target_compile_options(${PROJECT_NAME} PUBLIC
  $<$<NOT:$<C_COMPILER_ID:MSVC>>:-Wall -Wextra>
  # Dont be pedantic when using hot reloading.
  $<$<AND:$<NOT:$<C_COMPILER_ID:MSVC>>,$<NOT:$<BOOL:${DAW_BUILD_HOTRELOAD}>>>:-pedantic>
  $<$<C_COMPILER_ID:MSVC>:/W4>
  # Debug related flags.  sorry windows, you're just not that important.
)

target_compile_definitions(${PROJECT_NAME} PUBLIC
  $<$<BOOL:${DAW_BUILD_DEBUG}>:_DEBUG>
  $<$<BOOL:${DAW_BUILD_HOTRELOAD}>:DAW_BUILD_HOTRELOAD>
)