Skip to content

Commit

Permalink
cmake: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
leissa committed Sep 29, 2023
1 parent 5807912 commit 56c15e5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
20 changes: 11 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)

project(Thorin VERSION 1.9.0)

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(Thorin)

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
Expand Down Expand Up @@ -42,9 +49,6 @@ else()
add_compile_options(-Wall -Wextra)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(Thorin)

set(ABSL_PROPAGATE_CXX_STD ON)
set(ABSL_USE_EXTERNAL_GOOGLETEST ON)
set(ABSL_ENABLE_INSTALL ON)
Expand Down Expand Up @@ -85,24 +89,22 @@ if(THORIN_BUILD_DOCS)
endif()
endif()

include(CMakePackageConfigHelpers)

write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/thorin-config-version.cmake"
VERSION ${Thorin_VERSION}
COMPATIBILITY SameMajorVersion)

set(THORIN_CMAKE_INSTALL_DIR lib/cmake/thorin)
set(THORIN_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/thorin")

install(
FILES cmake/Thorin.cmake
DESTINATION "${THORIN_CMAKE_INSTALL_DIR}")
DESTINATION ${THORIN_CMAKE_INSTALL_DIR})

install(
EXPORT install_exports
EXPORT thorin_exports
FILE thorin-targets.cmake
NAMESPACE thorin::
DESTINATION "${THORIN_CMAKE_INSTALL_DIR}")
DESTINATION ${THORIN_CMAKE_INSTALL_DIR})

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/thorin-config.cmake.in"
Expand Down
23 changes: 19 additions & 4 deletions cmake/Thorin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,25 @@ function(add_thorin_plugin)
)

if(${PARSED_INSTALL})
install(TARGETS thorin_${PLUGIN} EXPORT install_exports LIBRARY DESTINATION lib/thorin RUNTIME DESTINATION lib/thorin INCLUDES DESTINATION include)
install(FILES ${THORIN_FILE_LIB_DIR} DESTINATION lib/thorin)
install(FILES ${PLUGIN_H} DESTINATION include/dialects/${PLUGIN})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${PLUGIN} DESTINATION include/dialects FILES_MATCHING PATTERN *.h)
install(
TARGETS thorin_${PLUGIN}
EXPORT thorin_exports
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/thorin"
RUNTIME DESTINATION "${CMAKE_INSTALL_LIBDIR}/thorin"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

install(
FILES ${THORIN_FILE_LIB_DIR}
DESTINATION lib/thorin)

install(
FILES ${PLUGIN_H}
DESTINATION "include/dialects/${PLUGIN}")

install(
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${PLUGIN} "
DESTINATION include/dialects
FILES_MATCHING PATTERN *.h)
endif()
if(TARGET thorin_all_plugins)
add_dependencies(thorin_all_plugins thorin_${PLUGIN})
Expand Down
2 changes: 1 addition & 1 deletion docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_custom_command(
OUTPUT ${CLI_HELP}
COMMAND thorin --help > ${CLI_HELP}
DEPENDS thorin
COMMENT "Generating help text of Thorin's CLI"
COMMENT "Generating help text of Thorin's CLI")

set(DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
set(DOXY_LAYOUT "${CMAKE_CURRENT_BINARY_DIR}/DoxygenLayout.xml")
Expand Down
27 changes: 19 additions & 8 deletions thorin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ add_library(libthorin

set_target_properties(libthorin PROPERTIES PREFIX "")

get_target_property(libthorin_HEADERS libthorin SOURCES)
list(FILTER libthorin_HEADERS INCLUDE REGEX ".*\.h")

configure_file(config.h.in ${CMAKE_BINARY_DIR}/include/thorin/config.h)
configure_file(
config.h.in
"${CMAKE_BINARY_DIR}/include/thorin/config.h")

target_include_directories(libthorin
PUBLIC
Expand All @@ -125,7 +124,19 @@ if(MSVC AND BUILD_SHARED_LIBS)
target_compile_definitions(libthorin PUBLIC ABSL_CONSUME_DLL)
endif()

install(TARGETS libthorin EXPORT install_exports INCLUDES DESTINATION include)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include FILES_MATCHING PATTERN "*.h")
install(FILES ${CMAKE_BINARY_DIR}/include/thorin/config.h DESTINATION include/thorin)
install(FILES ${PROJECT_SOURCE_DIR}/modules/half/include/half.hpp DESTINATION include)
install(
TARGETS libthorin
EXPORT thorin_exports
INCLUDES DESTINATION include)

install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DESTINATION include FILES_MATCHING PATTERN "*.h")

install(
FILES "${CMAKE_BINARY_DIR}/include/thorin/config.h"
DESTINATION include/thorin)

install(
FILES "${PROJECT_SOURCE_DIR}/modules/half/include/half.hpp"
DESTINATION include)

0 comments on commit 56c15e5

Please sign in to comment.