Skip to content

Commit

Permalink
Restructured Cmake build
Browse files Browse the repository at this point in the history
  • Loading branch information
hbe72 committed May 14, 2018
1 parent d907c0c commit 5abf854
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 114 deletions.
99 changes: 21 additions & 78 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
cmake_minimum_required(VERSION 3.7.2)
project(dsp)
project(Cdsp)
include("cmake/common.cmake")

set(Cnl_DESTDIR ${CMAKE_BINARY_DIR}/install)
file(MAKE_DIRECTORY ${Cnl_DESTDIR})

ExternalProject_Add(
Cnl
PREFIX ${CMAKE_BINARY_DIR}/Cnl
Expand All @@ -10,88 +13,28 @@ ExternalProject_Add(
GIT_SHALLOW 1
GIT_PROGRESS 1
UPDATE_COMMAND ""
INSTALL_COMMAND ""
)
######################################################################
# add_cnl_dependency
function(add_cnl_dependency target)
# gtest
ExternalProject_Get_Property(Cnl source_dir)
target_include_directories("${target}" SYSTEM PRIVATE "${source_dir}/include")
add_dependencies("${target}" Cnl)
endfunction(add_cnl_dependency)

# Google Test
ExternalProject_Add(
GoogleTest
PREFIX ${CMAKE_BINARY_DIR}/GoogleTest
URL "https://github.com/google/googletest/archive/3a4cf1a02ef4adc28fccb7eef2b573b14cd59009.zip"
URL_MD5 "06ac495303fbe94b198026e3c196425e"
UPDATE_COMMAND ""
INSTALL_COMMAND ""
CMAKE_ARGS -Dgtest_force_shared_crt=ON
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${Cnl_DESTDIR}"
)

######################################################################
# add_gtest_dependency
function(add_gtest_dependency target)
# gtest
ExternalProject_Get_Property(GoogleTest binary_dir)
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
target_link_libraries(
"${target}"
debug ${binary_dir}/googlemock/gtest/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}gtestd${CMAKE_FIND_LIBRARY_SUFFIXES}
debug ${binary_dir}/googlemock/gtest/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_maind${CMAKE_FIND_LIBRARY_SUFFIXES}
optimized ${binary_dir}/googlemock/gtest/Release/${CMAKE_FIND_LIBRARY_PREFIXES}gtest${CMAKE_FIND_LIBRARY_SUFFIXES}
optimized ${binary_dir}/googlemock/gtest/Release/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main${CMAKE_FIND_LIBRARY_SUFFIXES}
)
else ()
target_link_libraries(
"${target}"
general "${binary_dir}/googlemock/gtest/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a"
general "${binary_dir}/googlemock/gtest/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a"
general pthread
)
endif ()

ExternalProject_Get_Property(GoogleTest source_dir)
target_include_directories("${target}" SYSTEM PRIVATE "${source_dir}/googletest/include")

add_dependencies("${target}" GoogleTest)
endfunction(add_gtest_dependency)

# runs a suite of compile-time tests using `static_assert`
# and run-time tests using gtest
include(CTest)
add_subdirectory("test" EXCLUDE_FROM_ALL)

# DSP tests
set(sample_dsp_sources
test/basic_math.cpp
test/biquad.cpp
test/biquad_cascade.cpp
test/complex.cpp
test/complex_vector.cpp
test/fft.cpp
test/stft.cpp
test/trig.cpp
test/virtual_float.cpp)
add_library(Cdsp INTERFACE)

include(CTest)
add_custom_target(Tests)
install(DIRECTORY include/ DESTINATION include)

