Added CMake install target

This commit is contained in:
Mario Emmenlauer 2022-07-18 11:57:06 +02:00
parent 0503de0cb9
commit 08f957951f
4 changed files with 81 additions and 8 deletions

View File

@ -2,14 +2,7 @@ cmake_minimum_required (VERSION 3.8)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
project (uuid_v4)
project (uuid_v4 VERSION 1.0.0 LANGUAGES CXX)
option(test "Build all tests." OFF)
option(test_use_internal_googletest "Build googletest, do not use it from system." ON)
@ -50,3 +43,62 @@ ENDIF (benchmark)
add_executable(example example.cpp)
target_link_libraries (example)
add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
if(NOT CMAKE_VERSION VERSION_LESS 3.8)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
endif()
target_include_directories(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>)
################################################################################
## PACKAGE SUPPORT
################################################################################
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(include_install_dir "include")
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(targets_export_name "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")
include(CMakePackageConfigHelpers)
# CMake automatically adds an architecture compatibility check to make sure
# 32 and 64 bit code is not accidentally mixed. For a header-only library this
# is not required. The check can be disabled by temporarily unsetting
# CMAKE_SIZEOF_VOID_P. In CMake 3.14 and later this can be achieved more cleanly
# with write_basic_package_version_file(ARCH_INDEPENDENT).
# TODO: Use this once a newer CMake can be required.
set(TMP_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
unset(CMAKE_SIZEOF_VOID_P)
write_basic_package_version_file(
"${version_config}" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion
)
set(CMAKE_SIZEOF_VOID_P ${TMP_SIZEOF_VOID_P})
configure_file("Config.cmake.in" "${project_config}" @ONLY)
install(TARGETS ${PROJECT_NAME}
EXPORT "${targets_export_name}"
INCLUDES DESTINATION "${include_install_dir}")
install(FILES "uuid_v4.h"
DESTINATION "${include_install_dir}/uuid_v4")
install(FILES "endianness.h"
DESTINATION "${include_install_dir}/uuid_v4")
install(FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}")
install(EXPORT "${targets_export_name}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}")

6
Config.cmake.in Normal file
View File

@ -0,0 +1,6 @@
if(NOT TARGET @PROJECT_NAME@::@PROJECT_NAME@)
# Provide path for scripts
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake")
endif()

View File

@ -1,3 +1,11 @@
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
include_directories (${uuid_v4_SOURCE_DIR})
add_executable (uuid_v4_benchmark uuid_v4_benchmark.cpp)

View File

@ -1,3 +1,10 @@
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
include_directories (${uuid_v4_SOURCE_DIR})
add_executable (uuid_v4_test uuid_v4_test.cpp)