Skip to content

Commit

Permalink
Hunter support and CMake improvements (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickguan authored and ruslo committed Oct 26, 2018
1 parent 10e809c commit df72c77
Show file tree
Hide file tree
Showing 3 changed files with 574 additions and 35 deletions.
67 changes: 32 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
#

cmake_minimum_required(VERSION 3.1)
project(spdlog VERSION 1.2.0 LANGUAGES CXX)
include("cmake/HunterGate.cmake")
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.20.64.tar.gz"
SHA1 "7b830dfda7a094b2af15f44b24ebd2489404d880"
)
project(spdlog VERSION 1.2.1 LANGUAGES CXX)
include(CTest)
include(CMakeDependentOption)
include(GNUInstallDirs)

hunter_add_package(fmt)
find_package(fmt CONFIG REQUIRED)
#---------------------------------------------------------------------------------------
# set default build to release
#---------------------------------------------------------------------------------------
Expand All @@ -31,7 +38,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCH
add_compile_options("-Wconversion")
add_compile_options("-pedantic")
add_compile_options("-Wfatal-errors")

endif()

#---------------------------------------------------------------------------------------
Expand Down Expand Up @@ -67,6 +74,8 @@ target_include_directories(
)

set(HEADER_BASE "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(spdlog INTERFACE fmt::fmt)
target_compile_definitions(spdlog INTERFACE SPDLOG_FMT_EXTERNAL=1)

if(SPDLOG_BUILD_EXAMPLES)
add_subdirectory(example)
Expand All @@ -80,69 +89,57 @@ if(SPDLOG_BUILD_BENCH)
add_subdirectory(bench)
endif()

#---------------------------------------------------------------------------------------
# Install/export targets and files
#---------------------------------------------------------------------------------------
# set files and directories
set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(include_install_dir "${CMAKE_INSTALL_INCLUDEDIR}")
set(pkgconfig_install_dir "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
set(version_config "${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${PROJECT_NAME}Config.cmake")
set(pkg_config "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
### Install ###
# * https://github.com/forexample/package-example
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")

set(config_install_dir "lib/cmake/${PROJECT_NAME}")
set(include_install_dir "include")
set(pkgconfig_install_dir "lib/pkgconfig")

set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(pkg_config "${generated_dir}/${PROJECT_NAME}.pc")
set(targets_export_name "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")

# generate package version file
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)

# configure pkg config file
configure_file("cmake/spdlog.pc.in" "${pkg_config}" @ONLY)

# install targets
# Note: use 'targets_export_name'
configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)

install(
TARGETS spdlog
EXPORT "${targets_export_name}"
INCLUDES DESTINATION "${include_install_dir}"
)

# install headers
install(
DIRECTORY "${HEADER_BASE}/${PROJECT_NAME}"
DESTINATION "${include_install_dir}"
)
install(DIRECTORY "include/spdlog" DESTINATION "${include_install_dir}")

# install project version file
install(
FILES "${version_config}"
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)

# install pkg config file
install(
FILES "${pkg_config}"
DESTINATION "${pkgconfig_install_dir}"
)

# install project config file
install(
EXPORT "${targets_export_name}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
FILE ${project_config}
)

# export build directory config file
export(
EXPORT ${targets_export_name}
NAMESPACE "${namespace}"
FILE ${project_config}
)

# register project in CMake user registry
export(PACKAGE ${PROJECT_NAME})

file(GLOB_RECURSE spdlog_include_SRCS "${HEADER_BASE}/*.h")
add_custom_target(spdlog_headers_for_ide SOURCES ${spdlog_include_SRCS})
2 changes: 2 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
# * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
# *************************************************************************/

find_package(fmt REQUIRED)

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
Loading

0 comments on commit df72c77

Please sign in to comment.