Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve find and package support #264

Merged
merged 5 commits into from
Jan 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,13 @@ matrix:
- os: osx
env: BUILD=Doc

addons:
apt:
sources:
- kubuntu-backports # cmake 2.8.12
# - george-edison55-precise-backports # cmake 3.2.3
packages:
- cmake

script:
- support/travis-build.py
50 changes: 44 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
message(STATUS "CMake version: ${CMAKE_VERSION}")

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 2.8.12)

# Set the default CMAKE_BUILD_TYPE to Release.
# This should be done before the project command since the latter can set
Expand Down Expand Up @@ -142,7 +142,7 @@ endif ()
set_target_properties(cppformat PROPERTIES
VERSION ${CPPFORMAT_VERSION} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR})

if (EXISTS .gitignore)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.gitignore")
# Get the list of ignored files from .gitignore.
file (STRINGS ".gitignore" lines)
LIST(REMOVE_ITEM lines /doc/html)
Expand All @@ -156,15 +156,53 @@ if (EXISTS .gitignore)

set(CPACK_SOURCE_GENERATOR ZIP)
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}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove CPACK_SOURCE_PACKAGE_FILE_NAME? It is used to set the correct source package name for distribution via website and releases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced it with CPACK_PACKAGE_NAME which is used for all generators, not only the source ZIP generator. Binary packages generated via make package are now also named correctly.

However, it seems like I have missed that it now generates cppformat-<version>-Source.zip instead of cppformat-<version>.zip which definitely was not intended. Good catch!

set(CPACK_PACKAGE_NAME "cppformat")
set(CPACK_RESOURCE_FILE_README ${FORMAT_SOURCE_DIR}/README.rst)
include(CPack)
endif ()

# Install targets.
if (FMT_INSTALL)
set(FMT_LIB_DIR lib CACHE STRING
include(CMakePackageConfigHelpers)
set(config_install_dir "lib/cmake/cppformat")
set(version_config "${CMAKE_CURRENT_BINARY_DIR}/cppformatConfigVersion.cmake")
set(project_config "${CMAKE_CURRENT_BINARY_DIR}/cppformatConfig.cmake")
set(targets_export_name "cppformatTargets")

set(FMT_LIB_DIR "lib" CACHE STRING
"Installation directory for libraries, relative to ${CMAKE_INSTALL_PREFIX}.")
install(TARGETS cppformat DESTINATION ${FMT_LIB_DIR})
install(FILES format.h DESTINATION include/cppformat)

# copy the header into the build directory to mimic the installed tree
configure_file("format.h" "cppformat/format.h" COPYONLY)
# add the include directories for both build and install tree
target_include_directories(
cppformat PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)

# generate the version, config and target files into the build directory
write_basic_package_version_file(
"${version_config}"
VERSION ${CPPFORMAT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(
"support/cmake/cppformatConfig.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
export(TARGETS cppformat FILE "${targets_export_name}.cmake")

# install version, config and target files
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)
install(EXPORT "${targets_export_name}" DESTINATION "${config_install_dir}")

# install the library and the include file
install(TARGETS cppformat EXPORT "${targets_export_name}" DESTINATION "${FMT_LIB_DIR}")
install(FILES format.h DESTINATION "include/cppformat")
endif ()
4 changes: 4 additions & 0 deletions support/cmake/cppformatConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("cppformat")
10 changes: 2 additions & 8 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ function (target_link_cppformat target)
endif ()
endfunction ()

function (fmt_target_include_directories)
if (CMAKE_MAJOR_VERSION VERSION_GREATER 2.8.10)
target_include_directories(${ARGN})
endif ()
endfunction ()

# We compile Google Test ourselves instead of using pre-compiled libraries.
# See the Google Test FAQ "Why is it not recommended to install a
# pre-compiled copy of Google Test (for example, into /usr/local)?"
Expand All @@ -24,7 +18,7 @@ endfunction ()
add_library(gmock STATIC
${FMT_GMOCK_DIR}/gmock-gtest-all.cc ${FMT_GMOCK_DIR}/gmock/gmock.h
${FMT_GMOCK_DIR}/gtest/gtest.h ${FMT_GMOCK_DIR}/gtest/gtest-spi.h)
fmt_target_include_directories(gmock INTERFACE ${FMT_GMOCK_DIR})
target_include_directories(gmock INTERFACE ${FMT_GMOCK_DIR})
find_package(Threads)
if (Threads_FOUND)
target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT})
Expand All @@ -43,7 +37,7 @@ check_cxx_source_compiles("
check_cxx_source_compiles("
#include <initializer_list>
int main() {}" FMT_INITIALIZER_LIST)

if (NOT FMT_VARIADIC_TEMPLATES OR NOT FMT_INITIALIZER_LIST)
add_definitions(-DGTEST_LANG_CXX11=0)
endif ()
Expand Down