Output PDB files for Windows builds, and stop installing googletest (#18)

* Output PDB files for Debug and RelWithDebInfo configurations

* Stop installing googletest
This commit is contained in:
Bryan Hicks 2020-02-20 11:39:55 -08:00 коммит произвёл GitHub
Родитель e524b5dd43
Коммит b57727dcbf
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 78 добавлений и 44 удалений

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

@ -4,9 +4,10 @@
cmake_minimum_required (VERSION 3.11) cmake_minimum_required (VERSION 3.11)
project(AccessorFramework project(AccessorFramework
VERSION 1.0 VERSION 1.0.0
DESCRIPTION "A framework for using Accessors" DESCRIPTION "A framework for using Accessors"
LANGUAGES CXX LANGUAGES CXX
HOMEPAGE_URL "https://github.com/microsoft/AccessorFramework"
) )
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
@ -15,6 +16,10 @@ set(CMAKE_CXX_EXTENSIONS OFF)
option(BUILD_TESTS "Build test executable (on by default)" ON) option(BUILD_TESTS "Build test executable (on by default)" ON)
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "d")
endif()
add_library(AccessorFramework add_library(AccessorFramework
${PROJECT_SOURCE_DIR}/src/Accessor.cpp ${PROJECT_SOURCE_DIR}/src/Accessor.cpp
${PROJECT_SOURCE_DIR}/src/AccessorImpl.cpp ${PROJECT_SOURCE_DIR}/src/AccessorImpl.cpp
@ -28,6 +33,7 @@ add_library(AccessorFramework
) )
add_library(AccessorFramework::AccessorFramework ALIAS AccessorFramework) add_library(AccessorFramework::AccessorFramework ALIAS AccessorFramework)
if(${VERBOSE}) if(${VERBOSE})
target_compile_definitions(AccessorFramework PRIVATE VERBOSE=${VERBOSE}) target_compile_definitions(AccessorFramework PRIVATE VERBOSE=${VERBOSE})
endif() endif()
@ -47,57 +53,51 @@ endif()
set_target_properties(AccessorFramework PROPERTIES set_target_properties(AccessorFramework PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
COMPILE_PDB_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
PDB_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
)
get_target_property(AccessorFramework_NAME AccessorFramework NAME)
get_target_property(AccessorFramework_DEBUG_POSTFIX AccessorFramework DEBUG_POSTFIX)
set_target_properties(AccessorFramework PROPERTIES
COMPILE_PDB_NAME ${AccessorFramework_NAME}
COMPILE_PDB_NAME_DEBUG ${AccessorFramework_NAME}${AccessorFramework_DEBUG_POSTFIX}
PDB_NAME ${AccessorFramework_NAME}
PDB_NAME_DEBUG ${AccessorFramework_NAME}${AccessorFramework_DEBUG_POSTFIX}
) )
# Install # Install
install(TARGETS AccessorFramework install(TARGETS AccessorFramework
CONFIGURATIONS Debug EXPORT AccessorFrameworkTargets
EXPORT AccessorFrameworkTargets ARCHIVE DESTINATION lib
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib LIBRARY DESTINATION lib
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib RUNTIME DESTINATION bin
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
COMPONENT library
) )
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/AccessorFramework install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/AccessorFramework DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
DESTINATION ${CMAKE_INSTALL_PREFIX}/include
)
# Package if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
get_target_property(AccessorFramework_PDB_OUTPUT_DIRECTORY AccessorFramework PDB_OUTPUT_DIRECTORY)
if(WIN32 AND NOT CYGWIN) get_target_property(AccessorFramework_PDB_NAME AccessorFramework PDB_NAME)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_PREFIX}/cmake) get_target_property(AccessorFramework_PDB_NAME_DEBUG AccessorFramework PDB_NAME_DEBUG)
else() install(FILES
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_PREFIX}/lib/cmake/AccessorFramework) "${AccessorFramework_PDB_OUTPUT_DIRECTORY}/${AccessorFramework_PDB_NAME_DEBUG}.pdb"
"${AccessorFramework_PDB_OUTPUT_DIRECTORY}/${AccessorFramework_PDB_NAME}.pdb"
DESTINATION bin
OPTIONAL
)
endif() endif()
install(EXPORT AccessorFrameworkTargets install(EXPORT AccessorFrameworkTargets
FILE AccessorFrameworkTargets.cmake FILE AccessorFrameworkTargets.cmake
NAMESPACE AccessorFramework:: NAMESPACE AccessorFramework::
DESTINATION ${INSTALL_CONFIGDIR} DESTINATION lib/cmake/AccessorFramework
) )
include(CMakePackageConfigHelpers) # Export
write_basic_package_version_file(
${PROJECT_BINARY_DIR}/cmake/AccessorFrameworkConfigVersion.cmake
VERSION ${ACCESSORFRAMEWORK_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/AccessorFrameworkConfig.cmake.in
${PROJECT_BINARY_DIR}/cmake/AccessorFrameworkConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
install(
FILES
${PROJECT_BINARY_DIR}/cmake/AccessorFrameworkConfig.cmake
${PROJECT_BINARY_DIR}/cmake/AccessorFrameworkConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
export(EXPORT AccessorFrameworkTargets export(EXPORT AccessorFrameworkTargets
FILE ${PROJECT_BINARY_DIR}/cmake/AccessorFrameworkTargets.cmake FILE ${PROJECT_BINARY_DIR}/cmake/AccessorFrameworkTargets.cmake
@ -106,6 +106,30 @@ export(EXPORT AccessorFrameworkTargets
export(PACKAGE AccessorFramework) export(PACKAGE AccessorFramework)
# Package
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${PROJECT_BINARY_DIR}/cmake/AccessorFrameworkConfigVersion.cmake
VERSION ${ACCESSORFRAMEWORK_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cmake/AccessorFrameworkConfig.cmake.in
${PROJECT_BINARY_DIR}/cmake/AccessorFrameworkConfig.cmake
INSTALL_DESTINATION lib/cmake/AccessorFramework
)
install(
FILES
${PROJECT_BINARY_DIR}/cmake/AccessorFrameworkConfig.cmake
${PROJECT_BINARY_DIR}/cmake/AccessorFrameworkConfigVersion.cmake
DESTINATION lib/cmake/AccessorFramework
)
# Tests
if (BUILD_TESTS) if (BUILD_TESTS)
add_definitions(-DUSE_GTEST) add_definitions(-DUSE_GTEST)
enable_testing() enable_testing()

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

@ -3,18 +3,22 @@
cmake_minimum_required (VERSION 3.11) cmake_minimum_required (VERSION 3.11)
# Replace install() to do-nothing macro to avoid installing googletest
macro(install)
endmacro()
include(FetchContent) include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
googletest googletest
GIT_REPOSITORY https://github.com/google/googletest.git GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0 GIT_TAG release-1.10.0
) )
FetchContent_MakeAvailable(googletest) FetchContent_MakeAvailable(googletest)
FetchContent_GetProperties(googletest) FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED) if(NOT googletest_POPULATED)
FetchContent_Populate(googletest) FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}) add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif() endif()
add_executable(AccessorFrameworkTests add_executable(AccessorFrameworkTests
@ -25,9 +29,15 @@ add_executable(AccessorFrameworkTests
) )
target_link_libraries(AccessorFrameworkTests target_link_libraries(AccessorFrameworkTests
PRIVATE
gtest gtest
gmock_main gmock_main
AccessorFramework::AccessorFramework AccessorFramework::AccessorFramework
) )
add_test(NAME AccessorFrameworkTests COMMAND AccessorFrameworkTests) add_test(NAME AccessorFrameworkTests COMMAND AccessorFrameworkTests)
# Restore original install() behavior
macro(install)
_install(${ARGN})
endmacro()