Format CMake files, ignore generated files and don't copy header

This commit is contained in:
vitaut 2016-01-13 07:14:32 -08:00
parent 52ee516cf3
commit 22f61140d1
4 changed files with 32 additions and 37 deletions

2
.gitignore vendored
View File

@ -9,8 +9,8 @@ bin/
*.a *.a
*.so* *.so*
*.zip *.zip
/*.cmake
cmake_install.cmake cmake_install.cmake
CPack*Config.cmake
CTestTestfile.cmake CTestTestfile.cmake
CMakeCache.txt CMakeCache.txt
CMakeFiles CMakeFiles

View File

@ -142,9 +142,10 @@ endif ()
set_target_properties(cppformat PROPERTIES set_target_properties(cppformat PROPERTIES
VERSION ${CPPFORMAT_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR}) VERSION ${CPPFORMAT_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR})
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.gitignore") set(gitignore ${CMAKE_CURRENT_SOURCE_DIR}/.gitignore)
if (EXISTS ${gitignore})
# Get the list of ignored files from .gitignore. # Get the list of ignored files from .gitignore.
file (STRINGS ".gitignore" lines) file (STRINGS ${gitignore} lines)
LIST(REMOVE_ITEM lines /doc/html) LIST(REMOVE_ITEM lines /doc/html)
foreach (line ${lines}) foreach (line ${lines})
string(REPLACE "." "[.]" line "${line}") string(REPLACE "." "[.]" line "${line}")
@ -156,8 +157,8 @@ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.gitignore")
set(CPACK_SOURCE_GENERATOR ZIP) set(CPACK_SOURCE_GENERATOR ZIP)
set(CPACK_SOURCE_IGNORE_FILES ${ignored_files}) set(CPACK_SOURCE_IGNORE_FILES ${ignored_files})
set(CPACK_SOURCE_PACKAGE_FILE_NAME "cppformat-${CPPFORMAT_VERSION}") set(CPACK_SOURCE_PACKAGE_FILE_NAME cppformat-${CPPFORMAT_VERSION})
set(CPACK_PACKAGE_NAME "cppformat") set(CPACK_PACKAGE_NAME cppformat)
set(CPACK_RESOURCE_FILE_README ${FORMAT_SOURCE_DIR}/README.rst) set(CPACK_RESOURCE_FILE_README ${FORMAT_SOURCE_DIR}/README.rst)
include(CPack) include(CPack)
endif () endif ()
@ -165,44 +166,38 @@ endif ()
# Install targets. # Install targets.
if (FMT_INSTALL) if (FMT_INSTALL)
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
set(config_install_dir "lib/cmake/cppformat") set(config_install_dir lib/cmake/cppformat)
set(version_config "${CMAKE_CURRENT_BINARY_DIR}/cppformatConfigVersion.cmake") set(version_config ${CMAKE_CURRENT_BINARY_DIR}/cppformat-config-version.cmake)
set(project_config "${CMAKE_CURRENT_BINARY_DIR}/cppformatConfig.cmake") set(project_config ${CMAKE_CURRENT_BINARY_DIR}/cppformat-config.cmake)
set(targets_export_name "cppformatTargets") set(targets_export_name cppformat-targets)
set(FMT_LIB_DIR "lib" CACHE STRING set(FMT_LIB_DIR lib CACHE STRING
"Installation directory for libraries, relative to ${CMAKE_INSTALL_PREFIX}.") "Installation directory for libraries, relative to ${CMAKE_INSTALL_PREFIX}.")
# copy the header into the build directory to mimic the installed tree # Add the include directories for both build and install tree.
configure_file("format.h" "cppformat/format.h" COPYONLY)
# add the include directories for both build and install tree
target_include_directories( target_include_directories(
cppformat PUBLIC cppformat PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include>)
)
# generate the version, config and target files into the build directory # Generate the version, config and target files into the build directory.
write_basic_package_version_file( write_basic_package_version_file(
"${version_config}" ${version_config}
VERSION ${CPPFORMAT_VERSION} VERSION ${CPPFORMAT_VERSION}
COMPATIBILITY AnyNewerVersion COMPATIBILITY AnyNewerVersion)
)
configure_package_config_file( configure_package_config_file(
"support/cmake/cppformatConfig.cmake.in" support/cmake/cppformat-config.cmake.in
"${project_config}" ${project_config}
INSTALL_DESTINATION "${config_install_dir}" INSTALL_DESTINATION ${config_install_dir})
) export(TARGETS cppformat FILE ${targets_export_name}.cmake)
export(TARGETS cppformat FILE "${targets_export_name}.cmake")
# install version, config and target files # Install version, config and target files.
install( install(
FILES "${project_config}" "${version_config}" FILES ${project_config} ${version_config}
DESTINATION "${config_install_dir}" DESTINATION ${config_install_dir})
) install(EXPORT ${targets_export_name} DESTINATION ${config_install_dir})
install(EXPORT "${targets_export_name}" DESTINATION "${config_install_dir}")
# install the library and the include file # Install the library and the include file.
install(TARGETS cppformat EXPORT "${targets_export_name}" DESTINATION "${FMT_LIB_DIR}") install(TARGETS cppformat EXPORT ${targets_export_name} DESTINATION ${FMT_LIB_DIR})
install(FILES format.h DESTINATION "include/cppformat") install(FILES format.h DESTINATION include/cppformat)
endif () endif ()

View File

@ -0,0 +1,4 @@
@PACKAGE_INIT@
include(${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake)
check_required_components(cppformat)

View File

@ -1,4 +0,0 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake")
check_required_components("cppformat")