Skip to content

Commit

Permalink
CMake config generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dancazarin committed Feb 5, 2024
1 parent 0265961 commit b5467ed
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 15 deletions.
52 changes: 41 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ if (KFR_WITH_CLANG)
message(STATUS "Clang ${CLANG_VERSION} is set up successfully")
endif ()

project(kfr CXX)

file(STRINGS include/kfr/kfr.h KFR_VERSION
file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/include/kfr/kfr.h KFR_VERSION
REGEX "#define KFR_VERSION_(MINOR|MAJOR|PATCH)")
string(REGEX MATCHALL "[0-9]+" KFR_VERSION_MATCH ${KFR_VERSION})
string(REPLACE ";" "." KFR_VERSION "${KFR_VERSION_MATCH}")
message("KFR_VERSION = ${KFR_VERSION}")

project(
kfr
VERSION ${KFR_VERSION}
LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -293,15 +295,17 @@ endif ()

# KFR library
add_library(kfr INTERFACE)
target_sources(kfr INTERFACE ${KFR_SRC})
target_include_directories(kfr INTERFACE include)
# target_sources(kfr INTERFACE ${KFR_SRC})
target_include_directories(
kfr INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_options(kfr INTERFACE "$<$<CONFIG:DEBUG>:-DKFR_DEBUG>")
if (APPLE)
target_compile_options(kfr INTERFACE -faligned-allocation)
endif ()

if (MSVC)
target_compile_options(kfr INTERFACE -bigobj -EHsc)
target_compile_options(kfr INTERFACE -bigobj)
else ()
target_link_libraries(kfr INTERFACE ${STD_LIB} ${PTHREAD_LIB} m)
endif ()
Expand All @@ -312,14 +316,14 @@ if (KFR_STD_COMPLEX)
target_compile_definitions(kfr INTERFACE -DKFR_STD_COMPLEX)
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(kfr INTERFACE -Wno-ignored-qualifiers -Wno-psabi)
add_compile_options(-Wno-ignored-qualifiers -Wno-psabi)
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(kfr INTERFACE -Wno-c++1z-extensions -Wno-psabi
-Wno-unknown-warning-option)
add_compile_options(-Wno-c++1z-extensions -Wno-psabi
-Wno-unknown-warning-option)
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(kfr INTERFACE /wd4141)
add_compile_options(/wd4141)
endif ()

if (NOT KFR_ENABLE_DFT)
Expand Down Expand Up @@ -391,3 +395,29 @@ if (NOT TARGET uninstall)
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake)
endif ()

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

set(KFR_INSTALL_CMAKEDIR
"${CMAKE_INSTALL_LIBDIR}/cmake/kfr"
CACHE STRING "Path to KFR CMake files")

configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/KFRConfig.cmake"
INSTALL_DESTINATION "lib/cmake/kfr"
NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO)

install(TARGETS kfr EXPORT kfr_export)

install(
EXPORT kfr_export
DESTINATION "${KFR_INSTALL_CMAKEDIR}"
FILE KFRConfig.cmake)

# write_basic_package_version_file( KFRConfigVersion.cmake VERSION
# ${KFR_VERSION} COMPATIBILITY SameMajorVersion)

# install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KFRConfigVersion.cmake" DESTINATION
# "${KFR_INSTALL_CMAKEDIR}" )
10 changes: 9 additions & 1 deletion cmake/add_kfr_library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ function (add_kfr_library)
cmake_parse_arguments(LIB "MULTIARCH" "NAME" "SOURCES;LIBRARIES;DEFINITIONS;OPTIONS"
${ARGN})

set(${LIB_NAME}_LIBS PARENT_SCOPE)
set(${LIB_NAME}_LIBS)
set(${LIB_NAME}_TARGETS)
if (KFR_ENABLE_MULTIARCH AND LIB_MULTIARCH)
add_library(${LIB_NAME} INTERFACE)
foreach (ARCH IN LISTS KFR_ARCHS)
Expand All @@ -14,16 +15,20 @@ function (add_kfr_library)
target_compile_definitions(${LIB_NAME}_${ARCH} PRIVATE CMT_MULTI_ENABLED_${ENABLED_ARCH_UPPER}=1)
endforeach()
list(APPEND ${LIB_NAME}_LIBS ${LIB_NAME}_${ARCH})
list(APPEND ${LIB_NAME}_TARGETS ${LIB_NAME}_${ARCH})
target_link_libraries(${LIB_NAME} INTERFACE ${LIB_NAME}_${ARCH})
target_set_arch(${LIB_NAME}_${ARCH} PRIVATE ${ARCH})
endforeach ()
list(GET KFR_ARCHS 0 BASE_ARCH)
target_compile_definitions(${LIB_NAME}_${BASE_ARCH} PRIVATE CMT_BASE_ARCH=1)

link_as_whole(${LIB_NAME} INTERFACE ${LIB_NAME}_${BASE_ARCH})

list(APPEND ${LIB_NAME}_TARGETS ${LIB_NAME})
else ()
add_library(${LIB_NAME} STATIC ${LIB_SOURCES})
list(APPEND ${LIB_NAME}_LIBS ${LIB_NAME})
list(APPEND ${LIB_NAME}_TARGETS ${LIB_NAME})
target_set_arch(${LIB_NAME} PRIVATE ${KFR_ARCH})
endif ()

Expand All @@ -34,4 +39,7 @@ function (add_kfr_library)
target_compile_options(${LIB} PRIVATE ${LIB_OPTIONS})
endforeach ()

set(${LIB_NAME}_LIBS ${${LIB_NAME}_LIBS} PARENT_SCOPE)
set(${LIB_NAME}_TARGETS ${${LIB_NAME}_TARGETS} PARENT_SCOPE)

endfunction ()
3 changes: 3 additions & 0 deletions cmake/config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@


4 changes: 3 additions & 1 deletion src/capi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ if (KFR_INSTALL_LIBRARIES)
if (KFR_ENABLE_CAPI_BUILD)
install(
TARGETS kfr_capi
EXPORT kfr_export
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
RUNTIME DESTINATION bin
)
endif ()
endif ()
3 changes: 2 additions & 1 deletion src/dft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ endforeach ()

if (KFR_INSTALL_LIBRARIES)
install(
TARGETS ${kfr_dft_LIBS}
TARGETS ${kfr_dft_TARGETS}
EXPORT kfr_export
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
Expand Down
3 changes: 2 additions & 1 deletion src/dsp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ add_kfr_library(NAME kfr_dsp MULTIARCH SOURCES ${KFR_DSP_SRC})

if (KFR_INSTALL_LIBRARIES)
install(
TARGETS ${kfr_dsp_LIBS}
TARGETS ${kfr_dsp_TARGETS}
EXPORT kfr_export
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
Expand Down
1 change: 1 addition & 0 deletions src/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_kfr_library(NAME kfr_io SOURCES ${KFR_IO_SRC})
if (KFR_INSTALL_LIBRARIES)
install(
TARGETS kfr_io
EXPORT kfr_export
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
Expand Down

0 comments on commit b5467ed

Please sign in to comment.