diff --git a/CMakeLists.txt b/CMakeLists.txt index da27b53..f1652cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,61 +1,36 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.8.9) +project(libebur128 C) -project(ebur128-loudness-tools) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) -add_subdirectory(ebur128) -add_subdirectory(scanner) - include(utils) +add_subdirectory(ebur128) +add_subdirectory(test) + -set(ENABLE_INTERNAL_QUEUE_H OFF CACHE BOOL "Use own queue.h") -set(DISABLE_SPEEXDSP OFF CACHE BOOL "Don't build with speexdsp") -set(DISABLE_GLIB20 OFF CACHE BOOL "Don't build with glib") -set(DISABLE_SNDFILE OFF CACHE BOOL "Don't build with sndfile") -set(DISABLE_TAGLIB OFF CACHE BOOL "Don't build with taglib") -set(DISABLE_MPG123 OFF CACHE BOOL "Don't build with mpg123") -set(DISABLE_MPCDEC OFF CACHE BOOL "Don't build with mpcdec") -set(DISABLE_GSTREAMER OFF CACHE BOOL "Don't build with gstreamer") -set(DISABLE_FFMPEG OFF CACHE BOOL "Don't build with ffmpeg") -set(DISABLE_RSVG2 OFF CACHE BOOL "Don't build with rsvg2") -set(DISABLE_GTK2 OFF CACHE BOOL "Don't build with gtk2") -set(DISABLE_QT4 OFF CACHE BOOL "Don't build with qt4") - -to_yes_no(SUMMARY_HAS_QUEUE SUMMARY_SPEEXDSP_FOUND SUMMARY_GLIB20_FOUND - SUMMARY_GTHREAD20_FOUND SUMMARY_SNDFILE_FOUND SUMMARY_TAGLIB_FOUND - SUMMARY_MPG123_FOUND SUMMARY_MPCDEC_FOUND SUMMARY_GSTREAMER_FOUND - SUMMARY_FFMPEG_FOUND SUMMARY_RSVG2_FOUND SUMMARY_GTK2_FOUND - SUMMARY_QT4_FOUND) -to_yes_no(DISABLE_SPEEXDSP DISABLE_GLIB20 DISABLE_SNDFILE DISABLE_TAGLIB - DISABLE_MPG123 DISABLE_MPCDEC DISABLE_GSTREAMER DISABLE_FFMPEG - DISABLE_RSVG2 DISABLE_GTK2 DISABLE_QT4) +to_yes_no(SUMMARY_HAS_QUEUE SUMMARY_SPEEXDSP_FOUND) +to_yes_no(DISABLE_SPEEXDSP) if(ENABLE_INTERNAL_QUEUE_H) - set(USE_QUEUE "using own copy of queue.h") + set(USE_QUEUE "using own copy of queue.h") else() - set(USE_QUEUE "using system copy of queue.h") + set(USE_QUEUE "using system copy of queue.h") endif() ##### Print status message(STATUS "status found / disabled --") message(STATUS "queue.h: ${SUMMARY_HAS_QUEUE}" " ${USE_QUEUE}") message(STATUS "speexdsp: ${SUMMARY_SPEEXDSP_FOUND}" " ${DISABLE_SPEEXDSP}") -message(STATUS "glib-2.0: ${SUMMARY_GLIB20_FOUND}" " ${DISABLE_GLIB20}") -message(STATUS "gthread-2.0: ${SUMMARY_GTHREAD20_FOUND}" " ${DISABLE_GLIB20}") -message(STATUS "sndfile: ${SUMMARY_SNDFILE_FOUND}" " ${DISABLE_SNDFILE}") -message(STATUS "taglib: ${SUMMARY_TAGLIB_FOUND}" " ${DISABLE_TAGLIB}") -message(STATUS "mpg123: ${SUMMARY_MPG123_FOUND}" " ${DISABLE_MPG123}") -message(STATUS "mpcdec: ${SUMMARY_MPCDEC_FOUND}" " ${DISABLE_MPCDEC}") -message(STATUS "gstreamer: ${SUMMARY_GSTREAMER_FOUND}" " ${DISABLE_GSTREAMER}") -message(STATUS "ffmpeg: ${SUMMARY_FFMPEG_FOUND}" " ${DISABLE_FFMPEG}") -message(STATUS "rsvg2: ${SUMMARY_RSVG2_FOUND}" " ${DISABLE_RSVG2}") -message(STATUS "gtk2: ${SUMMARY_GTK2_FOUND}" " ${DISABLE_GTK2}") -message(STATUS "qt4: ${SUMMARY_QT4_FOUND}" " ${DISABLE_QT4}") - if(NOT SUMMARY_HAS_QUEUE AND NOT ENABLE_INTERNAL_QUEUE_H) - message(FATAL_ERROR "queue.h not found, please set ENABLE_INTERNAL_QUEUE_H to ON") + message(FATAL_ERROR "queue.h not found, please set ENABLE_INTERNAL_QUEUE_H to ON") +endif() + +if(ENABLE_TESTS) + message(STATUS "building tests!") +else() + message(STATUS "not building tests, set ENABLE_TESTS to ON to enable") endif() diff --git a/README.md b/README.md index 9d8d6e2..fdc2f45 100644 --- a/README.md +++ b/README.md @@ -49,3 +49,6 @@ Usage Library usage should be pretty straightforward. All exported symbols are documented in the ebur128.h header file. For a usage example, see minimal-example.c in the tests folder. + +On some operating systems, static libraries should be compiled as position +independent code. You can enable that by turning on WITH\_STATIC\_PIC. diff --git a/cmake/utils.cmake b/cmake/utils.cmake index b37603d..b27c57b 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -26,3 +26,30 @@ function(to_space_list sc_list) 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() diff --git a/ebur128/CMakeLists.txt b/ebur128/CMakeLists.txt index fe196e5..20479ea 100644 --- a/ebur128/CMakeLists.txt +++ b/ebur128/CMakeLists.txt @@ -1,5 +1,9 @@ -cmake_minimum_required(VERSION 2.8) -project(ebur128 C) +cmake_minimum_required(VERSION 2.8.9) + +set(WITH_STATIC_PIC OFF CACHE BOOL "Compile static library with -fPIC flag") +set(ENABLE_INTERNAL_QUEUE_H OFF CACHE BOOL "Use own queue.h") +set(DISABLE_SPEEXDSP OFF CACHE BOOL "Don't build with speexdsp") + #### queue.h file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/queuetest.c @@ -16,15 +20,9 @@ endif() #### speexdsp if(NOT DISABLE_SPEEXDSP) - find_package(PkgConfig) - if(PKG_CONFIG_FOUND) - pkg_check_modules(SPEEXDSP speexdsp) - endif() - + find_pkg_config(SPEEXDSP speexdsp) if(SPEEXDSP_FOUND) include_directories(SYSTEM ${SPEEXDSP_INCLUDE_DIRS}) - link_directories(${SPEEXDSP_LIBRARY_DIRS}) - add_definitions(${SPEEXDSP_CFLAGS_OTHER}) add_definitions(-DUSE_SPEEX_RESAMPLER) endif() endif() @@ -34,20 +32,30 @@ if(MSVC) add_definitions(-D_USE_MATH_DEFINES) endif() + set(EBUR128_VERSION_MAJOR 1) set(EBUR128_VERSION 1.0.0) add_library(ebur128_static STATIC ebur128.c) -set_target_properties(ebur128_static PROPERTIES - OUTPUT_NAME ebur128) -set_target_properties(ebur128_static PROPERTIES - COMPILE_FLAGS "-fPIC") +set_property(TARGET ebur128_static PROPERTY OUTPUT_NAME ebur128) +if(WITH_STATIC_PIC) + set_property(TARGET ebur128_static PROPERTY POSITION_INDEPENDENT_CODE ON) +endif() + add_library(ebur128 SHARED ebur128.c) set_target_properties(ebur128 PROPERTIES SOVERSION ${EBUR128_VERSION_MAJOR} VERSION ${EBUR128_VERSION}) -target_link_libraries(ebur128 ${SPEEXDSP_LIBRARIES}) + +if(SPEEXDSP_FOUND AND NOT DISABLE_SPEEXDSP) + set_property(TARGET ebur128_static APPEND_STRING PROPERTY + COMPILE_FLAGS " ${SPEEXDSP_CFLAGS}") + set_property(TARGET ebur128 APPEND_STRING PROPERTY + COMPILE_FLAGS " ${SPEEXDSP_CFLAGS}") + target_link_libraries(ebur128 ${SPEEXDSP_LIBRARIES}) +endif() + set(SUMMARY_SPEEXDSP_FOUND ${SPEEXDSP_FOUND} CACHE INTERNAL "") set(EBUR128_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0a5cf7a..28716f0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,18 @@ -if(SNDFILE_FOUND) +cmake_minimum_required(VERSION 2.8.9) + +set(ENABLE_TESTS OFF CACHE BOOL "Build test binaries, needs libsndfile") + +if(ENABLE_TESTS) + find_pkg_config(SNDFILE sndfile REQUIRED) + + include_directories(${EBUR128_INCLUDE_DIR}) include_directories(SYSTEM ${SNDFILE_INCLUDE_DIRS}) - add_executable(r128-test-library tests.c) + add_executable(r128-test-library tests) + add_executable(minimal-example minimal-example) + set_property(TARGET r128-test-library APPEND_STRING PROPERTY + COMPILE_FLAGS " ${SNDFILE_CFLAGS}") + set_property(TARGET minimal-example APPEND_STRING PROPERTY + COMPILE_FLAGS " ${SNDFILE_CFLAGS}") target_link_libraries(r128-test-library ebur128 ${SNDFILE_LIBRARIES}) - add_test(test1 ${EXECUTABLE_OUTPUT_PATH}/r128-test-library) + target_link_libraries(minimal-example ebur128 ${SNDFILE_LIBRARIES}) endif()