From acbc2a73cb3553c8f178b95dde34ae1c1cfa9b57 Mon Sep 17 00:00:00 2001 From: KerstinKeller Date: Fri, 14 Jun 2019 17:24:21 +0200 Subject: [PATCH 1/2] Allow to install tom11 library with CMake. Add option to build tests. --- CMakeLists.txt | 69 ++++++++++++++++++++++++++++++++++++- cmake/toml11Config.cmake.in | 2 ++ tests/CMakeLists.txt | 3 +- 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 cmake/toml11Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index f76b700..daf57fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,17 @@ cmake_minimum_required(VERSION 2.8) enable_testing() + project(toml11) +set(toml11_VERSION_MAYOR 2) +set(toml11_VERSION_MINOR 3) +set(toml11_VERSION_PATCH 1) +set(toml11_VERSION + "${toml11_VERSION_MAYOR}.${toml11_VERSION_MINOR}.${toml11_VERSION_PATCH}" +) + +option(toml11_BUILD_TEST "Build toml tests" ON) + include(CheckCXXCompilerFlag) if("${CMAKE_VERSION}" VERSION_GREATER 3.1) set(CMAKE_CXX_EXTENSIONS OFF) @@ -34,5 +44,62 @@ else() endif() endif() -include_directories(${PROJECT_SOURCE_DIR}) +# Set some common directories +include(GNUInstallDirs) +set(toml11_install_cmake_dir ${CMAKE_INSTALL_LIBDIR}/cmake/toml11) +set(toml11_install_include_dir ${CMAKE_INSTALL_INCLUDEDIR}) +set(toml11_config_dir ${CMAKE_CURRENT_BINARY_DIR}/cmake/) +set(toml11_config ${toml11_config_dir}/toml11Config.cmake) +set(toml11_config_version ${toml11_config_dir}/toml11ConfigVersion.cmake) + +add_library(toml11 INTERFACE) +target_include_directories(toml11 INTERFACE + $ + $ +) +add_library(toml11::toml11 ALIAS toml11) + +# Write config and version config files +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + ${toml11_config_version} + VERSION ${toml11_VERSION} + COMPATIBILITY SameMajorVersion +) + +configure_package_config_file( + cmake/toml11Config.cmake.in + ${toml11_config} + INSTALL_DESTINATION ${toml11_install_cmake_dir} + PATH_VARS toml11_install_cmake_dir +) + +# Install config files +install(FILES ${toml11_config} ${toml11_config_version} + DESTINATION ${toml11_install_cmake_dir} +) + +# Install header files +install( + FILES toml.hpp + DESTINATION "${toml11_install_include_dir}" +) +install( + DIRECTORY "toml" + DESTINATION "${toml11_install_include_dir}" + FILES_MATCHING PATTERN "*.hpp" +) + +# Export targets and install them +install(TARGETS toml11 + EXPORT toml11Targets +) +install(EXPORT toml11Targets + FILE toml11Targets.cmake + DESTINATION ${toml11_install_cmake_dir} + NAMESPACE toml11:: +) + +if (toml11_BUILD_TEST) add_subdirectory(tests) +endif () \ No newline at end of file diff --git a/cmake/toml11Config.cmake.in b/cmake/toml11Config.cmake.in new file mode 100644 index 0000000..80c76f7 --- /dev/null +++ b/cmake/toml11Config.cmake.in @@ -0,0 +1,2 @@ +@PACKAGE_INIT@ +include("@PACKAGE_toml11_install_cmake_dir@/toml11Targets.cmake") \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 04ab6c4..6577085 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -88,7 +88,7 @@ add_definitions(-DUNITTEST_FRAMEWORK_LIBRARY_EXIST) foreach(TEST_NAME ${TEST_NAMES}) add_executable(${TEST_NAME} ${TEST_NAME}.cpp) - target_link_libraries(${TEST_NAME} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + target_link_libraries(${TEST_NAME} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} toml11::toml11) target_include_directories(${TEST_NAME} PRIVATE ${Boost_INCLUDE_DIRS}) add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) @@ -105,3 +105,4 @@ endforeach(TEST_NAME) add_executable(test_multiple_translation_unit test_multiple_translation_unit_1.cpp test_multiple_translation_unit_2.cpp) +target_link_libraries(test_multiple_translation_unit toml11::toml11) From 0357d8fb576abb69f69ae6146bf8040e2cd1d301 Mon Sep 17 00:00:00 2001 From: KerstinKeller Date: Mon, 17 Jun 2019 10:04:39 +0200 Subject: [PATCH 2/2] Add newline to end of CMake files. --- CMakeLists.txt | 2 +- cmake/toml11Config.cmake.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index daf57fe..1a45686 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,4 +102,4 @@ install(EXPORT toml11Targets if (toml11_BUILD_TEST) add_subdirectory(tests) -endif () \ No newline at end of file +endif () diff --git a/cmake/toml11Config.cmake.in b/cmake/toml11Config.cmake.in index 80c76f7..edc73f6 100644 --- a/cmake/toml11Config.cmake.in +++ b/cmake/toml11Config.cmake.in @@ -1,2 +1,2 @@ @PACKAGE_INIT@ -include("@PACKAGE_toml11_install_cmake_dir@/toml11Targets.cmake") \ No newline at end of file +include("@PACKAGE_toml11_install_cmake_dir@/toml11Targets.cmake")