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

Implement CMake build script #18

Closed
wants to merge 29 commits into from
Closed
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
698958a
Implement CMake build script
jcelerier Sep 5, 2019
8df1fb0
Fix CMakeLists.txt for MSVC (tested with Community 2017)
Nov 18, 2019
d16c179
Merge pull request #1 from mi-art/master
jcelerier Nov 19, 2019
d78ecf7
Accelerate framework
jcelerier Nov 25, 2019
09e31f7
Fixes for libsamplerate
jcelerier Nov 29, 2019
d10e4fd
Do not build for 10.7 as it uses libstdc++ instead of libc++ not avai…
jcelerier Dec 21, 2019
3c2d2c5
Lower minimum CMake version
jcelerier Mar 22, 2020
645e64f
Do not force speex on win32
jcelerier Mar 24, 2020
e639056
Fix cross-compilation to ARM
jcelerier Jun 24, 2020
8e09e4a
Put -march=native flag behind a CMake option
jcelerier Sep 7, 2020
478936a
Update CMakeLists.txt
jcelerier Jan 21, 2021
cc9540e
CMake: Add support for building windows DLL
Holzhaus Jan 21, 2021
15b2c29
CMake: Install header files
Holzhaus Jan 21, 2021
ba8b1cd
pkg-config: Use @PREFIX@ instead of %PREFIX%
Holzhaus Jan 21, 2021
ba3b4bc
CMake: Install pkgconfig file on Unix
Holzhaus Jan 21, 2021
9231a57
CMake: Add find_package() config
Holzhaus Jan 21, 2021
bf1b5a2
CMake: Remove wrong MSVC defines
Holzhaus Jan 21, 2021
26def5e
Merge branch 'master' of https://github.com/breakfastquay/rubberband
Holzhaus Jan 21, 2021
68b9483
CMake: Clean up and rework dependency logic
Holzhaus Jan 21, 2021
95f4e1e
CMake: Fix DLL build on Windows
Holzhaus Jan 21, 2021
ecb03c8
CMake: Add support for newer OSX_DEPLOYMENT_TARGET versions
Holzhaus Jan 21, 2021
d534181
CMake: Add support for the JNI interface
Holzhaus Jan 21, 2021
7b2ac36
CMake: fix include INSTALL_INTERFACE
Be-ing Jan 24, 2021
b7cea08
CMake: consolidate Apple-specific code
Be-ing Feb 2, 2021
e4ed0c2
CMake: combine platform-specific code with elseif
Be-ing Feb 2, 2021
719b80d
CMake: "kissFFT" -> "KISS FFT"
Be-ing Feb 2, 2021
e4ea785
CMake: search more names for libsamplerate
Be-ing Feb 3, 2021
51ed896
CMake: search more names for fftw
Be-ing Feb 3, 2021
5c8c7fe
GitHub Actions: add workflow using CMake on Ubuntu, Windows, macOS
Be-ing Feb 2, 2021
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
188 changes: 188 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(rubberband VERSION 2.1.1)

option(RUBBERBAND_EXAMPLE "Build the Rubberband example app" OFF)
option(RUBBERBAND_OPTIMIZED "Build Rubberband optimized for the build machine's CPU" OFF)
### Dependencies ###

# ARM cross-compilers do not support march=native, only mtune=native
set(MARCH_NATIVE_FLAG)

include(CheckCXXCompilerFlag)

if(RUBBERBAND_OPTIMIZED)
check_cxx_compiler_flag("-march=native" MARCH_NATIVE_SUPPORTED)
if(MARCH_NATIVE_SUPPORTED)
set(MARCH_NATIVE_FLAG "-march=native")
else()
endif()
endif()

find_package(Threads REQUIRED)

# FFTW3
find_path(FFTW3_INCLUDEDIR fftw3.h)
find_library(FFTW3_LIBRARY fftw3)

# libsamplerate
if(NOT TARGET samplerate)
find_path(SAMPLERATE_INCLUDEDIR samplerate.h)
find_library(SAMPLERATE_LIBRARY samplerate)
endif()

# Accelerate framework
if(APPLE)
find_library(ACCELERATE_FRAMEWORK NAMES Accelerate)
endif()

### Create our target ###
add_library(rubberband)

