CMake for Audio and Speech Processing

Cmake Basic Files

Two Essential Lines

For any cmake project, we need to have a CMakeLists.txt file, there are two scripts are fixed:

line ``` is mostly about the ```cmake version```.
1
2
3

```cmake
cmake_minimum_required(VERSION 3.1)
line``` is the project name:
1
2
3

```camke
project(kaldi)

Include DIR

Next step is to call or include the DIRs you need, the DIR can be the environmental files or other files:

1
include_directories(${CMAKE_SOURCE_DIR}/include)
here means the current absolute path, ```include``` is the sub-directory.
1
2
3
4
5
6
7
8
9



## Executable CMake

After finish all the settings there, just use this line:

```cmake
add_executable(output_cmake_exe the_cpp_file.cpp the_cpp_file2.cpp)

An Example like include the gsl lib

1
2
3
4
5
6
7
8
9
10
11
12
13
        find_package(GSL)  # 查找包

        set(GSL_LIBS gsl;gslcblas;m) # 指定要包含的库

        message(STATUS "**GSL library status:"# 显示GSL的查找情况

        message(STATUS "    //version: ${GSL_VERSION}"

        message(STATUS "    //libraries: ${GSL_LIBS}")

        message(STATUS "    //include path: ${GSL_INCLUDE_DIRS}")

        target_link_libraries(stereo_matching ${GSL_LIBS})

or

1
2
3
4
5
6
7
8
9
10
cmake_minimum_required(VERSION 3.7)
project(Unitsv1)

set(SOURCE_FILES main.cpp
transition.cpp
random.cpp)
add_executable(Unitsv1 ${SOURCE_FILES})

find_package(GSL REQUIRED)
target_link_libraries(Unitsv1 GSL::gsl GSL::gslcblas)

https://solarianprogrammer.com/2020/01/26/getting-started-gsl-gnu-scientific-library-windows-macos-linux/

If we need to do in CLion, we need to include the dir:

1
2
3
4
5
6
7
8
set(INC_DIR /Users/haoran/Downloads/wfdb/include)
set(LINK_DIR /Users/haoran/Downloads/wfdb/lib)

include_directories(${INC_DIR})
link_directories(${LINK_DIR})
link_libraries(wfdb)

target_link_libraries(wfdb_demo wfdb)

Complete version looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cmake_minimum_required(VERSION 3.6)
project(wfdb_demo)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)

set(INC_DIR /Users/haoran/Downloads/wfdb/include)
set(LINK_DIR /Users/haoran/Downloads/wfdb/lib)

include_directories(${INC_DIR})
link_directories(${LINK_DIR})
link_libraries(wfdb)

add_executable(wfdb_demo ${SOURCE_FILES})
target_link_libraries(wfdb_demo wfdb)

Compile the code

1
2
3
cmake .
make -j
make install

Installation Steps

1
2
3
4
5
configure
make
make check
sudo make install
make installcheck

Configure the LIB environment

1
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

GCC

1
gcc -Wall -I/home/steve/dev/include -c example.c
1
gcc -L/home/steve/dev/lib example.o -lgsl -lgslcblas -lm
1
./a.out

VCPKG

Install VCPKG

1
2
3
4
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg integrate install

Install Libs with VCPKG

1
vcpkg install gsl gsl:x64-windows

Add targests to CMAKE

1
2
3
4
5

The package gsl is compatible with built-in CMake targets:

find_package(GSL REQUIRED)
target_link_libraries(main PRIVATE GSL::gsl GSL::gslcblas)

Some Great Open Resource tools

World: https://github.com/mmorise/World

Athena-signal processing open source library: https://github.com/athena-team/athena-signal

SPTK: https://github.com/sp-nitech/SPTK

WebRTC AEC AGC ANC NS示例: https://github.com/shichaog/WebRTC-audio-processing

AudioTutorials: https://github.com/BennyQBD/AudioTutorial

SoundTouch Audio Processing Library: https://www.surina.net/soundtouch/index.html

STRAIGHT Library (http://www.kisc.meiji.ac.jp/~mmorise/straight/english/)


CMake for Audio and Speech Processing
http://xiaos.site/2022/08/29/CMake-for-Audio-and-Speech-Processing/
Author
Xiao Zhang
Posted on
August 29, 2022
Licensed under