Skip to content

Commit

Permalink
Add AudioFile.h in cmake library interface
Browse files Browse the repository at this point in the history
  • Loading branch information
alxarsenault committed Oct 28, 2023
1 parent bcb61a4 commit 8f5cd73
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 32 deletions.
16 changes: 6 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ option (BUILD_TESTS "Build tests" ON)
option (BUILD_EXAMPLES "Build examples" ON)

#===============================================================================
add_library (${PROJECT_NAME} INTERFACE)
set (AUDIOFILE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/AudioFile.h)
source_group (TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${AUDIOFILE_SOURCES})

#===============================================================================
if(MSVC)
# needed for M_PI macro
add_definitions(-D_USE_MATH_DEFINES)
endif()
add_library (${PROJECT_NAME} INTERFACE ${AUDIOFILE_SOURCES})

#===============================================================================
target_include_directories (
${PROJECT_NAME}
INTERFACE $<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_include_directories (${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

#===============================================================================
target_compile_features (${PROJECT_NAME} INTERFACE cxx_std_17)
Expand Down
15 changes: 10 additions & 5 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
include_directories (${AudioFile_SOURCE_DIR})

add_definitions (-DPROJECT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}")
file (COPY test-audio.wav DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

add_executable (Examples examples.cpp)
target_link_libraries (Examples AudioFile)
set (AUDIOFILE_EXAMPLE Example)

file (GLOB AUDIOFILE_EXAMPLES_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
source_group (TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${AUDIOFILE_EXAMPLES_SOURCES})

add_executable (${AUDIOFILE_EXAMPLE} ${AUDIOFILE_EXAMPLES_SOURCES})
target_link_libraries (${AUDIOFILE_EXAMPLE} PUBLIC AudioFile)
target_compile_definitions (${AUDIOFILE_EXAMPLE} PUBLIC
-D_USE_MATH_DEFINES # needed for M_PI macro
-DPROJECT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}")
2 changes: 1 addition & 1 deletion tests/AiffLoadingTests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "doctest.h"
#include "doctest/doctest.h"
#include <iostream>
#include <vector>
#include <AudioFile.h>
Expand Down
24 changes: 13 additions & 11 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
include_directories (doctest)
include_directories (${AudioFile_SOURCE_DIR})

add_definitions(-DPROJECT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}")

file (COPY test-audio DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/audio-write-tests)

add_executable (Tests main.cpp GeneralTests.cpp WavLoadingTests.cpp AiffLoadingTests.cpp FileWritingTests.cpp SampleConversionTests.cpp)
target_compile_features (Tests PRIVATE cxx_std_17)
add_test (NAME Tests COMMAND Tests)
set (AUDIOFILE_TESTS Tests)

file (GLOB AUDIOFILE_TESTS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
source_group (TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${AUDIOFILE_TESTS_SOURCES})

add_executable (${AUDIOFILE_TESTS} ${AUDIOFILE_TESTS_SOURCES})
target_include_directories (${AUDIOFILE_TESTS} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries (${AUDIOFILE_TESTS} PUBLIC AudioFile)
target_compile_features (${AUDIOFILE_TESTS} PRIVATE cxx_std_17)
target_compile_definitions (${AUDIOFILE_TESTS} PUBLIC
-D_USE_MATH_DEFINES # needed for M_PI macro
-DPROJECT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}")

# add_executable (LoadingTests main.cpp WavLoadingTests.cpp AiffLoadingTests.cpp)
# target_compile_features (LoadingTests PRIVATE cxx_std_17)
# add_test (NAME LoadingTests COMMAND LoadingTests)
add_test (NAME ${AUDIOFILE_TESTS} COMMAND ${AUDIOFILE_TESTS})
2 changes: 1 addition & 1 deletion tests/FileWritingTests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "doctest.h"
#include "doctest/doctest.h"
#include <iostream>
#include <vector>
#include <cmath>
Expand Down
2 changes: 1 addition & 1 deletion tests/GeneralTests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "doctest.h"
#include "doctest/doctest.h"
#include <iostream>
#include <vector>
#include <math.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/SampleConversionTests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "doctest.h"
#include "doctest/doctest.h"
#include <iostream>
#include <vector>
#include <AudioFile.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/WavLoadingTests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "doctest.h"
#include "doctest/doctest.h"
#include <iostream>
#include <vector>
#include <AudioFile.h>
Expand Down
2 changes: 1 addition & 1 deletion tests/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#define DOCTEST_CONFIG_COLORS_NONE
#include "doctest.h"
#include "doctest/doctest.h"

0 comments on commit 8f5cd73

Please sign in to comment.