Skip to content

Commit

Permalink
Merge pull request KomputeProject#338 from SlopeCraft/fix-find-package
Browse files Browse the repository at this point in the history
Fix find_package, enable CPack and support clang-cl
  • Loading branch information
axsaucedo authored Nov 2, 2023
2 parents 0fe2343 + 032c64f commit df0ab79
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 16 deletions.
25 changes: 22 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")

set(KOMPUTE_LIBRARIES kompute CACHE INTERNAL "")

if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(kompute_opt_install_default_val ON)
else ()
set(kompute_opt_install_default_val OFF)
endif ()

# ####################################################
# Options
# ####################################################
Expand Down Expand Up @@ -84,7 +90,7 @@ message(STATUS "=======================================================")
kompute_option(KOMPUTE_OPT_BUILD_TESTS "Enable if you want to build tests." OFF)
kompute_option(KOMPUTE_OPT_CODE_COVERAGE "Enable if you want code coverage." OFF)
kompute_option(KOMPUTE_OPT_BUILD_DOCS "Enable if you want to build documentation." OFF)
kompute_option(KOMPUTE_OPT_INSTALL "Enable if you want to enable installation." OFF)
kompute_option(KOMPUTE_OPT_INSTALL "Enable if you want to enable installation." ${kompute_opt_install_default_val})

# Build options
kompute_option(KOMPUTE_OPT_BUILD_PYTHON "Enable if you want to build python bindings." OFF)
Expand Down Expand Up @@ -177,7 +183,7 @@ endif()
if(KOMPUTE_OPT_USE_BUILT_IN_FMT)
set(FMT_INSTALL ${KOMPUTE_OPT_INSTALL})
FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 8.1.1) # Source: https://github.com/fmtlib/fmt/releases
GIT_TAG 10.1.1) # Source: https://github.com/fmtlib/fmt/releases
FetchContent_MakeAvailable(fmt)
else()
find_package(fmt REQUIRED)
Expand Down Expand Up @@ -244,7 +250,8 @@ if(KOMPUTE_OPT_INSTALL)
set(ENABLE_GLSLANG_INSTALL ON CACHE BOOL "Enables install of glslang" FORCE)
endif()

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
if(MSVC)
# MSVC is true when the compiler is msvc(cl) or clang-cl, both receive msvc-like commandline flags
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror")
endif()
Expand Down Expand Up @@ -284,3 +291,15 @@ endif()
if(KOMPUTE_OPT_BUILD_PYTHON)
add_subdirectory(python)
endif()

if(KOMPUTE_OPT_INSTALL)
# Many other targets may be exported to komputeTargets in subdirs, so install the export in the last
# Generates komputeTargets.cmake, which is required by komputeConfig.cmake in a find_package call.
install(EXPORT komputeTargets
FILE komputeTargets.cmake
NAMESPACE kompute::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kompute)
endif()


include(cmake/set_package_info.cmake)
12 changes: 12 additions & 0 deletions cmake/cpack-configs/archive.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is for generating archive packages.
# Up to v3.20, CPack supports .7z, .tar.bz2, .tar.gz, .tar.xz, .tar.z, .tar.zst and .zip
# For details, see https://cmake.org/cmake/help/v3.20/cpack_gen/archive.html

# The number of available cores on the machine will be used to compress
# Only available for tar.xz.
set(CPACK_ARCHIVE_THREADS 0)

# Other variables:
# set(CPACK_ARCHIVE_FILE_NAME)
# set(CPACK_ARCHIVE_<component>_FILE_NAME)
# set(CPACK_ARCHIVE_COMPONENT_INSTALL)
50 changes: 50 additions & 0 deletions cmake/cpack-configs/deb.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This file is for generating .deb packages for debian Linux

# Here are all variables for deb generators.
# Commented variables are not used, or their default values are ok.
# Also see https://cmake.org/cmake/help/v3.20/cpack_gen/deb.html

# Kompute depends on the vulkan development package
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libvulkan-dev")
# set(CPACK_DEBIAN_<COMPONENT>_PACKAGE_DEPENDS)

