git.haldean.org qb / b340f54 CMakeLists.txt
b340f54

Tree @b340f54 (Download .tar.gz)

CMakeLists.txt @b340f54raw · history · blame

cmake_minimum_required(VERSION 3.0)
project(cimgui-sokol-starterkit)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (CMAKE_SYSTEM_NAME STREQUAL Emscripten)
    set(CMAKE_EXECUTABLE_SUFFIX ".html")
endif()
if(MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
endif(MSVC)

# Linux -pthread shenanigans
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
    set(THREADS_PREFER_PTHREAD_FLAG ON)
    find_package(Threads REQUIRED)
endif()

#=== LIBRARY: cimgui + Dear ImGui
add_library(cimgui STATIC 
    cimgui/cimgui.cpp 
    cimgui/cimgui.h 
    cimgui/imgui/imgui.cpp
    cimgui/imgui/imgui.h
    cimgui/imgui/imgui_widgets.cpp 
    cimgui/imgui/imgui_draw.cpp 
    cimgui/imgui/imgui_tables.cpp
    cimgui/imgui/imgui_demo.cpp)
target_include_directories(cimgui INTERFACE cimgui)
target_include_directories(cimgui PRIVATE cimgui/imgui)

#=== LIBRARY: sokol
# add headers to the the file list because they are useful to have in IDEs
set(SOKOL_HEADERS
    sokol/sokol_gfx.h
    sokol/sokol_app.h
    sokol/sokol_audio.h
    sokol/sokol_time.h
    sokol/sokol_imgui.h
    sokol/sokol_glue.h)
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
    add_library(sokol STATIC sokol/sokol.m ${SOKOL_HEADERS})
    target_link_libraries(sokol PUBLIC
        "-framework QuartzCore"
        "-framework Cocoa"
        "-framework MetalKit"
        "-framework Metal")
else()
    add_library(sokol STATIC sokol/sokol.c ${SOKOL_HEADERS})
    if (CMAKE_SYSTEM_NAME STREQUAL Linux)
        target_link_libraries(sokol INTERFACE X11 Xi Xcursor GL dl m)
        target_link_libraries(sokol PUBLIC Threads::Threads)
    endif()
endif()
target_link_libraries(sokol PUBLIC cimgui)
target_include_directories(sokol INTERFACE sokol)

#=== LIBRARY: AudioFFT
add_library(audiofft STATIC
    AudioFFT/AudioFFT.h
    AudioFFT/AudioFFT.cpp)
target_include_directories(cimgui INTERFACE AudioFFT)

#=== EXECUTABLE: qb
set(QB_SOURCES
    launch.c
    audionode.cpp
    colors.cpp
    colors.hpp
    qb.cpp
    qb.hpp
    qbshim.cpp
    qbshim.hpp
    nodeui.cpp
    nodeui.hpp
    task.cpp
    task.hpp
    AudioFile/AudioFile.h
    )
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
    add_executable(qb WIN32 ${QB_SOURCES})
else()
    add_executable(qb ${QB_SOURCES})
endif()
target_include_directories(qb PRIVATE cimgui/imgui implot AudioFFT)
target_link_libraries(qb sokol audiofft)

# explicitly strip dead code
if (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_SYSTEM_NAME STREQUAL Emscripten)
    target_link_options(qb PRIVATE LINKER:-dead_strip)
endif()

# this hack removes the xxx-CMakeForceLinker.cxx dummy file
set_target_properties(qb PROPERTIES LINKER_LANGUAGE C)