Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake build system (based on previous work from @mdsitton and @jcelerier) and CI #24

Merged
merged 1 commit into from
Feb 3, 2018
Merged
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.cm*
# *.cm* # This line is broken it matches all files.
*.dat
*.gz
*.la
Expand Down Expand Up @@ -29,6 +29,7 @@ autom4te.cache
libsamplerate-*.tar.bz2
compile
config.*
!/config.h.in
configure
depcomp
doc/ChangeLog
Expand All @@ -53,3 +54,4 @@ tests/benchmark
tests/src-evaluate
*.log
*.trs
build/
14 changes: 11 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ before_install:
- sudo apt-get update
- sudo apt-get install -y autoconf automake-1.15 pkg-config m4 libsndfile-dev libfftw3-dev libasound2-dev

env:
- AUTOGEN=true CMAKE_SHARED=OFF
- AUTOGEN=false CMAKE_SHARED=ON

script:
- ./autogen.sh
- ./configure
- make distcheck
- if $AUTOGEN; then ./autogen.sh && ./configure && make distcheck; fi
- mkdir build
- cd build
- cmake -DBUILD_SHARED_LIBS=$CMAKE_SHARED ..
- cat config.h
- make
- make test
141 changes: 141 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
cmake_minimum_required(VERSION 3.1)
project(libsamplerate VERSION 0.1.9 LANGUAGES C)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)

include(TestBigEndian)
include(CheckFunctionExists)
include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckTypeSize)
include(ClipMode)

set(SAMPLERATE_SRC
${PROJECT_SOURCE_DIR}/src/samplerate.c
${PROJECT_SOURCE_DIR}/src/src_linear.c
${PROJECT_SOURCE_DIR}/src/src_sinc.c
${PROJECT_SOURCE_DIR}/src/src_zoh.c)

if(WIN32)
set(OS_IS_WIN32 TRUE)
set(SAMPLERATE_SRC
${SAMPLERATE_SRC}
${PROJECT_SOURCE_DIR}/Win32/libsamplerate-0.def)
include_directories(Win32)
endif()

test_big_endian(CPU_IS_BIG_ENDIAN)
if(CPU_IS_BIG_ENDIAN)
set(CPU_IS_LITTLE_ENDIAN 0)
else()
set(CPU_IS_LITTLE_ENDIAN 1)
endif()

check_function_exists(pow RESULT)
if(NOT RESULT)
list(APPEND CMAKE_REQUIRED_LIBRARIES m)
set(NEED_MATH)
endif()
check_function_exists(alarm HAVE_ALARM)
check_function_exists(lrint HAVE_LRINT)
check_function_exists(lrintf HAVE_LRINTF)
check_function_exists(signal HAVE_SIGNAL)

check_include_files(stdint.h HAVE_STDINT)
check_include_files(sys/times.h HAVE_SYS_TIMES_H)

check_symbol_exists(SIGALRM signal.h HAVE_SIGALRM)

check_type_size(int SIZEOF_INT)
check_type_size(long SIZEOF_LONG)

# This will set CPU_CLIPS_NEGATIVE and CPU_CLIPS_POSITIVE
clip_mode()

find_package(ALSA)
set(HAVE_ALSA ${ALSA_FOUND})
if(ALSA_FOUND)
include_directories("${ALSA_INCLUDE_DIR}")
endif()

find_package(Sndfile)
set(HAVE_SNDFILE ${SNDFILE_FOUND})
if(SNDFILE_FOUND)
include_directories("${SNDFILE_INCLUDE_DIR}")
endif()

find_package(FFTW)
set(HAVE_FFTW3 ${FFTW_FOUND})
if(FFTW_FOUND)
include_directories("${FFTW_INCLUDE_DIR}")
endif()

configure_file(${PROJECT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)

add_library(samplerate ${SAMPLERATE_SRC})

if(BUILD_SHARED_LIBS AND WIN32)
if (MSVC)
set_target_properties(samplerate PROPERTIES OUTPUT_NAME "libsamplerate-0")
else()
set_target_properties(samplerate PROPERTIES OUTPUT_NAME "samplerate-0")
endif()
endif()

target_include_directories(samplerate PUBLIC
${PROJECT_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR})

enable_testing()

file(GLOB TEST_SRCS ${PROJECT_SOURCE_DIR}/tests/*_test.c)

foreach(testSrc ${TEST_SRCS})
get_filename_component(testName ${testSrc} NAME_WE)
add_executable(${testName}
${testSrc}
${PROJECT_SOURCE_DIR}/tests/util.c
${PROJECT_SOURCE_DIR}/tests/calc_snr.c)
target_link_libraries(${testName} PUBLIC samplerate ${CMAKE_REQUIRED_LIBRARIES})
if(FFTW_FOUND)
target_link_libraries(${testName} PUBLIC ${FFTW_LIBRARY})
endif()
add_test(NAME ${testName} COMMAND ${testName})
endforeach(testSrc)

set(EXAMPLE_SRCS
${PROJECT_SOURCE_DIR}/examples/sndfile-resample.c
${PROJECT_SOURCE_DIR}/examples/timewarp-file.c
${PROJECT_SOURCE_DIR}/examples/varispeed-play.c)

foreach(exampleSrc ${EXAMPLE_SRCS})
get_filename_component(exampleName ${exampleSrc} NAME_WE)
add_executable(${exampleName}
${exampleSrc}
${PROJECT_SOURCE_DIR}/examples/audio_out.c)
target_link_libraries(${exampleName} PUBLIC samplerate ${CMAKE_REQUIRED_LIBRARIES})
if(ALSA_FOUND)
target_link_libraries(${exampleName} PUBLIC ${ALSA_LIBRARY})
endif()
if(SNDFILE_FOUND)
target_link_libraries(${exampleName} PUBLIC ${SNDFILE_LIBRARY})
endif()
if(WIN32)
target_link_libraries(${exampleName} PUBLIC winmm)
endif()
endforeach(exampleSrc)

set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(includedir "\${prefix}/include")
set(libdir "\${exec_prefix}/lib")
set(VERSION "${PROJECT_VERSION}")
if(NEED_MATH)
set(LIBS "-lm")
endif()
configure_file(samplerate.pc.in samplerate.pc @ONLY)

install(TARGETS samplerate DESTINATION lib)
install(FILES src/samplerate.h DESTINATION include)
install(DIRECTORY doc/ DESTINATION share/doc/libsamplerate)
install(FILES ${CMAKE_BINARY_DIR}/samplerate.pc DESTINATION lib/pkgconfig)
11 changes: 11 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ the following three commands :
make
make install

CMake
-----
There is a new CMake-based build system available:
mkdir build
cd build
cmake ..
make

Use `cmake -DCMAKE_BUILD_TYPE=Release ..` to make a release build.
Use `cmake -DBUILD_SHARED_LIBS=ON ..` to build a shared library.

CONTACTS
--------

Expand Down
197 changes: 0 additions & 197 deletions Win32/config.h

This file was deleted.

Loading