kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

CMakeLists.txt (7132B)


      1 # Copyright (C) 2016-2023 Dan Cazarin (https://www.kfrlib.com)
      2 # This file is part of KFR
      3 #
      4 # KFR is free software: you can redistribute it and/or modify
      5 # it under the terms of the GNU General Public License as published by
      6 # the Free Software Foundation, either version 2 of the License, or
      7 # (at your option) any later version.
      8 #
      9 # KFR is distributed in the hope that it will be useful,
     10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 # GNU General Public License for more details.
     13 #
     14 # You should have received a copy of the GNU General Public License
     15 # along with KFR.
     16 
     17 cmake_minimum_required(VERSION 3.12)
     18 
     19 add_definitions(-DKFR_TESTING=1)
     20 add_definitions(-DKFR_SRC_DIR=\"${CMAKE_SOURCE_DIR}\")
     21 
     22 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
     23     add_compile_options(-fdiagnostics-absolute-paths)
     24 endif ()
     25 
     26 option(KFR_ENABLE_COVERAGE "Enable coverage reporting" OFF)
     27 
     28 if (KFR_ENABLE_COVERAGE)
     29     if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
     30         add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
     31     endif ()
     32 endif ()
     33 
     34 if (KFR_ENABLE_DFT)
     35     add_definitions(-DHAVE_DFT)
     36 endif ()
     37 
     38 if (MSVC)
     39     link_libraries(-DEBUG)
     40 else ()
     41     add_compile_options(-g)
     42 endif ()
     43 
     44 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
     45     add_compile_options(-Wno-parentheses)
     46 endif ()
     47 
     48 # Binary output directories
     49 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin)
     50 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_BINARY_DIR}/bin)
     51 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/bin)
     52 
     53 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tests/cmake/")
     54 
     55 if (KFR_ENABLE_CAPI_BUILD)
     56     add_executable(capi_test capi_test.cpp)
     57     target_include_directories(capi_test
     58                                PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include)
     59     target_link_libraries(capi_test PRIVATE kfr_capi)
     60 endif ()
     61 
     62 if (KFR_ENABLE_ASMTEST)
     63     add_executable(asm_test internal/asm_test.cpp)
     64     target_link_libraries(asm_test kfr)
     65     target_set_arch(asm_test PRIVATE avx2)
     66     target_compile_definitions(asm_test PRIVATE KFR_SHOW_NOT_OPTIMIZED)
     67     target_compile_definitions(asm_test PRIVATE KFR_FUNCTION_IS_INTRINSIC)
     68     if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
     69         target_compile_options(asm_test PRIVATE -fno-stack-protector)
     70     endif ()
     71     if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
     72         target_compile_options(asm_test PRIVATE -GS-)
     73         target_compile_options(asm_test PRIVATE -Gs16384)
     74     endif ()
     75 
     76     add_custom_command(
     77         TARGET asm_test
     78         POST_BUILD
     79         COMMAND objconv -fyasm $<TARGET_FILE:asm_test>)
     80 endif ()
     81 
     82 set(ALL_TESTS_CPP ${KFR_UNITTEST_SRC})
     83 
     84 if (KFR_ENABLE_DFT)
     85     list(APPEND ALL_TESTS_CPP dft_test.cpp)
     86 
     87     add_executable(dft_test dft_test.cpp)
     88 endif ()
     89 
     90 if (KFR_REGENERATE_TESTS)
     91     find_package(MPFR)
     92     find_package(GMP)
     93 
     94     if (MPFR_FOUND AND GMP_FOUND)
     95         add_executable(generate_data internal/generate_data.cpp)
     96         target_link_libraries(generate_data kfr)
     97         target_include_directories(generate_data PRIVATE ${MPFR_INCLUDE_DIR}
     98                                                          ${GMP_INCLUDE_DIR})
     99         target_link_libraries(generate_data ${MPFR_LIBRARIES} ${GMP_LIBRARIES})
    100         if (KFR_REGENERATE_TESTS)
    101             add_custom_command(
    102                 TARGET generate_data
    103                 POST_BUILD
    104                 COMMENT "Generating tests..."
    105                 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests/data
    106                 COMMAND generate_data)
    107         endif ()
    108     endif ()
    109 endif ()
    110 
    111 add_executable(all_tests all_tests.cpp ${ALL_TESTS_CPP})
    112 target_compile_definitions(all_tests PRIVATE KFR_NO_MAIN)
    113 target_link_libraries(all_tests kfr use_arch kfr_dsp)
    114 if (KFR_ENABLE_DFT)
    115     target_link_libraries(all_tests kfr_dft)
    116     target_link_libraries(dft_test kfr_dft)
    117 endif ()
    118 target_link_libraries(all_tests kfr_io)
    119 
    120 option(KFR_NO_PERF_TESTS "Disable performance tests" OFF)
    121 
    122 if (KFR_NO_PERF_TESTS)
    123     add_compile_definitions(KFR_NO_PERF_TESTS=1)
    124 endif ()
    125 
    126 function (add_x86_test ARCH)
    127     set(NAME ${ARCH})
    128 
    129     add_executable(all_tests_${NAME} all_tests.cpp ${ALL_TESTS_CPP}
    130                                      ${KFR_IO_SRC} ${KFR_DSP_SRC})
    131     if (KFR_ENABLE_DFT)
    132         target_sources(all_tests_${NAME} PRIVATE ${KFR_DFT_SRC})
    133     endif ()
    134     target_link_libraries(all_tests_${NAME} kfr)
    135     target_set_arch(all_tests_${NAME} PRIVATE ${ARCH})
    136     target_compile_definitions(all_tests_${NAME} PRIVATE KFR_NO_MAIN)
    137     target_compile_definitions(all_tests_${NAME} PUBLIC KFR_ENABLE_FLAC=1)
    138 endfunction ()
    139 
    140 if (KFR_ARCH_TESTS AND KFR_ARCH_TESTS STREQUAL "ON")
    141     set(ARCH_LIST
    142         generic
    143         sse2
    144         ssse3
    145         sse42
    146         avx
    147         avx2
    148         avx512)
    149 else ()
    150     string(REPLACE "," ";" ARCH_LIST "${KFR_ARCH_TESTS}")
    151 endif ()
    152 
    153 if (MSVC AND NOT CLANG)
    154     list(REMOVE_ITEM ARCH_LIST generic)
    155 endif ()
    156 
    157 if (KFR_ARCH_TESTS)
    158     foreach (A IN LISTS ARCH_LIST)
    159         add_x86_test(${A})
    160     endforeach ()
    161 endif ()
    162 
    163 if (KFR_USE_SDE)
    164     if (BITNESS64)
    165         find_program(SDE NAMES "sde64" "sde")
    166     else ()
    167         find_program(SDE NAMES "sde")
    168     endif ()
    169     set(EMULATOR "${SDE}")
    170     list(APPEND EMULATOR "-skx")
    171     list(APPEND EMULATOR "--")
    172 elseif (NOT EMULATOR)
    173     set(EMULATOR "")
    174     set(SDE "")
    175 endif ()
    176 
    177 set(SDE_ARCH_generic -p4p)
    178 set(SDE_ARCH_sse2 -p4p)
    179 set(SDE_ARCH_sse3 -p4p)
    180 set(SDE_ARCH_ssse3 -mrm)
    181 set(SDE_ARCH_sse41 -pnr)
    182 set(SDE_ARCH_sse42 -nhm)
    183 set(SDE_ARCH_avx -snb)
    184 set(SDE_ARCH_avx2 -hsw)
    185 set(SDE_ARCH_avx512 -skx)
    186 
    187 if (NOT KFR_SKIP_TESTS)
    188     enable_testing()
    189 
    190     if (KFR_ENABLE_CAPI_BUILD)
    191         add_test(NAME capi_test COMMAND ${EMULATOR}
    192                                         ${PROJECT_BINARY_DIR}/bin/capi_test)
    193         if (UNIX)
    194             set_tests_properties(
    195                 capi_test
    196                 PROPERTIES
    197                     ENVIRONMENT
    198                     "LD_LIBRARY_PATH=${PROJECT_BINARY_DIR}/lib:$ENV{LD_LIBRARY_PATH}"
    199             )
    200         endif ()
    201     endif ()
    202 
    203     if (KFR_ARCH_TESTS)
    204         foreach (A IN LISTS ARCH_LIST)
    205             if (KFR_USE_SDE)
    206                 add_test(NAME all_tests_${A}
    207                          COMMAND ${SDE} ${SDE_ARCH_${A}} -chip_check_exe_only
    208                                  -- ${PROJECT_BINARY_DIR}/bin/all_tests_${A})
    209             else ()
    210                 add_test(NAME all_tests_${A}
    211                          COMMAND ${EMULATOR}
    212                                  ${PROJECT_BINARY_DIR}/bin/all_tests_${A})
    213             endif ()
    214         endforeach ()
    215     endif ()
    216     if (KFR_USE_SDE)
    217         add_test(NAME all_tests
    218                  COMMAND ${SDE} ${SDE_ARCH_${KFR_ARCH}} -chip_check_exe_only --
    219                          ${PROJECT_BINARY_DIR}/bin/all_tests)
    220         add_test(NAME all_tests_on_avx512
    221                  COMMAND ${SDE} ${SDE_ARCH_avx512} -chip_check_exe_only --
    222                          ${PROJECT_BINARY_DIR}/bin/all_tests)
    223     else ()
    224         add_test(NAME all_tests COMMAND ${EMULATOR}
    225                                         ${PROJECT_BINARY_DIR}/bin/all_tests)
    226     endif ()
    227 endif ()