Skip to content

Commit

Permalink
Use find_package COMPONENTS to select shared/static + datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr committed Oct 30, 2020
1 parent 2d5de83 commit 1487038
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 14 deletions.
25 changes: 14 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ option(KISSFFT_OPENMP "Build kissfft with openmp" OFF)

if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
add_compile_options(-ffast-math -fomit-frame-pointer
-W -Wall -Wstrict-prototypes -Wmissing-prototypes -Waggregate-return
-Wcast-align -Wcast-qual -Wnested-externs -Wshadow -Wbad-function-cast
-Wwrite-strings)
-W -Wall -Waggregate-return -Wcast-align -Wcast-qual -Wshadow -Wwrite-strings
"$<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes;-Wmissing-prototypes;-Wnested-externs;-Wbad-function-cast>")
endif()

set(KISSFFT_FIXED_WIDTH_VALID 16 32)
Expand All @@ -35,11 +34,10 @@ endif()

add_library(kissfft
kiss_fft.c)
add_library(kissfft::kissfft ALIAS kissfft)

target_include_directories(kissfft PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:.>)
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

set(KISSFFT_COMPILE_DEFINITIONS)
if(KISSFFT_SIMD)
Expand All @@ -51,7 +49,7 @@ else()
set(KISSFFT_DATATYPE "${KISSFFT_FLOAT_TYPE}")
else()
list(APPEND KISSFFT_COMPILE_DEFINITIONS KISSFFT_FIXED_POINT=${KISSFFT_FIXED_WIDTH})
set(KISSFFT_DATATYPE "int${KISSFFT_FIXED_WIDTH}_t")
set(KISSFFT_DATATYPE "int${KISSFFT_FIXED_WIDTH}")
endif()
endif()
if(KISSFFT_OPENMP)
Expand All @@ -64,29 +62,35 @@ if(KISSFFT_OPENMP)
endif()
message(STATUS "Building KissFFT with datatype=${KISSFFT_DATATYPE}")

set(KISSFFT_EXPORT_SUFFIX "")
if(BUILD_SHARED_LIBS)
list(APPEND KISSFFT_COMPILE_DEFINITIONS KISS_FFT_SHARED)
set_target_properties(kissfft PROPERTIES
C_VISIBILITY_PRESET hidden)
set(KISSFFT_EXPORT_SUFFIX "-shared")
else()
set(KISSFFT_EXPORT_SUFFIX "-static")
endif()
target_compile_definitions(kissfft PUBLIC ${KISSFFT_COMPILE_DEFINITIONS})
set(KISSFFT_OUTPUT_NAME "kissfft_${KISSFFT_DATATYPE}")
set_target_properties(kissfft PROPERTIES
OUTPUT_NAME "${KISSFFT_OUTPUT_NAME}"
DEFINE_SYMBOL KISS_FFT_BUILD
EXPORT_NAME "kissfit_${KISSFFT_DATATYPE}${KISSFFT_EXPORT_SUFFIX}"
EXPORT_NAME "kissfft-${KISSFFT_DATATYPE}"
VERSION ${PROJECT_VERSION})
add_library(kissfft::kissfft ALIAS kissfft)
add_library(kissfft::kissff-${KISSFFT_DATATYPE} ALIAS kissfft)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(kissfft PRIVATE m)
endif()

function(add_kissfft_executable NAME)
add_executable(${NAME} ${ARGN})
target_link_libraries(${NAME} PRIVATE kissfft::kissfft)
set_target_properties(${NAME} PROPERTIES
OUTPUT_NAME "${NAME}_${KISSFFT_DATATYPE}")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(${NAME} PRIVATE m)
endif()
set_target_properties(${NAME} PROPERTIES
OUTPUT_NAME "${NAME}_${KISSFFT_DATATYPE}")
endfunction()

option(KISSFFT_TOOLS "Build kissfft tools" ON)
Expand All @@ -100,7 +104,6 @@ if(KISSFFT_TEST)
add_subdirectory(test)
endif()


