Skip to content

Commit

Permalink
fix(build): Build samples when generating SDK binaries.
Browse files Browse the repository at this point in the history
  • Loading branch information
na2axl committed Nov 5, 2023
1 parent 4efed9b commit fb5f2a7
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 36 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
40 changes: 16 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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})
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion cmake/FindAmplitudeAudioSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
15 changes: 14 additions & 1 deletion samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
6 changes: 6 additions & 0 deletions samples/sample_01/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion samples/sample_01/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions samples/sample_02/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_NAME_IF_EXISTS:SDL2::SDL2main> $<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>
PUBLIC Static
Expand Down
8 changes: 4 additions & 4 deletions samples/sample_02/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ const Uint32 kDelayMilliseconds = static_cast<Uint32>(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;
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions tools/amac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

cmake_minimum_required(VERSION 3.20)

project(amac)

set(AMC_SRC
Expand All @@ -28,3 +29,8 @@ target_link_libraries(amac
add_dependencies(amac
Static
)

install(
TARGETS amac
RUNTIME DESTINATION ${AM_BIN_DESTINATION}
)

0 comments on commit fb5f2a7

Please sign in to comment.