cmake_minimum_required(VERSION 3.21) project(ffmini VERSION 0.0.1) set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Group CMake targets inside a folder set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Generate compile_commands.json for language servers include(FetchContent) FetchContent_Declare( fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git GIT_TAG 10.1.0 ) list(APPEND FETCH_CONTENTS fmt) FetchContent_Declare( asio GIT_REPOSITORY https://github.com/mononerv/asio.git GIT_TAG 1f9c5682840d3dc32e6f36f2e0f54a0e854e87d6 ) list(APPEND FETCH_CONTENTS asio) FetchContent_Declare( miniaudio GIT_REPOSITORY https://github.com/mononerv/miniaudio.git GIT_TAG v0.11.9 ) list(APPEND FETCH_CONTENTS miniaudio) FetchContent_MakeAvailable(${FETCH_CONTENTS}) # Group dependencies in Visual Studio and Xcode if (CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR MATCHES "Xcode") set_target_properties(fmt PROPERTIES FOLDER deps) set_target_properties(miniaudio_static PROPERTIES FOLDER deps) endif() set(BASE_DEFINITIONS "ASIO_STANDALONE") if (APPLE) set(PLATFORM_LINK_LIBRARIES "-framework Cocoa" "-framework IOKit" "-framework CoreVideo" "-framework OpenGL" ) elseif (UNIX AND NOT APPLE AND NOT EMSCRIPTEN) # Linux, BSD, Solaris, Minix set(PLATFORM_LINK_LIBRARIES "dl" "m" "GL" "X11" ) elseif (WIN32) list(APPEND BASE_DEFINITIONS "_WIN32_WINNT=0x0A00" ) set(PLATFORM_LINK_LIBRARIES "OpenGL32.lib") else() message(FATAL_ERROR "Unknown platform!") endif() # Compiler specific options if (NOT MSVC) set(BASE_OPTIONS "-Wall" "-Wextra" "-Wconversion" "-Wpedantic" "-Wshadow" "-Werror" # fmt warnings "-Wno-unknown-attributes" # asio "-Wno-sign-conversion" "-Wno-shadow" "-Wno-shorten-64-to-32" "-Wno-implicit-int-conversion" "-Wno-unused-private-field" "-Wno-deprecated-declarations" ) if (EMSCRIPTEN) list(APPEND BASE_OPTIONS # fmt warnings "-Wno-deprecated-literal-operator" ) endif() else() set(BASE_OPTIONS "/W4" "/WX" "/utf-8" "/Zc:__cplusplus" #"/fsanitize=address" # Doesn't work without Visual Studio ) endif() set(SOURCE_FILES "ffmini.cpp") add_executable(ffmini ${HEADER_FILES} ${SOURCE_FILES}) target_include_directories(ffmini PRIVATE ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/dsp ) target_compile_definitions(ffmini PRIVATE ${BASE_DEFINITIONS}) target_compile_features(ffmini PRIVATE cxx_std_20) target_compile_options(ffmini PRIVATE ${BASE_OPTIONS}) target_link_libraries(ffmini PRIVATE asio::asio fmt ) source_group(TREE "${CMAKE_CURRENT_LIST_DIR}" FILES ${SOURCE_FILES})