Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions cmake/Findsndfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# CMake config for systems with a CMake build of sndfile (i.e., windows with vcpkg)
find_package(LibSndFile QUIET CONFIG)

set(SNDFILE_CFLAGS)

if(LibSndFile_FOUND)
set(SNDFILE_INCLUDE_DIRS)
if(TARGET sndfile-shared AND (BUILD_SHARED_LIBS OR NOT TARGET sndfile-static))
set(SNDFILE_LIBRARIES sndfile-shared)
return()
elseif(TARGET sndfile-static)
set(SNDFILE_LIBRARIES sndfile-static)
return()
endif()
endif()

# pkgconfig for linux and other systems with pkgconfig
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_SNDFILE QUIET sndfile)
if(PC_SNDFILE_FOUND)
set(SNDFILE_INCLUDE_DIRS ${PC_SNDFILE_INCLUDEDIR} ${PC_SNDFILE_INCLUDEDIRS})
set(SNDFILE_LIBRARIES)
foreach(_LIB ${PC_SNDFILE_LIBRARIES})
find_library(SNDFILE_${_LIB}_LIBRARY ${_LIB} HINTS ${PC_SNDFILE_LIBDIR} ${PC_SNDFILE_LIBRARY_DIRS})
list(APPEND SNDFILE_LIBRARIES ${SNDFILE_${_LIB}_LIBRARY})
mark_as_advanced(SNDFILE_${_LIB}_LIBRARY)
endforeach()
foreach(_FLAG ${PC_SNDFILE_CFLAGS_OTHER})
set(SNDFILE_CFLAGS "${SNDFILE_CFLAGS} ${_FLAG}")
endforeach()
return()
endif()
endif()

# default find script may fail due to missing dependencies
find_path(SNDFILE_INCLUDE_DIR sndfile.h)
find_library(SNDFILE_LIBRARY NAMES sndfile sndfile-1 libsndfile libsndfile-1)
find_package_handle_standard_args(sndfile DEFAULT_MSG SNDFILE_LIBRARY SNDFILE_INCLUDE_DIR)
mark_as_advanced(SNDFILE_INCLUDE_DIR SNDFILE_LIBRARY)

set(SNDFILE_INCLUDE_DIRS ${SNDFILE_INCLUDE_DIR})
set(SNDFILE_LIBRARIES ${SNDFILE_LIBRARY})
46 changes: 0 additions & 46 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,3 @@ macro(to_yes_no vars)
endif()
endforeach()
endmacro()

macro(if_empty_print_missing vars)
foreach(var ${ARGV})
if(NOT ${var})
set(${var} "<not set>")
endif()
endforeach()
endmacro()

function(to_space_list sc_list)
set(ret)
foreach(val ${${sc_list}})
set(ret "${ret} ${val}")
endforeach()
if(ret)
string(STRIP ${ret} ret)
set(${sc_list} "${ret}" PARENT_SCOPE)
endif()
endfunction()

macro(find_pkg_config prefix pkgname)
find_package(PkgConfig ${ARGV2})
if(PKG_CONFIG_FOUND)
pkg_check_modules(${prefix}_PKGCONF ${ARGV2} ${pkgname})
if(${${prefix}_PKGCONF_FOUND})
message(STATUS "${pkgname} library dirs: ${${prefix}_PKGCONF_LIBRARY_DIRS}")
message(STATUS "${pkgname} cflags: ${${prefix}_PKGCONF_CFLAGS_OTHER}")
message(STATUS "${pkgname} include dirs: ${${prefix}_PKGCONF_INCLUDE_DIRS}")
message(STATUS "${pkgname} libraries: ${${prefix}_PKGCONF_LIBRARIES}")
message(STATUS "${pkgname} ldflags: ${${prefix}_PKGCONF_LDFLAGS_OTHER}")

set(${prefix}_FOUND ${${prefix}_PKGCONF_FOUND})
set(${prefix}_CFLAGS ${${prefix}_PKGCONF_CFLAGS_OTHER})
to_space_list(${prefix}_CFLAGS)
set(${prefix}_INCLUDE_DIRS ${${prefix}_PKGCONF_INCLUDE_DIRS})
foreach(lib ${${prefix}_PKGCONF_LIBRARIES})
string(TOUPPER ${lib} LIB)
find_library(${prefix}_${LIB}_LIBRARY ${lib}
HINTS ${${prefix}_PKGCONF_LIBRARY_DIRS})
mark_as_advanced(${prefix}_${LIB}_LIBRARY)
list(APPEND ${prefix}_LIBRARIES ${${prefix}_${LIB}_LIBRARY})
endforeach()
list(APPEND ${prefix}_LIBRARIES ${${prefix}_PKGCONF_LDFLAGS_OTHER})
endif()
endif()
endmacro()
3 changes: 1 addition & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ cmake_minimum_required(VERSION 2.8.9)
set(ENABLE_TESTS OFF CACHE BOOL "Build test binaries, needs libsndfile")

if(ENABLE_TESTS)
find_package(PkgConfig REQUIRED)
find_pkg_config(SNDFILE sndfile REQUIRED)
find_package(sndfile REQUIRED)

include_directories(${EBUR128_INCLUDE_DIR})
include_directories(SYSTEM ${SNDFILE_INCLUDE_DIRS})
Expand Down
4 changes: 2 additions & 2 deletions test/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ double test_max_momentary(const char* filename) {
SF_INFO file_info;
SNDFILE* file;
sf_count_t nr_frames_read;
sf_count_t total_frames_read;
sf_count_t total_frames_read = 0;
ebur128_state* st = NULL;
double momentary;
double max_momentary = -HUGE_VAL;
Expand Down Expand Up @@ -198,7 +198,7 @@ double test_max_shortterm(const char* filename) {
SF_INFO file_info;
SNDFILE* file;
sf_count_t nr_frames_read;
sf_count_t total_frames_read;
sf_count_t total_frames_read = 0;
ebur128_state* st = NULL;
double shortterm;
double max_shortterm = -HUGE_VAL;
Expand Down