# The maintainer of this deb package
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "axsaucedo")


# These variables may be used.
# set(CPACK_DEBIAN_ARCHIVE_TYPE) # The archive format used for creating the Debian package.
# set(CPACK_DEBIAN_COMPRESSION_TYPE) # Possible values: lzma, xz, bzip2, gzip. gzip by default.

# Set Priority control field e.g. required, important, standard, optional, extra. Default value is optional.
# set(CPACK_DEBIAN_PACKAGE_PRIORITY)
# set(CPACK_DEBIAN_<COMPONENT>_PACKAGE_PRIORITY)

# Predepends is like depends, but it forces dpkg to complete installation of predepend packages even before starting
# the installation of our package.
# set(CPACK_DEBIAN_PACKAGE_PREDEPENDS)
# set(CPACK_DEBIAN_<COMPONENT>_PACKAGE_PREDEPENDS)

# Recommend other packages after user installs our package
# set(CPACK_DEBIAN_PACKAGE_RECOMMENDS)
# set(CPACK_DEBIAN_<COMPONENT>_PACKAGE_RECOMMENDS)

# Suggest other packages before user installs our package
# set(CPACK_DEBIAN_PACKAGE_SUGGESTS)
# set(CPACK_DEBIAN_<COMPONENT>_PACKAGE_SUGGESTS)

# Packages that will be broken by our package
# set(CPACK_DEBIAN_PACKAGE_BREAKS)
# set(CPACK_DEBIAN_<COMPONENT>_PACKAGE_BREAKS)

# Packages that conflicts with our package
# set(CPACK_DEBIAN_PACKAGE_CONFLICTS)
# set(CPACK_DEBIAN_<COMPONENT>_PACKAGE_CONFLICTS)

# Used for virtual packages
# set(CPACK_DEBIAN_PACKAGE_PROVIDES)
# set(CPACK_DEBIAN_<COMPONENT>_PACKAGE_PROVIDES)

# Packages that should be overwritten by our package
# set(CPACK_DEBIAN_PACKAGE_REPLACES)
# set(CPACK_DEBIAN_<COMPONENT>_PACKAGE_REPLACES)
27 changes: 27 additions & 0 deletions cmake/cpack-configs/nsis.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file is for generating .exe installer (NSIS) for Windows

# Here are all variables for NSIS generators.
# Commented variables are not used, or their default values are ok.
# Also see https://cmake.org/cmake/help/v3.20/cpack_gen/nsis.html

# The compressing method. Supported values: ZLIB, BZIP2 and LZMA
set(CPACK_NSIS_COMPRESSOR "LZMA")

# The name appears in Windows Apps & features in Control Panel
set(CPACK_NSIS_DISPLAY_NAME "Kompute")

# Ask the user whether to uninstall the previous versions
set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)

# The icon of exe installer
set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/docs/images/kompute.ico")

# The icon of exe uninstaller
set(CPACK_NSIS_MUI_UNIICON ${CPACK_NSIS_MUI_ICON})

set(CPACK_NSIS_URL_INFO_ABOUT "https://kompute.cc")
set(CPACK_NSIS_HELP_LINK "https://kompute.cc/overview/community.html")

#set(CPACK_NSNS_CONTACT)
#set(CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP)
#set(CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP)
2 changes: 1 addition & 1 deletion cmake/komputeConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include(CMakeFindDependencyMacro)
@PACKAGE_INIT@

find_dependency(VULKAN REQUIRED)
find_dependency(Vulkan REQUIRED)

include(${CMAKE_CURRENT_LIST_DIR}/komputeTargets.cmake)

Expand Down
62 changes: 62 additions & 0 deletions cmake/set_package_info.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This file is to setup information for cpack
# CPack is a package tool distributed with cmake.
# For details about CPack, see https://cmake.org/cmake/help/book/mastering-cmake/chapter/Packaging%20With%20CPack.html


