From fb5f2a71e4ddfd9485a628473b80c422f932b7ca Mon Sep 17 00:00:00 2001 From: Axel Nana Date: Sun, 5 Nov 2023 13:42:48 +0100 Subject: [PATCH] fix(build): Build samples when generating SDK binaries. --- .github/workflows/cmake.yml | 9 ++++--- CMakeLists.txt | 40 +++++++++++++------------------ cmake/FindAmplitudeAudioSDK.cmake | 2 +- samples/CMakeLists.txt | 15 +++++++++++- samples/sample_01/CMakeLists.txt | 6 +++++ samples/sample_01/main.cpp | 2 +- samples/sample_02/CMakeLists.txt | 6 +++++ samples/sample_02/main.cpp | 8 +++---- tools/amac/CMakeLists.txt | 6 +++++ 9 files changed, 58 insertions(+), 36 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 23243136..1ca82432 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -167,16 +167,15 @@ jobs: shell: bash run: | mkdir build - mkdir lib cmake \ -S . \ -B build \ - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ -G "${{ matrix.config.generator }}" \ - -DCMAKE_INSTALL_PREFIX:PATH=lib \ + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ -DCMAKE_TOOLCHAIN_FILE:STRING="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" \ -DVCPKG_TARGET_TRIPLET:STRING="${{ matrix.config.target_triplet }}" \ - -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE + -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE \ + -DBUILD_SAMPLES:BOOL=TRUE - name: Build shell: bash @@ -190,7 +189,7 @@ jobs: - name: Pack shell: bash - run: ${{ matrix.config.archiver }} ./${{ matrix.build_type }}_${{ matrix.config.artifact }} LICENSE sdk + run: ${{ matrix.config.archiver }} ./${{ matrix.build_type }}_${{ matrix.config.artifact }} LICENSE README.md sdk - name: Upload uses: actions/upload-artifact@v1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ffd70e6..395be949 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,17 +34,25 @@ set(CMAKE_DEBUG_POSTFIX "_d") set(BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(OBJ_DIR ${CMAKE_CURRENT_BINARY_DIR}/obj) -if(MSVC) +if(MSVC OR WIN32) set(RUNTIME_OUTPUT_DIRECTORY "win") elseif(APPLE) set(RUNTIME_OUTPUT_DIRECTORY "osx") - set(CMAKE_MACOSX_RPATH 1) - set(CMAKE_INSTALL_RPATH "@executable_path") else() set(RUNTIME_OUTPUT_DIRECTORY "linux") - set(CMAKE_INSTALL_RPATH ".") endif() +set(AM_LIB_DESTINATION "lib/${RUNTIME_OUTPUT_DIRECTORY}") +set(AM_INC_DESTINATION "include") +set(AM_SHM_DESTINATION "schemas") +set(AM_BIN_DESTINATION "bin/${RUNTIME_OUTPUT_DIRECTORY}") + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${AM_BIN_DESTINATION}") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${AM_LIB_DESTINATION}") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${AM_BIN_DESTINATION}") + +set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/sdk") + if(UNIX) find_package(Threads REQUIRED) endif() @@ -326,6 +334,10 @@ target_compile_definitions(Static PUBLIC AM_BUILDSYSTEM_STATIC) add_library(Shared SHARED ${SA_SOURCE}) target_compile_definitions(Shared PUBLIC AM_BUILDSYSTEM_SHARED) +add_custom_target(amplitude_build_binary_schemas + COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/build_schemas.py --output ${CMAKE_CURRENT_SOURCE_DIR}/schemas +) + set(AM_BUILDSYSTEM_TYPE "Static" "Shared") foreach(build_type ${AM_BUILDSYSTEM_TYPE}) @@ -351,10 +363,6 @@ foreach(build_type ${AM_BUILDSYSTEM_TYPE}) endif() endforeach() -add_custom_target(amplitude_build_binary_schemas - COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/scripts/build_schemas.py --output ${CMAKE_CURRENT_SOURCE_DIR}/schemas -) - add_subdirectory(tools/amac) if(BUILD_SAMPLES) @@ -364,17 +372,6 @@ endif() # ##################################################### # INSTALL -set(AM_LIB_DESTINATION "lib/${RUNTIME_OUTPUT_DIRECTORY}") -set(AM_INC_DESTINATION "include") -set(AM_SHM_DESTINATION "schemas") -set(AM_BIN_DESTINATION "bin/${RUNTIME_OUTPUT_DIRECTORY}") - -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${AM_BIN_DESTINATION}") -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${AM_LIB_DESTINATION}") -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${AM_BIN_DESTINATION}") - -set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/sdk") - install( TARGETS Static EXPORT AmplitudeAudioSDKConfig @@ -389,11 +386,6 @@ install( RUNTIME DESTINATION ${AM_LIB_DESTINATION}/shared ) -install( - TARGETS amac - RUNTIME DESTINATION ${AM_BIN_DESTINATION} -) - install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${AM_INC_DESTINATION} diff --git a/cmake/FindAmplitudeAudioSDK.cmake b/cmake/FindAmplitudeAudioSDK.cmake index f32781fc..2d2d3cdc 100644 --- a/cmake/FindAmplitudeAudioSDK.cmake +++ b/cmake/FindAmplitudeAudioSDK.cmake @@ -61,7 +61,7 @@ set(AMPLITUDE_COMPILE_DEFINITIONS get_filename_component(AMPLITUDE_INSTALL_ROOT ${AM_SDK_PATH} DIRECTORY) get_filename_component(AMPLITUDE_FOLDER ${AM_SDK_PATH} NAME) -if(MSVC) +if(MSVC OR WIN32) set(AMPLITUDE_LIB_OS "win") set(AMPLITUDE_STATIC_LIB_NAME "Amplitude.lib") set(AMPLITUDE_STATIC_LIB_NAME_DEBUG "Amplitude_d.lib") diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 23ff7803..32f5b923 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -19,8 +19,21 @@ set(PROJECT_NAME ss_amplitude_audio_samples) project(${PROJECT_NAME}) add_custom_target(ss_amplitude_audio_sample_assets - COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/build_assets.py --output ${CMAKE_BINARY_DIR}/samples/assets + COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/build_assets.py --output ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/samples/assets +) + +add_dependencies(ss_amplitude_audio_sample_assets + amplitude_build_binary_schemas ) add_subdirectory(sample_01) add_subdirectory(sample_02) + +install( + CODE "execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/build_assets.py --output ${CMAKE_INSTALL_PREFIX}/${AM_BIN_DESTINATION}/samples/assets)" +) + +install( + TARGETS ss_amplitude_audio_sample_01 ss_amplitude_audio_sample_02 + RUNTIME DESTINATION ${AM_BIN_DESTINATION}/samples +) diff --git a/samples/sample_01/CMakeLists.txt b/samples/sample_01/CMakeLists.txt index 581c47d8..b81da782 100644 --- a/samples/sample_01/CMakeLists.txt +++ b/samples/sample_01/CMakeLists.txt @@ -24,6 +24,12 @@ set(ss_amplitude_audio_sample_01_SRCS add_executable(ss_amplitude_audio_sample_01 ${ss_amplitude_audio_sample_01_SRCS}) +set_target_properties(ss_amplitude_audio_sample_01 + PROPERTIES + OUTPUT_NAME sample_01 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/samples +) + target_link_libraries(${PROJECT_NAME} PUBLIC Static ) diff --git a/samples/sample_01/main.cpp b/samples/sample_01/main.cpp index 4493042b..fe24e5df 100644 --- a/samples/sample_01/main.cpp +++ b/samples/sample_01/main.cpp @@ -70,7 +70,7 @@ static void run(AmVoidPtr param) MemoryManager::Initialize(MemoryManagerConfig()); FileLoader loader = FileLoader(); - loader.SetBasePath(AM_OS_STRING("../assets")); + loader.SetBasePath(AM_OS_STRING("./assets")); amEngine->SetFileLoader(loader); diff --git a/samples/sample_02/CMakeLists.txt b/samples/sample_02/CMakeLists.txt index 9576a648..be363e19 100644 --- a/samples/sample_02/CMakeLists.txt +++ b/samples/sample_02/CMakeLists.txt @@ -26,6 +26,12 @@ set(ss_amplitude_audio_sample_SRCS add_executable(${PROJECT_NAME} ${ss_amplitude_audio_sample_SRCS}) +set_target_properties(ss_amplitude_audio_sample_02 + PROPERTIES + OUTPUT_NAME sample_02 + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/samples +) + target_link_libraries(${PROJECT_NAME} PRIVATE $ $,SDL2::SDL2,SDL2::SDL2-static> PUBLIC Static diff --git a/samples/sample_02/main.cpp b/samples/sample_02/main.cpp index 320846cc..e9d9fdda 100644 --- a/samples/sample_02/main.cpp +++ b/samples/sample_02/main.cpp @@ -61,9 +61,9 @@ const Uint32 kDelayMilliseconds = static_cast(kAmSecond * 1.0 / kFramesP const char* kWindowTitle = "Amplitude Audio SDK Sample"; AmOsString kAudioConfig = AM_OS_STRING("audio_config.amconfig"); AmOsString kSoundBank = AM_OS_STRING("sample_02.ambank"); -const char* kInstructionsTexture = "../assets/textures/instructions.bmp"; -const char* kChannelTexture = "../assets/textures/channel.bmp"; -const char* kListenerTexture = "../assets/textures/listener.bmp"; +const char* kInstructionsTexture = "./assets/textures/instructions.bmp"; +const char* kChannelTexture = "./assets/textures/channel.bmp"; +const char* kListenerTexture = "./assets/textures/listener.bmp"; const char* kSoundHandleName = "throw_collection_1"; int gListenerIdCounter = 0; @@ -225,7 +225,7 @@ bool SampleState::Initialize() MemoryManager::Initialize(MemoryManagerConfig()); - _loader.SetBasePath(AM_OS_STRING("../assets")); + _loader.SetBasePath(AM_OS_STRING("./assets")); amEngine->SetFileLoader(_loader); // Initialize Amplitude. diff --git a/tools/amac/CMakeLists.txt b/tools/amac/CMakeLists.txt index 2db2b78c..d5fe68d4 100644 --- a/tools/amac/CMakeLists.txt +++ b/tools/amac/CMakeLists.txt @@ -13,6 +13,7 @@ # limitations under the License. cmake_minimum_required(VERSION 3.20) + project(amac) set(AMC_SRC @@ -28,3 +29,8 @@ target_link_libraries(amac add_dependencies(amac Static ) + +install( + TARGETS amac + RUNTIME DESTINATION ${AM_BIN_DESTINATION} +)