option(KISSFFT_INSTALL "Enable kissfft install" ON)
if (KISSFFT_INSTALL)
include(GNUInstallDirs)
Expand Down
74 changes: 72 additions & 2 deletions kissfft-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,82 @@
# kissfft-config.ccmake accept the following components:
#
# SHARED/STATIC:
# This components allows one to choose a shared/static kissfft library.
# The default is selected by BUILD_SHARED_LIBS.
# They are to be used exclusively. Using them together is an error.
#
# example:
# find_package(kissfft CONFIG REQUIRED COMPONENTS STATIC)
#
# simd/int16/int32/float/double:
# This components allows one to choose the datatype.
# When using this component, the target kissfft::kissfft becomes available.
# When not using this component, you will have to choose the correct kissfft target.
#
# example:
# find_package(kissfft CONFIG REQUIRED)
# # - kissfft::kissfft-float, kissfft::kissfft-int32_t/ ... are available (if they are installed)
# # - kissfft::kissfft is not available,
#
# find_package(kissfft CONFIG REQUIRED COMPONENTS int32_t)
# # - kissfft::kissfft-float, kissfft::kissfft-int32_t/ ... are available (if they are installed)
# # - kissfft::kissfft is available (as an alias for kissfft::kissfft-int32_t),

@PACKAGE_INIT@

cmake_minimum_required(VERSION 3.3)

# Set include glob of config files using SHARED/static component, BUILD_SHARED_LIBS by default
set(_kissfft_shared_detected OFF)
set(_kissfft_shared ${BUILD_SHARED_LIBS})
if("SHARED" IN_LIST kissfft_FIND_COMPONENTS)
set(_kissfft_shared_detected ON)
set(_kissfft_shared ON)
endif()
if("STATIC" IN_LIST kissfft_FIND_COMPONENTS)
if(_kissfft_shared_detected)
message(FATAL_ERROR "SHARED and STATIC components cannot be used together")
endif()
set(_kissfft_shared_detected ON)
set(_kissfft_shared OFF)
endif()

if(_kissfft_shared)
set(_kissfft_config_glob "kissfft-*-shared-targets.cmake")
else()
set(_kissfft_config_glob "kissfft-*-static-targets.cmake")
endif()

# Load information for all configured kissfft
get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
file(GLOB CONFIG_FILES "${_DIR}/kissfft-*-targets.cmake")
file(GLOB CONFIG_FILES "${_DIR}/${_kissfft_config_glob}")
foreach(f ${CONFIG_FILES})
include(${f})
endforeach()

# If a datatype component is passed, create kissfft::kissfft
set(_kissfft_datatype_detected)
foreach(_kissfft_datatype simd int16 int32 float double)
if(_kissfft_datatype IN_LIST kissfft_FIND_COMPONENTS)
if(_kissfft_datatype_detected)
message(FATAL_ERROR "Cannot define datatype COMPONENT twice: ${_kissfft_datatype_detected} and ${_kissfft_datatype}")
endif()
set(_kissfft_datatype_detected ${_kissfft_datatype})
endif()
endforeach()

if(_kissfft_datatype_detected)
if(NOT TARGET kissfft::kissfft-${_kissfft_datatype_detected})
message(FATAL_ERROR "kissfft with datatype=${_kissfft_datatype_detected} is not installed")
endif()
if(TARGET kissfft::kissfft)
message(SEND_ERROR "kissfft::kissfft already exists. You cannot use 2 find_package's with datatype that are visible to eachother.")
else()
add_library(kissfft::kissfft INTERFACE IMPORTED)
set_property(TARGET kissfft::kissfft PROPERTY INTERFACE_LINK_LIBRARIES kissfft::kissfft-${_kissfft_datatype_detected})
endif()
endif()

set(kissfft_FOUND ON)
set(KISSFFT_VERSION @kissfft_VERSION@)

check_required_components(kissfft)
2 changes: 1 addition & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ if(NOT KISSFFT_DATATYPE MATCHES "simd")
target_link_libraries(psdpng PRIVATE PkgConfig::libpng)
endif()

#dumphdr.c is not available
#FIXME: dumphdr.c is not available
#add_kissfft_executable(dumphdr dumphdr.c)

0 comments on commit 1487038

Please sign in to comment.