foreach(source ${sample_dsp_sources})
string(REPLACE "\." "_" target "${source}")
string(REPLACE "/" "-" target "${target}")
add_executable(${target} ${source})
add_test("${target}" "${target}")
target_include_directories(
Cdsp INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

add_gtest_dependency("${target}")
add_cnl_dependency("${target}")
install(TARGETS Cdsp EXPORT CdspTargets)

target_include_directories(
${target} PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
add_dependencies(Tests "${target}")
endforeach(source)
install(EXPORT CdspTargets
FILE CdspConfig.cmake
NAMESPACE Cnl::
DESTINATION lib/cmake/cdsp)

install(DIRECTORY include/ DESTINATION include)
ExternalProject_Get_Property(Cnl source_dir)
install(DIRECTORY ${source_dir}/include/ DESTINATION include)
install(DIRECTORY ${Cnl_DESTDIR}/ DESTINATION ${CMAKE_INSTALL_PREFIX})
94 changes: 58 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,61 @@
# dsp
# CDSP - Compositional DSP Library for C++

CDSP is a header only DSP library written with [CNL](https://github.com/johnmcfarlane/cnl)
aiming for floating point and fixed-point implementation of typical DSP kernels.

## Requirements are the same as with [CNL](https://github.com/johnmcfarlane/cnl)
### Linux
Requires:
* GCC 5.1 / Clang 3.5
* [Cmake](https://cmake.org/) 3.2.2

Optional:
* [Boost](https://www.boost.org/) - for multiprecision support with [CNL](https://github.com/johnmcfarlane/cnl)
* [Doxygen](https://www.doxygen.org/) - generates documentation in the doc/gh-pages directory

### Mac
See the instructions for Linux. Works similarly.
For missing packages please use [Homebrew](https://brew.sh/).

### Windows
* MSBuild 15.0 (VS 2017)
* [Cmake](https://cmake.org/) 3.8.0

## Instructions
In an empty workspace folder, run the following script:

```sh
#!/bin/bash

# clone the repositories
git clone git@github.com:johnmcfarlane/cnl --branch develop
git clone git@github.com:google/googletest --branch master
git clone git@github.com:hbe72/dsp

# create an env directory (for include, lib etc.)
ENV="$(pwd)/env"
mkdir -p $ENV

# configure, build and install CNL in env/
mkdir -p build/cnl
pushd build/cnl
cmake -DCMAKE_INSTALL_PREFIX=$ENV ../../cnl
cmake --build . -- -j 8 install
popd

# configure, build and install Google Test in env/
mkdir -p build/googletest
pushd build/googletest
cmake -DCMAKE_INSTALL_PREFIX=$ENV ../../googletest
cmake --build . -- -j 8 install
popd

# configure, build and test DSP
mkdir -p build/dsp
pushd build/dspcd
cmake -DCMAKE_INSTALL_PREFIX=$ENV -DCMAKE_PREFIX_PATH=$ENV ../../dsp
cmake --build . -- -j 8 install
ctest
popd
### Download
The library is hosted on [GitHub](https://github.com/hbe72/dsp)
```
cd /some/directory
git clone https://github.com/hbe72/dsp.git
```

###Build
1. Generate the build system
```
mkdir build
cd build
cmake /some/directory/dsp -DCMAKE_INSTALL_PREFIX=/directory/to/install
```
2. Build tests:
* Linux and Mac parallel with 8 cores
```
cmake --build . --target Tests -- j 8
```
* Windows
```
cmake --build . --target Tests
```
3. Run the tests
```
ctest
```
4. Install
If you want to install the CDSP and CNL libraries to location specified by
CMAKE_INSTALL_PREFIX.
```
cmake --build . --target install
```
By default CDSP and CNL install to /usr/local.
79 changes: 79 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
include("../cmake/common.cmake")

######################################################################
# add_cnl_dependency
function(add_cnl_dependency target)
ExternalProject_Get_Property(Cnl source_dir)
target_include_directories("${target}" SYSTEM PRIVATE "${source_dir}/include")
add_dependencies("${target}" Cnl)
endfunction(add_cnl_dependency)

# Google Test
ExternalProject_Add(
GoogleTest
PREFIX ${CMAKE_BINARY_DIR}/GoogleTest
URL "https://github.com/google/googletest/archive/3a4cf1a02ef4adc28fccb7eef2b573b14cd59009.zip"
URL_MD5 "06ac495303fbe94b198026e3c196425e"
UPDATE_COMMAND ""
INSTALL_COMMAND ""
CMAKE_ARGS -Dgtest_force_shared_crt=ON
)

######################################################################
# add_gtest_dependency
function(add_gtest_dependency target)
# gtest
ExternalProject_Get_Property(GoogleTest binary_dir)
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
target_link_libraries("${target}"
debug ${binary_dir}/googlemock/gtest/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}gtestd${CMAKE_FIND_LIBRARY_SUFFIXES}
debug ${binary_dir}/googlemock/gtest/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_maind${CMAKE_FIND_LIBRARY_SUFFIXES}
optimized ${binary_dir}/googlemock/gtest/Release/${CMAKE_FIND_LIBRARY_PREFIXES}gtest${CMAKE_FIND_LIBRARY_SUFFIXES}
optimized ${binary_dir}/googlemock/gtest/Release/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main${CMAKE_FIND_LIBRARY_SUFFIXES}
)
else ()
target_link_libraries(
"${target}"
general "${binary_dir}/googlemock/gtest/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a"
general "${binary_dir}/googlemock/gtest/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a"
general pthread
)
endif ()

ExternalProject_Get_Property(GoogleTest source_dir)
target_include_directories("${target}" SYSTEM PRIVATE "${source_dir}/googletest/include")

add_dependencies("${target}" GoogleTest)
endfunction(add_gtest_dependency)


# DSP tests
set(sample_cdsp_sources
basic_math.cpp
biquad.cpp
biquad_cascade.cpp
complex.cpp
complex_vector.cpp
fft.cpp
stft.cpp
trig.cpp
virtual_float.cpp)

include(CTest)
add_custom_target(Tests)

foreach(source ${sample_cdsp_sources})
string(REPLACE "\." "_" target "${source}")
string(REPLACE "/" "-" target "${target}")
add_executable(${target} ${source})
add_test("${target}" "${target}")

add_gtest_dependency("${target}")
add_cnl_dependency("${target}")

target_include_directories(
${target} PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
add_dependencies(Tests "${target}")
endforeach(source)

0 comments on commit 5abf854

Please sign in to comment.