CMakeLists.txt#
The file CMakeLists.txt
can be used to build the examples using CMake.
cmake_minimum_required(VERSION 3.18)
project(HpkExamples LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# The following line (if uncommented) will import all available Hpk targets:
# find_package(Hpk CONFIG)
# but instead lets 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 0 CONFIG REQUIRED Core Avx2
PATHS /opt/libhpk0/lib/cmake/hpk)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
find_package(Hpk 0 CONFIG REQUIRED Core Sve256
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(hpkfft_fp32 ALIAS hpk::fft_avx2_fp32)
add_library(hpkfft_fp64 ALIAS hpk::fft_avx2_fp64)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
add_library(hpkfft_fp32 ALIAS hpk::fft_sve256_fp32)
add_library(hpkfft_fp64 ALIAS hpk::fft_sve256_fp64)
endif()
# 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 hpkfft_fp32)
# The next example uses both single and double precision.
add_executable(fft_cc fft_cc.cpp)
target_link_libraries(fft_cc PRIVATE warnings hpkfft_fp32 hpkfft_fp64)
# This 2D example uses only single precision.
add_executable(fft_2x4 fft_2x4.cpp)
target_link_libraries(fft_2x4 PRIVATE warnings hpkfft_fp32)
# This real time domain example uses only single precision. Note that we can
# explicitly list hpk::core as a link library if we choose.
add_executable(fft_rc fft_rc.cpp)
target_link_libraries(fft_rc PRIVATE warnings hpkfft_fp32 hpk::core)
# This will build the advanced examples:
add_subdirectory(advanced)