Skip to content

Commit

Permalink
feat: support cmake config-file and create cmake.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-LZW committed May 2, 2023
1 parent ed321b3 commit bcecf4e
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CMake

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: 'true'

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea
cmake-build*
Testing
.DS_Store
.cache
/.vs
Expand Down
61 changes: 58 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)

cmake_minimum_required(VERSION 3.12)
project(libstdaudio)
project(libstdaudio
VERSION 0.1.0
LANGUAGES CXX
)

set(CMAKE_CXX_STANDARD 17)
include(CheckIncludeFileCXX)

set(CMAKE_CXX_STANDARD 23)

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX")
Expand All @@ -18,6 +23,56 @@ if (APPLE)
set(CMAKE_EXE_LINKER_FLAGS "-framework CoreAudio")
endif ()

CHECK_INCLUDE_FILE_CXX(mdspan MDSPAN_EXIST)
if (NOT MDSPAN_EXIST)
add_subdirectory(third_party/mdspan)
endif()

add_library(audio INTERFACE)
add_library(std::audio ALIAS audio)
target_include_directories(audio INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(audio INTERFACE std::mdspan)

###################################################

install(TARGETS audio EXPORT audioTargets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(EXPORT audioTargets
FILE audioTargets.cmake
NAMESPACE std::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/audio
)

export(TARGETS audio
NAMESPACE std::
FILE audioTargets.cmake
)

install(DIRECTORY include/experimental DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/audioConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/audioConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/audio
)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/audioConfigVersion.cmake
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/audioConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/audioConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/audio
)

###################################################
# Test and Examples, move into their own directory
###################################################

include_directories(include)

add_executable(white_noise examples/white_noise.cpp)
Expand All @@ -29,4 +84,4 @@ add_executable(level_meter examples/level_meter.cpp)
add_executable(test
test/test_main.cpp
test/audio_buffer_test.cpp
test/audio_device_test.cpp)
test/audio_device_test.cpp)
3 changes: 3 additions & 0 deletions cmake/audioConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/audioTargets.cmake")

0 comments on commit bcecf4e

Please sign in to comment.