cmake : Add install target to support consuming WIL through cmake. (#137)

* cmake : Use PROJECT_SOURCE_DIR to support FetchContent.

* cmake : Add install target.

* cmake : Add options to disable packaging and unit tests.

* cmake : Typos and cleanup.
This commit is contained in:
p-groarke 2020-05-07 16:36:12 -04:00 коммит произвёл GitHub
Родитель cd51fa9d3c
Коммит 8cabf25897
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 35 добавлений и 5 удалений

Просмотреть файл

@ -1,8 +1,12 @@
cmake_minimum_required(VERSION 3.11)
project(WIL)
include(GNUInstallDirs)
# Set by build server to speed up build/reduce file/object size
option(FAST_BUILD "Sets options to speed up build/reduce obj/executable size" OFF)
option(WIL_BUILD_PACKAGING "Sets option to build the packaging, default on" On)
option(WIL_BUILD_TESTS "Sets option to build the unit tests, default on" On)
if (NOT DEFINED WIL_BUILD_VERSION)
set(WIL_BUILD_VERSION "0.0.0")
@ -17,5 +21,31 @@ else()
string(REGEX REPLACE "\\\\$" "" WIL_WINDOWS_SDK_VERSION "$ENV{WindowsSDKVersion}")
endif()
add_subdirectory(packaging)
add_subdirectory(tests)
if (${WIL_BUILD_PACKAGING})
add_subdirectory(packaging)
endif()
if (${WIL_BUILD_TESTS})
add_subdirectory(tests)
endif()
# Gather headers into an interface library.
file(GLOB_RECURSE HEADER_FILES "${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/*.h")
add_library(${PROJECT_NAME} INTERFACE)
# The interface's include directory.
target_include_directories(${PROJECT_NAME} INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
# Install Package Configuration
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}_targets)
install(EXPORT ${PROJECT_NAME}_targets
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME}-config.cmake
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}"
)
# Install the headers at a standard cmake location.
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

Просмотреть файл

@ -1,8 +1,8 @@
include(${CMAKE_SOURCE_DIR}/cmake/common_build_flags.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/common_build_flags.cmake)
cmake_minimum_required(VERSION 3.11)
# All projects need to reference the WIL headers
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/include)
# TODO: Might be worth trying to conditionally do this on SDK version, assuming there's a semi-easy way to detect that
include_directories(BEFORE SYSTEM ./workarounds/wrl)