summaryrefslogtreecommitdiff
path: root/common/c_cpp/CMakeLists.txt
blob: f87b1d58a3aa225394f66d1c7447c02be65d3793 (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
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_library(common INTERFACE)

set(FETCHCONTENT_QUIET FALSE)
include(FetchContent)

# -----------------------------------------------------------------------------
# Language options
# -----------------------------------------------------------------------------
target_compile_features(common INTERFACE cxx_std_20)
target_compile_features(common INTERFACE c_std_17)

# -----------------------------------------------------------------------------
# Compiler flags for maximum debuggage
# -----------------------------------------------------------------------------
if(MSVC)
  target_compile_options(common INTERFACE /W3)
else()
  target_compile_options(common INTERFACE -Wall -Wextra -Wpedantic)
endif()

# @@ should do a test compile to see if asan is actually available
if(NOT MINGW)
  target_compile_options(common INTERFACE -fsanitize=address)
  target_link_options(common    INTERFACE -fsanitize=address)
endif()

# -----------------------------------------------------------------------------
# Dependency: Dear ImGui
# -----------------------------------------------------------------------------
if(DEMO_NEEDS_DEAR_IMGUI)
  FetchContent_Declare(
    DEAR_IMGUI
    GIT_REPOSITORY https://github.com/ocornut/imgui.git
    GIT_TAG        v1.92.4 
    GIT_PROGRESS   TRUE
    GIT_SHALLOW    TRUE
  )
  FetchContent_MakeAvailable(DEAR_IMGUI)
  message("dear_imgui_SOURCE_DIR: ${dear_imgui_SOURCE_DIR}")
  add_library(common_dear_imgui STATIC
    "${dear_imgui_SOURCE_DIR}/imgui.cpp"
    "${dear_imgui_SOURCE_DIR}/imgui_demo.cpp"
    "${dear_imgui_SOURCE_DIR}/imgui_draw.cpp"
    "${dear_imgui_SOURCE_DIR}/imgui_tables.cpp"
    "${dear_imgui_SOURCE_DIR}/imgui_widgets.cpp"
  )
  target_include_directories(common_dear_imgui PUBLIC
    "${dear_imgui_SOURCE_DIR}"
    "${dear_imgui_SOURCE_DIR}/backends"
  )
  target_compile_features(common_dear_imgui PRIVATE cxx_std_17)
  target_link_libraries(common INTERFACE common_dear_imgui)
endif()

# -----------------------------------------------------------------------------
# Dependency: FFmpeg
# -----------------------------------------------------------------------------
if(DEMO_NEEDS_FFMPEG)
  if(WIN32 AND MSVC)
    message(FATAL_ERROR "FFmpeg is not available for msvc")
  else()
    find_package(PkgConfig REQUIRED)
    pkg_check_modules(AVCODEC     REQUIRED IMPORTED_TARGET libavcodec)
    pkg_check_modules(AVFORMAT    REQUIRED IMPORTED_TARGET libavformat)
    pkg_check_modules(AVUTIL      REQUIRED IMPORTED_TARGET libavutil)
    pkg_check_modules(SWRESAMPLE  REQUIRED IMPORTED_TARGET libswresample)
    pkg_check_modules(SWSCALE     REQUIRED IMPORTED_TARGET libswscale)
    target_link_libraries(common INTERFACE
      PkgConfig::AVCODEC
      PkgConfig::AVFORMAT
      PkgConfig::AVUTIL
      PkgConfig::SWRESAMPLE
      PkgConfig::SWSCALE
    )
  endif()
endif()

# -----------------------------------------------------------------------------
# Dependency: SDL3
# -----------------------------------------------------------------------------
if(DEMO_NEEDS_SDL3)
  if(WIN32 AND MSVC)
    FetchContent_Declare(
      SDL
      GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
      GIT_TAG        release-3.2.18
      GIT_PROGRESS   TRUE
      GIT_SHALLOW    TRUE
    )
    FetchContent_MakeAvailable(SDL)
    target_link_libraries(common INTERFACE SDL3::SDL3)
  else()
    find_package(PkgConfig REQUIRED)
    pkg_check_modules(SDL3 REQUIRED IMPORTED_TARGET SDL3)
    target_link_libraries(common INTERFACE PkgConfig::SDL3)
  endif()
endif()