### Handle general flags, include paths, etc ###
target_compile_options(rubberband
PRIVATE
$<$<BOOL:${APPLE}>:-mmacosx-version-min=10.11>
$<$<AND:$<NOT:$<CXX_COMPILER_ID:MSVC>>,$<CONFIG:Release>>:-ffast-math ${MARCH_NATIVE_FLAG} -O3 -ftree-vectorize>
Copy link

@Holzhaus Holzhaus Jan 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally find these generator expressiong very hard to read. This would be much more straightforward IMHO:

Suggested change
target_compile_options(rubberband
PRIVATE
$<$<BOOL:${APPLE}>:-mmacosx-version-min=10.11>
$<$<AND:$<NOT:$<CXX_COMPILER_ID:MSVC>>,$<CONFIG:Release>>:-ffast-math ${MARCH_NATIVE_FLAG} -O3 -ftree-vectorize>
if(APPLE)
target_compile_options(rubberband PRIVATE -mmacosx-version-min=10.11)
endif()
if(NOT MSVC)
target_compile_options(rubberband PRIVATE $<CONFIG:Release:-ffast-math ${MARCH_NATIVE_FLAG} -O3 -ftree-vectorize>)
endif()

I'll open a PR.

)

target_compile_definitions(rubberband
PRIVATE
$<$<BOOL:${UNIX}>:USE_PTHREADS>
$<$<BOOL:${APPLE}>:HAVE_VDSP>
$<$<BOOL:$<CXX_COMPILER_ID:MSVC>>:__MSVC__ WIN32 _LIB NOMINMAX _USE_MATH_DEFINES USE_KISSFFT>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this specify USE_KISSFFT on MSVC in any case? We may be using FFTW3...

Also, if I understand that weird Microsoft XML thingy correctly, WIN32 is only specified for 32 bit builds, not all windows builds.

ANd the same applies here, I think an if/else ladder would be much more readable than all these genexprs.

$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:NDEBUG>
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Debug>>:_DEBUG NO_TIMING NO_THREAD_CHECKS>
MALLOC_IS_ALIGNED
NO_THREAD_CHECKS
NO_TIMING
)

target_include_directories(rubberband
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rubberband>
$<INSTALL_INTERFACE:rubberband>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
)

target_link_libraries(rubberband
PRIVATE
Threads::Threads
)

# Handle FFT library
if(FFTW3_INCLUDEDIR AND FFTW3_LIBRARY)
target_include_directories(rubberband
PRIVATE
${FFTW3_INCLUDEDIR}
)
target_compile_definitions(rubberband
PRIVATE
HAVE_FFTW3
FFTW_DOUBLE_ONLY
)
target_link_libraries(rubberband
PUBLIC
${FFTW3_LIBRARY}
)
else()
target_compile_definitions(rubberband
PRIVATE
USE_KISSFFT
)
target_sources(rubberband
PRIVATE
src/kissfft/kiss_fft.c
src/kissfft/kiss_fftr.c
)
endif()

# Apple framework
if(APPLE)
target_link_libraries(rubberband
PRIVATE
"${ACCELERATE_FRAMEWORK}"
)
endif()

# Handle resampling library
if(TARGET samplerate)
target_compile_definitions(rubberband
PRIVATE
HAVE_LIBSAMPLERATE
)

target_link_libraries(rubberband
PRIVATE
samplerate
)
elseif(SAMPLERATE_INCLUDEDIR AND SAMPLERATE_LIBRARY)
target_include_directories(rubberband
PRIVATE
${SAMPLERATE_INCLUDEDIR}
)
target_compile_definitions(rubberband
PRIVATE
HAVE_LIBSAMPLERATE
)
target_link_libraries(rubberband
PUBLIC
${SAMPLERATE_LIBRARY}
)
else()
target_compile_definitions(rubberband
PRIVATE
USE_SPEEX
)
target_sources(rubberband
PRIVATE
src/speex/resample.c
)
endif()

### Source files ###
target_sources(rubberband
PRIVATE
src/RubberBandStretcher.cpp
src/StretchCalculator.cpp
src/StretcherChannelData.cpp
src/StretcherImpl.cpp
src/StretcherProcess.cpp
src/audiocurves/CompoundAudioCurve.cpp
src/audiocurves/ConstantAudioCurve.cpp
src/audiocurves/HighFrequencyAudioCurve.cpp
src/audiocurves/PercussiveAudioCurve.cpp
src/audiocurves/SilentAudioCurve.cpp
src/audiocurves/SpectralDifferenceAudioCurve.cpp
src/base/Profiler.cpp
src/dsp/AudioCurveCalculator.cpp
src/dsp/FFT.cpp
src/dsp/Resampler.cpp
src/rubberband-c.cpp
src/system/Allocators.cpp
src/system/Thread.cpp
src/system/VectorOpsComplex.cpp
src/system/sysutils.cpp
)

### Example ###
if(RUBBERBAND_EXAMPLE)
add_executable(rubberband_test main/main.cpp)
target_include_directories(rubberband_test PRIVATE src Threads::Threads)
target_link_libraries(rubberband_test PRIVATE rubberband -lsndfile)
endif()

### Installation ###

include(GNUInstallDirs)
install(
TARGETS rubberband
EXPORT rubberband-exports
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(EXPORT rubberband-exports
DESTINATION lib/cmake/rubberband)
export(EXPORT rubberband-exports)