From 74e2774ea395141abe7f90595a87b03d5fa0b6e3 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Thu, 20 Feb 2020 23:19:40 +0300 Subject: [PATCH] [A] Add test lib to package test --- .travis.yml | 11 ++---- tests/package_tests/CMakeLists.txt | 37 +++++++++++++++++-- .../{1-simple_table.cpp => foo-app.cpp} | 0 tests/package_tests/foo-lib.cpp | 13 +++++++ 4 files changed, 50 insertions(+), 11 deletions(-) rename tests/package_tests/{1-simple_table.cpp => foo-app.cpp} (100%) create mode 100644 tests/package_tests/foo-lib.cpp diff --git a/.travis.yml b/.travis.yml index e6cbb00..91ee15b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -263,10 +263,12 @@ script: - cmake --build build -- install - ls `pwd`/install - cd tests/package_tests - - cmake -H. -B_build -DCMAKE_PREFIX_PATH=../../install -DCMAKE_C_STANDARD=99 -DCMAKE_CXX_STANDARD=11 + - cmake -H. -B_build -DCMAKE_PREFIX_PATH=../../install -DCMAKE_C_STANDARD=99 -DCMAKE_CXX_STANDARD=11 -DCMAKE_INSTALL_PREFIX=./_install_foo - cmake --build _build -- -j3 - - ./_build/app + - ./_build/foo-app + - cmake --build _build -- install - rm -rf _build + - rm -rf _install_foo - cd ../../build # Build for coveralls (should be the last) @@ -284,8 +286,3 @@ script: - - - - - diff --git a/tests/package_tests/CMakeLists.txt b/tests/package_tests/CMakeLists.txt index cc9fd01..247bbca 100644 --- a/tests/package_tests/CMakeLists.txt +++ b/tests/package_tests/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.0) +project(foo) + find_package(libfort) # Assert exports of libfort @@ -16,8 +18,35 @@ if (NOT ${libfort_VERSION} EQUAL "0.4.0") message(FATAL_ERROR "libfort_VERSION is incorrect") endif() -add_executable(app - 1-simple_table.cpp) +# Create target that depend on libfort and check they'll compile ok +add_executable(foo-app + foo-app.cpp) +target_link_libraries(foo-app + PRIVATE libfort::fort +) + +add_library(foo-lib + foo-lib.cpp) +target_link_libraries(foo-lib + PRIVATE libfort::fort) + +include(GNUInstallDirs) +install( + TARGETS foo-lib + EXPORT ${PROJECT_NAME}-targets + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + + +include(CMakePackageConfigHelpers) + +install( + EXPORT ${PROJECT_NAME}-targets + FILE ${PROJECT_NAME}-targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) -target_link_libraries(app - libfort::fort) diff --git a/tests/package_tests/1-simple_table.cpp b/tests/package_tests/foo-app.cpp similarity index 100% rename from tests/package_tests/1-simple_table.cpp rename to tests/package_tests/foo-app.cpp diff --git a/tests/package_tests/foo-lib.cpp b/tests/package_tests/foo-lib.cpp new file mode 100644 index 0000000..51b6e97 --- /dev/null +++ b/tests/package_tests/foo-lib.cpp @@ -0,0 +1,13 @@ +#include "fort.hpp" + +std::string print_string() +{ + fort::char_table table; + table << fort::header + << "N" << "Driver" << "Time" << "Avg Speed" << fort::endr + << "1" << "Ricciardo" << "1:25.945" << "47.362" << fort::endr + << "2" << "Hamilton" << "1:26.373" << "35.02" << fort::endr + << "3" << "Verstappen" << "1:26.469" << "29.78" << fort::endr; + + return table.to_string(); +}