CMakeLists.txt#
The file CMakeLists.txt
can be used to build the examples using CMake.
cmake_minimum_required(VERSION 3.18)
project(HpkExamples
VERSION 0.5.1
DESCRIPTION "High performance kernels Examples"
HOMEPAGE_URL "https://hpkfft.com"
LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# This example project is distributed with Hpk and is given the same version
# as Hpk itself. Below, we set the variable HpkVersion to be our version.
set(HpkVersion ${CMAKE_PROJECT_VERSION})
# The following line (if uncommented) will import all available Hpk targets:
# find_package(Hpk CONFIG)
# but instead let's specify the Hpk version, the components we require, and
# offer a hard-coded guess as to where Hpk config files are installed.
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
find_package(Hpk ${HpkVersion} CONFIG
REQUIRED COMPONENTS Core Avx2
OPTIONAL_COMPONENTS Omp
PATHS /opt/libhpk0/lib/cmake/hpk)
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
find_package(Hpk ${HpkVersion} CONFIG
REQUIRED COMPONENTS Core Sve256
OPTIONAL_COMPONENTS Omp
PATHS /opt/libhpk0/lib64/cmake/hpk)
else()
message(FATAL_ERROR "Unknown processor: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
# Hpk FFT libraries are specific to the hardware instruction set.
# So, let's create library aliases for our later convenience.
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
add_library(hpk_fft_fp32 ALIAS hpk::fft_avx2_fp32)
add_library(hpk_fft_fp64 ALIAS hpk::fft_avx2_fp64)
if (Hpk_Omp_FOUND)
add_library(hpk_fft_openmp ALIAS hpk::fft_iomp)
endif()
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
add_library(hpk_fft_fp32 ALIAS hpk::fft_sve256_fp32)
add_library(hpk_fft_fp64 ALIAS hpk::fft_sve256_fp64)
if (Hpk_Omp_FOUND)
add_library(hpk_fft_openmp ALIAS hpk::fft_omp)
endif()
endif()
# The dynamic link interface (dlopen, dlsym, etc.) is built into libc.so.6 for
# glibc >= 2.34, so the following is needed only on older platforms:
add_library(dl INTERFACE)
target_link_libraries(dl INTERFACE ${CMAKE_DL_LIBS})
# Also, for our convenience, let's create an interface library that does
# nothing more than add compiler warning flags.
add_library(warnings INTERFACE)
target_compile_options(warnings INTERFACE -Wall -Wextra -Wpedantic)
# The first example below uses only single precision, so we link with that
# target. CMake knows that the fft libraries depend on hpk::core and will
# automatically add that link target as well.
add_executable(example example.cpp)
target_link_libraries(example PRIVATE warnings hpk_fft_fp32 dl)
# The next example uses both single and double precision.
# Note that we can explicitly list hpk_core as a dependency if we choose.
add_executable(fft_cc fft_cc.cpp)
target_link_libraries(fft_cc
PRIVATE warnings hpk_fft_fp32 hpk_fft_fp64 hpk::core dl)
# This 2D example uses single precision and OpenMP parallelism.
if (Hpk_Omp_FOUND)
add_executable(fft_cc_2d fft_cc_2d.cpp)
target_link_libraries(fft_cc_2d
PRIVATE warnings hpk_fft_fp32 hpk_fft_openmp
PRIVATE hpk::core dl)
endif()
# This real time domain example uses only single precision.
add_executable(fft_rc fft_rc.cpp)
target_link_libraries(fft_rc PRIVATE warnings hpk_fft_fp32 hpk::core dl)
# This will build the advanced examples:
add_subdirectory("advanced")