# Common variables for all generators
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CPACK_PACKAGE_NAME "kompute-debug")
else()
set(CPACK_PACKAGE_NAME "kompute")
endif ()
set(CPACK_PACKAGE_VENDOR "KomputeProject")
set(CPACK_PACKAGE_DESCRIPTION "General purpose GPU compute framework built on Vulkan to support 1000s of cross vendor graphics cards (AMD, Qualcomm, NVIDIA & friends). Blazing fast, mobile-enabled, asynchronous and optimized for advanced GPU data processing usecases. Backed by the Linux Foundation. ")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "GPGPU framework built on Vulkan.")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://kompute.cc/")

# The license file used by GUI installers
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
# The readme file used by GUI installers
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")

set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}\\\\${PROJECT_VERSION}")
# set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/docs/images/kompute.jpg")

# Other common variables, in most cases they are not used,
# otherwise their default values are ok.
# Also see https://cmake.org/cmake/help/v3.20/module/CPack.html
#
# set(CPACK_PACKAGE_DIRECTORY)
# set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
# set(CPACK_PACKAGE_DIRECTORY)
# set(CPACK_PACKAGE_VERSION_MAJOR)
# set(CPACK_PACKAGE_VERSION_MINOR)
# set(CPACK_PACKAGE_VERSION_PATCH)
# set(CPACK_PACKAGE_DESCRIPTION_FILE)
# set(CPACK_PACKAGE_FILE_NAME)
# set(CPACK_PACKAGE_INSTALL_DIRECTORY)
# set(CPACK_PACKAGE_ICON)
# set(CPACK_PACKAGE_CHECKSUM)
# set(CPACK_PROJECT_CONFIG_FILE)
# set(CPACK_RESOURCE_FILE_LICENSE)
# set(CPACK_RESOURCE_FILE_README)
# set(CPACK_RESOURCE_FILE_WELCOME)
# set(CPACK_MONOLITHIC_INSTALL)
# set(CPACK_GENERATOR)
# set(CPACK_OUTPUT_CONFIG_FILE)
# set(CPACK_PACKAGE_EXECUTABLES)
# set(CPACK_STRIP_FILES)
# set(CPACK_VERBATIM_VARIABLES)
# set(CPACK_THREADS)



# Setup detailed package info for any cpack generator.
# Each file correspond to a cpack generator
file(GLOB config_files "${CMAKE_SOURCE_DIR}/cmake/cpack-configs/*.cmake")
foreach (config_file ${config_files})
include(${config_file})
endforeach ()

