diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 7eb7f2297..b56cde4c3 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -10,28 +10,23 @@ jobs: include: - name: Ubuntu GCC os: ubuntu-latest - install_dir: ~/portaudio vcpkg_triplet: x64-linux cmake_generator: "Unix Makefiles" cmake_options: -DPA_USE_OSS=ON - -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake - name: Ubuntu MinGW os: ubuntu-latest - install_dir: ~/portaudio asio_sdk_cache_path: asiosdk.zip dependencies_extras: mingw-w64 - # FIXME: linking JACK fails with vcpkg. Switch the CMake toolchain file to use vcpkg. The - # toolchain file in this repository is not needed when using a MinGW triplet with vcpkg. vcpkg_triplet: x64-mingw-static cmake_generator: "Unix Makefiles" + # FIXME: linking vcpkg Jack fais due to MinGW-W64 linker assertion. Disable Jack for this build. cmake_options: -DPA_USE_ASIO=ON + -DPA_USE_JACK=OFF -DASIO_SDK_ZIP_PATH=asiosdk.zip - -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/i686-w64-mingw32.cmake - name: Windows MSVC os: windows-latest - install_dir: C:\portaudio vcpkg_triplet: x64-windows cmake_generator: "Visual Studio 17 2022" # ASIO_SDK_ZIP_PATH needs to be quoted or CMake will save the download to @@ -41,10 +36,8 @@ jobs: cmake_options: -DPA_USE_ASIO=ON -DASIO_SDK_ZIP_PATH="asiosdk.zip" - -DCMAKE_TOOLCHAIN_FILE=D:\a\portaudio\portaudio\vcpkg\scripts\buildsystems\vcpkg.cmake - name: Windows MinGW os: windows-latest - install_dir: C:\portaudio vcpkg_triplet: x64-mingw-static cmake_generator: "MinGW Makefiles" # ASIO_SDK_ZIP_PATH needs to be quoted or CMake will save the download to @@ -54,61 +47,57 @@ jobs: cmake_options: -DPA_USE_ASIO=ON -DASIO_SDK_ZIP_PATH="asiosdk.zip" - -DCMAKE_TOOLCHAIN_FILE=D:\a\portaudio\portaudio\vcpkg\scripts\buildsystems\vcpkg.cmake - name: macOS Clang os: macOS-latest - install_dir: ~/portaudio vcpkg_triplet: x64-osx cmake_generator: "Unix Makefiles" cmake_options: -DCMAKE_FRAMEWORK=OFF - -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake - name: macOS Clang framework os: macOS-latest - install_dir: ~/portaudio vcpkg_triplet: x64-osx cmake_generator: "Unix Makefiles" cmake_options: -DCMAKE_FRAMEWORK=ON - -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake runs-on: ${{ matrix.os }} name: ${{ matrix.name }} env: cmake_build_type: RelWithDebInfo steps: - - name: checkout Git repository + - name: Checkout PortAudio Git repository uses: actions/checkout@v2 - - name: "[Ubuntu] install dependencies" + - name: "Install dependencies [Ubuntu]" run: | sudo apt-get update sudo apt-get install libasound2-dev libpulse-dev ${{ matrix.dependencies_extras }} if: matrix.os == 'ubuntu-latest' - - name: "[macOS] install dependencies" - # https://github.com/PortAudio/portaudio/issues/767 - run: brew install pkg-config - if: matrix.os == 'macOS-latest' - - name: "[Windows/MinGW] set up ASIO SDK cache" + - name: "Set up ASIO SDK cache [Windows/MinGW]" uses: actions/cache@v2 if: matrix.asio_sdk_cache_path != null with: path: ${{ matrix.asio_sdk_cache_path }} key: ${{ hashFiles('.github/asiosdk-version.txt') }} + - name: Setup vcpkg uses: lukka/run-vcpkg@v7 if: ${{ matrix.vcpkg_triplet }} != null with: + vcpkgDirectory: ${{ github.workspace }}/../vcpkg vcpkgTriplet: ${{ matrix.vcpkg_triplet }} appendedCacheKey: ${{ hashFiles( '**/vcpkg.json' ) }} additionalCachedPaths: build/vcpkg_installed - vcpkgGitCommitId: f30786c9c4c901f21a13e2d524349e39cc359a90 + # vcpkg commit: [libxml2] Fix ICU support option, hash: ca9ac0b, date: Dec 1, 2023, https://github.com/microsoft/vcpkg/commits + vcpkgGitCommitId: ca9ac0ba65965937fb66783c4f726c2c755ad9d9 # Required when using vcpkg.json manifest in repository setupOnly: true - - name: configure + + - name: Configure PortAudio library run: cmake -G "${{ matrix.cmake_generator }}" ${{ matrix.cmake_options }} - -DCMAKE_INSTALL_PREFIX=${{ matrix.install_dir }} + -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/../vcpkg/scripts/buildsystems/vcpkg.cmake + -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/../out -DCMAKE_BUILD_TYPE=${{ env.cmake_build_type }} -DVCPKG_TARGET_TRIPLET=${{ matrix.vcpkg_triplet }} -DPA_USE_SKELETON=ON @@ -116,13 +105,24 @@ jobs: -DPA_BUILD_EXAMPLES=ON -DPA_WARNINGS_ARE_ERRORS=ON -S . - -B build - - name: build - run: cmake --build build --config ${{ env.cmake_build_type }} --parallel 2 - - name: install - run: cmake --install build --config ${{ env.cmake_build_type }} - - name: "Upload GitHub Actions artifacts" - uses: actions/upload-artifact@v2 - with: - name: ${{ matrix.name }} PortAudio build - path: ${{ matrix.install_dir }} + -B ${{ github.workspace }}/build + - name: Build PortAudio library + run: cmake --build ${{ github.workspace }}/build --config ${{ env.cmake_build_type }} --parallel 4 + - name: Install PortAudio library + run: cmake --install ${{ github.workspace }}/build --config ${{ env.cmake_build_type }} + + # Required for vcpkg packages to be found by CMake's find_package() + - name: Enter build-test + run: cd ${{ github.workspace }}/test/test_use_cmake + - name: Configure build-test + run: cmake + -G "${{ matrix.cmake_generator }}" + ${{ matrix.cmake_options }} + -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/../vcpkg/scripts/buildsystems/vcpkg.cmake + -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/../out + -DCMAKE_BUILD_TYPE=${{ env.cmake_build_type }} + -DVCPKG_TARGET_TRIPLET=${{ matrix.vcpkg_triplet }} + -S . + -B ${{ github.workspace }}/build-test + - name: Build build-test + run: cmake --build ${{ github.workspace }}/build-test --config ${{ env.cmake_build_type }} diff --git a/CMakeLists.txt b/CMakeLists.txt index fff8af999..bd2d243fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -386,6 +386,11 @@ elseif(UNIX) endif() endif() +# Make sure PA_USE_ALSA is available as it is used for PortAudioConfig.cmake configuration +if (NOT PA_USE_ALSA) + set(PA_USE_ALSA OFF) +endif() + # Add public headers to sources of PortAudio (used by some IDEs to list them in project tree) source_group("Public Header Files" FILES ${PORTAUDIO_PUBLIC_HEADERS}) target_sources(PortAudio PRIVATE ${PORTAUDIO_PUBLIC_HEADERS}) diff --git a/cmake/PortAudioConfig.cmake.in b/cmake/PortAudioConfig.cmake.in index ce50d159d..640337df1 100644 --- a/cmake/PortAudioConfig.cmake.in +++ b/cmake/PortAudioConfig.cmake.in @@ -8,11 +8,13 @@ include(CMakeFindDependencyMacro) find_dependency(Threads) -if("@PA_USE_JACK@") +# PA_USE_JACK +if(@PA_USE_JACK@) find_dependency(Regex) find_dependency(JACK) endif() -if("@PA_USE_ALSA@") +# PA_USE_ALSA +if(@PA_USE_ALSA@) find_dependency(ALSA) endif() diff --git a/cmake/toolchains/i686-w64-mingw32.cmake b/cmake/toolchains/i686-w64-mingw32.cmake deleted file mode 100644 index 2a2c7bfc4..000000000 --- a/cmake/toolchains/i686-w64-mingw32.cmake +++ /dev/null @@ -1,17 +0,0 @@ -# CMake Toolchain file for cross-compiling PortAudio to i686-w64-mingw32 -# Inspired from: https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/cross_compiling/Mingw -# Example usage: $ cmake -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/i686-w64-mingw32.cmake . -# i686-w64-mingw32 needs to be installed for this to work. On Debian-based -# distributions the package is typically named `mingw-w64`. - -SET(CMAKE_SYSTEM_NAME Windows) - -SET(CMAKE_C_COMPILER i686-w64-mingw32-gcc) -SET(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) -SET(CMAKE_RC_COMPILER i686-w64-mingw32-windres) - -SET(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) - -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/test/test_use_cmake/CMakeLists.txt b/test/test_use_cmake/CMakeLists.txt new file mode 100644 index 000000000..317752ce8 --- /dev/null +++ b/test/test_use_cmake/CMakeLists.txt @@ -0,0 +1,30 @@ +# This test checks that it is possible to use the +# CMake artifacts generated by the build. + +cmake_minimum_required(VERSION 3.1.0) +project(test_use) + +file(GENERATE + OUTPUT + "${CMAKE_CURRENT_BINARY_DIR}/main.cpp" + CONTENT + [=[ +#include +int main() +{ + Pa_Initialize(); + Pa_Terminate(); +} +]=] +) + +find_package(PortAudio REQUIRED) + +add_library(test_use_static STATIC "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +add_library(test_use_shared SHARED "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") +add_executable(test_use_exe "${CMAKE_CURRENT_BINARY_DIR}/main.cpp") + +target_link_libraries(test_use_static PRIVATE PortAudio::PortAudio) +target_link_libraries(test_use_shared PRIVATE PortAudio::PortAudio) +target_link_libraries(test_use_exe PRIVATE PortAudio::PortAudio) +