duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

CMakeLists.txt (5644B)


      1 # TODO
      2 # - backend selection via command line, rather than simply detecting headers.
      3 
      4 cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
      5 project(cubeb C CXX)
      6 
      7 option(LAZY_LOAD_LIBS "Lazily load shared libraries" ON)
      8 
      9 if(NOT CMAKE_BUILD_TYPE)
     10   set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
     11       "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
     12 endif()
     13 
     14 set(CMAKE_C_STANDARD 99)
     15 set(CMAKE_CXX_STANDARD 17)
     16 set(CMAKE_CXX_STANDARD_REQUIRED ON)
     17 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
     18 
     19 set(CMAKE_CXX_WARNING_LEVEL 4)
     20 if(NOT MSVC)
     21   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter")
     22   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -fno-exceptions -fno-rtti")
     23 else()
     24   string(REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # Disable RTTI
     25   string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # Disable Exceptions
     26 endif()
     27 
     28 add_library(cubeb
     29   src/cubeb.c
     30   src/cubeb_mixer.cpp
     31   src/cubeb_resampler.cpp
     32   src/cubeb_log.cpp
     33   src/cubeb_strings.c
     34   src/cubeb_utils.cpp
     35 )
     36 target_include_directories(cubeb
     37   PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>
     38 )
     39 
     40   add_library(speex OBJECT subprojects/speex/resample.c)
     41   set_target_properties(speex PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
     42   target_include_directories(speex INTERFACE subprojects)
     43   target_compile_definitions(speex PUBLIC
     44     OUTSIDE_SPEEX
     45     FLOATING_POINT
     46     EXPORT=
     47     RANDOM_PREFIX=speex
     48   )
     49 
     50 # $<BUILD_INTERFACE:> required because of https://gitlab.kitware.com/cmake/cmake/-/issues/15415
     51 target_link_libraries(cubeb PRIVATE $<BUILD_INTERFACE:speex>)
     52 
     53 include(CheckIncludeFiles)
     54 
     55 # Threads needed by cubeb_log, _pulse, _alsa, _jack, _sndio, _oss and _sun
     56 set(THREADS_PREFER_PTHREAD_FLAG ON)
     57 find_package(Threads)
     58 target_link_libraries(cubeb PRIVATE Threads::Threads)
     59 
     60 if(LAZY_LOAD_LIBS)
     61   if(NOT APPLE AND NOT WIN32) # Skip checks on MacOS because it takes ages in XCode.
     62   check_include_files(pulse/pulseaudio.h USE_PULSE)
     63   check_include_files(alsa/asoundlib.h   USE_ALSA)
     64   check_include_files(jack/jack.h        USE_JACK)
     65   check_include_files(sndio.h            USE_SNDIO)
     66 
     67   if(USE_PULSE OR USE_ALSA OR USE_JACK OR USE_SNDIO OR USE_AAUDIO)
     68     target_link_libraries(cubeb PRIVATE ${CMAKE_DL_LIBS})
     69 
     70     if(ANDROID)
     71       target_compile_definitions(cubeb PRIVATE __ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__)
     72     endif()
     73   endif()
     74   endif()
     75 
     76 elseif(NOT APPLE AND NOT WIN32)
     77 
     78   find_package(PkgConfig REQUIRED)
     79 
     80   pkg_check_modules(libpulse IMPORTED_TARGET libpulse)
     81   if(libpulse_FOUND)
     82     set(USE_PULSE ON)
     83     target_compile_definitions(cubeb PRIVATE DISABLE_LIBPULSE_DLOPEN)
     84     target_link_libraries(cubeb PRIVATE PkgConfig::libpulse)
     85   endif()
     86 
     87   pkg_check_modules(alsa IMPORTED_TARGET alsa)
     88   if(alsa_FOUND)
     89     set(USE_ALSA ON)
     90     target_compile_definitions(cubeb PRIVATE DISABLE_LIBASOUND_DLOPEN)
     91     target_link_libraries(cubeb PRIVATE PkgConfig::alsa)
     92   endif()
     93 
     94   pkg_check_modules(jack IMPORTED_TARGET jack)
     95   if(jack_FOUND)
     96     set(USE_JACK ON)
     97     target_compile_definitions(cubeb PRIVATE DISABLE_LIBJACK_DLOPEN)
     98     target_link_libraries(cubeb PRIVATE PkgConfig::jack)
     99   endif()
    100 
    101   check_include_files(sndio.h USE_SNDIO)
    102   if(USE_SNDIO)
    103     target_compile_definitions(cubeb PRIVATE DISABLE_LIBSNDIO_DLOPEN)
    104     target_link_libraries(cubeb PRIVATE sndio)
    105   endif()
    106 endif()
    107 
    108 if(USE_PULSE)
    109   target_sources(cubeb PRIVATE src/cubeb_pulse.c)
    110   target_compile_definitions(cubeb PRIVATE USE_PULSE)
    111 endif()
    112 
    113 if(USE_ALSA)
    114   target_sources(cubeb PRIVATE src/cubeb_alsa.c)
    115   target_compile_definitions(cubeb PRIVATE USE_ALSA)
    116 endif()
    117 
    118 if(USE_JACK)
    119   target_sources(cubeb PRIVATE src/cubeb_jack.cpp)
    120   target_compile_definitions(cubeb PRIVATE USE_JACK)
    121 endif()
    122 
    123 if(USE_SNDIO)
    124   target_sources(cubeb PRIVATE src/cubeb_sndio.c)
    125   target_compile_definitions(cubeb PRIVATE USE_SNDIO)
    126 endif()
    127 
    128 if(APPLE)
    129 check_include_files(AudioUnit/AudioUnit.h USE_AUDIOUNIT)
    130 if(USE_AUDIOUNIT)
    131   target_sources(cubeb PRIVATE
    132     src/cubeb_audiounit.cpp
    133     src/cubeb_osx_run_loop.cpp)
    134   target_compile_definitions(cubeb PRIVATE USE_AUDIOUNIT)
    135   target_link_libraries(cubeb PRIVATE "-framework AudioUnit" "-framework CoreAudio" "-framework CoreServices")
    136 endif()
    137 endif()
    138 
    139 if(WIN32)
    140 check_include_files(audioclient.h USE_WASAPI)
    141 if(USE_WASAPI)
    142   target_sources(cubeb PRIVATE
    143     src/cubeb_wasapi.cpp)
    144   target_compile_definitions(cubeb PRIVATE USE_WASAPI)
    145   target_link_libraries(cubeb PRIVATE ole32 ksuser)
    146 endif()
    147 
    148 check_include_files("windows.h;mmsystem.h" USE_WINMM)
    149 if(USE_WINMM)
    150   target_sources(cubeb PRIVATE
    151     src/cubeb_winmm.c)
    152   target_compile_definitions(cubeb PRIVATE USE_WINMM)
    153   target_link_libraries(cubeb PRIVATE winmm)
    154 endif()
    155 endif()
    156 
    157 if(NOT WIN32 AND NOT APPLE)
    158 check_include_files(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
    159 if(HAVE_SYS_SOUNDCARD_H)
    160   try_compile(USE_OSS "${PROJECT_BINARY_DIR}/compile_tests"
    161     ${PROJECT_SOURCE_DIR}/cmake/compile_tests/oss_is_v4.c)
    162   if(USE_OSS)
    163     # strlcpy is not available on BSD systems that use glibc,
    164     # like Debian kfreebsd, so try using libbsd if available
    165     include(CheckSymbolExists)
    166     check_symbol_exists(strlcpy string.h HAVE_STRLCPY)
    167     if(NOT HAVE_STRLCPY)
    168       pkg_check_modules(libbsd-overlay IMPORTED_TARGET libbsd-overlay)
    169       if(libbsd-overlay_FOUND)
    170         target_link_libraries(cubeb PRIVATE PkgConfig::libbsd-overlay)
    171         set(HAVE_STRLCPY true)
    172       endif()
    173     endif()
    174     if (HAVE_STRLCPY)
    175       target_sources(cubeb PRIVATE
    176         src/cubeb_oss.c)
    177       target_compile_definitions(cubeb PRIVATE USE_OSS)
    178     endif()
    179   endif()
    180 endif()
    181 endif()