# This should be include at last, and all unset cpack variables will be setup to their default value.
include(CPack)
Binary file added docs/images/kompute.ico
Binary file not shown.
57 changes: 50 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ set_target_properties(kompute

# Import GNU common install directory variables
include(GNUInstallDirs)

install(TARGETS kompute
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(KOMPUTE_OPT_INSTALL)
install(TARGETS kompute
EXPORT komputeTargets # Export kompute to komputeTargets. komputeTargets can hold multiple targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()

# Include CMake helpers for package config files
# Follow this installation guideline: https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html
Expand All @@ -51,8 +53,10 @@ write_basic_package_version_file(
COMPATIBILITY SameMajorVersion# All possible values: SameMajorVersion, SameMinorVersion, ExactVersion, AnyNewerVersion
)

install(FILES ${PROJECT_BINARY_DIR}/kompute/komputeConfig.cmake
${PROJECT_BINARY_DIR}/kompute/komputeConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kompute)
if(KOMPUTE_OPT_INSTALL)
install(FILES ${PROJECT_BINARY_DIR}/kompute/komputeConfig.cmake
${PROJECT_BINARY_DIR}/kompute/komputeConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kompute)
endif()

# ####################################################
# Linking
Expand Down Expand Up @@ -86,3 +90,42 @@ endif()
add_subdirectory(logger)
add_subdirectory(shaders)
add_subdirectory(include)

if(KOMPUTE_OPT_INSTALL)
if (KOMPUTE_OPT_USE_BUILT_IN_FMT)
# We can't export fmt::fmt because it's alias target, so we unwrap the alias and install it.
get_target_property(fmt_aliased_target fmt::fmt ALIASED_TARGET)
install(TARGETS ${fmt_aliased_target}
EXPORT komputeTargets
#COMPONENT DO_NOT_INSTALL_THIS
EXCLUDE_FROM_ALL)
# Installation of headers changed in fmt from v8 to v10. In v10, cmake will try to find fmt headers in the
# include dir of kompute, which will fail definitely. Add EXCLUDE_FROM_ALL to avoid this bug.
endif ()

if(KOMPUTE_OPT_USE_BUILT_IN_VULKAN_HEADER)
# We can't export Vulkan::Headers because it's alias target, so we unwrap the alias and install it.
get_target_property(vk_header_target Vulkan::Headers ALIASED_TARGET)

# Before installation, reset the INTERFACE_INCLUDE_DIRECTORIES to a generator expression
# Otherwise INTERFACE_INCLUDE_DIRECTORIES will point to an absolute path even if the software package
# is copied to another computer. If we don't do this, cmake will complains about it in the configuration step.
# Get the build interface of include dir
get_target_property(vk_header_include_dir ${vk_header_target} INTERFACE_INCLUDE_DIRECTORIES)
#message(STATUS "vk_header_include_dir = ${vk_header_include_dir}")
# Reset INTERFACE_INCLUDE_DIRECTORIES to a generator expression.
set_target_properties(${vk_header_target}
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "$<INSTALL_INTERFACE:include>;$<BUILD_INTERFACE:${vk_header_include_dir}>")
#message(STATUS "vk_header_include_dir = ${vk_header_include_di r}")
install(TARGETS ${vk_header_target}
EXPORT komputeTargets)
endif ()

if(KOMPUTE_OPT_BUILD_PYTHON)
# We can't export pybind11::headers because it's alias target, so we unwrap the alias and install it.
get_target_property(pybind11_aliased_target pybind11::headers ALIASED_TARGET)
install(TARGETS ${pybind11_aliased_target}
EXPORT komputeTargets)
endif ()
endif()
2 changes: 1 addition & 1 deletion src/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ Manager::createDevice(const std::vector<uint32_t>& familyQueueIndices,

KP_LOG_INFO("Using physical device index {} found {}",
physicalDeviceIndex,
physicalDeviceProperties.deviceName);
physicalDeviceProperties.deviceName.data());

if (familyQueueIndices.empty()) {
// Find compute queue
Expand Down
4 changes: 3 additions & 1 deletion src/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ target_sources(kompute PRIVATE
kompute/logger/Logger.hpp
)

install(DIRECTORY kompute DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if(KOMPUTE_OPT_INSTALL)
install(DIRECTORY kompute DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()

# ####################################################
# Logger
Expand Down
8 changes: 8 additions & 0 deletions src/logger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ if(NOT KOMPUTE_OPT_LOG_LEVEL_DISABLED)
target_link_libraries(kp_logger PUBLIC fmt::fmt)
endif()
endif()


# Nothing will be installed, this will only export kp_logger to komputeTargets
add_library(kompute::logger ALIAS kp_logger)
if(KOMPUTE_OPT_INSTALL)
install(TARGETS kp_logger
EXPORT komputeTargets)
endif()
13 changes: 10 additions & 3 deletions src/shaders/glsl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ add_library(kp_shader INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/ShaderOpMult.hpp"

target_include_directories(kp_shader INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)

# Make sure we install shaders:
install(FILES $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>/ShaderOpMult.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>/ShaderLogisticRegression.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Nothing will be installed, this will only export kp_shader to komputeTargets
add_library(kompute::shader ALIAS kp_shader)
if(KOMPUTE_OPT_INSTALL)
install(TARGETS kp_shader
EXPORT komputeTargets)

# Make sure we install shaders:
install(FILES $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>/ShaderOpMult.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>/ShaderLogisticRegression.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()

0 comments on commit df0ab79

Please sign in to comment.