Merge remote-tracking branch 'origin/develop' into issue-38

This commit is contained in:
seleznevae 2020-02-23 11:00:38 +03:00
commit d91c7ce9d1
11 changed files with 267 additions and 27 deletions

View File

@ -255,6 +255,35 @@ script:
# scan-build make ;
# fi
# Test package installation
- cd ..
- rm -r build/*
- cmake -H. -Bbuild -DFORT_ENABLE_TESTING=OFF -DCMAKE_C_STANDARD=99 -DCMAKE_CXX_STANDARD=11 -DCMAKE_INSTALL_PREFIX=`pwd`/install
- cmake --build build --target all
- 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 -DCMAKE_INSTALL_PREFIX=./_install_foo
- cmake --build _build -- -j3
- ./_build/foo-app
- cmake --build _build -- install
- rm -rf _build
- rm -rf _install_foo
- cd ../../build
# Test cmake integration via `add_subdirectory`
- cd ..
- rm -r build/*
- ln -s `pwd` tests/add_subdirectory_tests/libfort
- cd tests/add_subdirectory_tests/
- cmake -H. -B_build -DCMAKE_C_STANDARD=99 -DCMAKE_CXX_STANDARD=11 -DCMAKE_INSTALL_PREFIX=./_install_foo
- cmake --build _build -- -j3
- ./_build/foo-app
- cmake --build _build -- install
- rm -rf _build
- rm -rf _install_foo
- cd ../../build
# Build for coveralls (should be the last)
- |
if [ "${CC}" = 'gcc' ]; then
@ -270,8 +299,3 @@ script:

View File

@ -15,6 +15,7 @@ include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
option(FORT_ENABLE_ASTYLE "Enable astyle" OFF)
option(FORT_ENABLE_WCHAR "Enable wchar support" ON)
option(FORT_ENABLE_UTF8 "Enable utf8 support" ON)
option(FORT_ENABLE_TESTING "Enables building tests and examples" ON)
set(FORT_BUILD_TYPE "common" CACHE STRING "Build type")
set_property(CACHE FORT_BUILD_TYPE PROPERTY STRINGS
@ -155,9 +156,11 @@ set(FORT_HAVE_UTF8 "${FORT_ENABLE_UTF8}" CACHE STRING "fort option")
# ------------------------------------------------------------------------------
add_subdirectory(lib)
add_subdirectory(src)
add_subdirectory(tests)
add_subdirectory(examples)
if(FORT_ENABLE_TESTING)
add_subdirectory(src)
add_subdirectory(tests)
add_subdirectory(examples)
endif()
# ------------------------------------------------------------------------------
@ -176,10 +179,11 @@ add_custom_target(headers SOURCES ${FortHeaders})
# ------------------------------------------------------------------------------
# Set preprocessor macros for all test builds.
# ------------------------------------------------------------------------------
target_compile_definitions(${PROJECT_NAME}_test_dev PRIVATE FT_TEST_BUILD=1)
target_compile_definitions(${PROJECT_NAME}_test_cpp PRIVATE FT_TEST_BUILD=1)
target_compile_definitions(${PROJECT_NAME}_test PRIVATE FT_TEST_BUILD=1)
if(FORT_ENABLE_TESTING)
target_compile_definitions(${PROJECT_NAME}_test_dev PRIVATE FT_TEST_BUILD=1)
target_compile_definitions(${PROJECT_NAME}_test_cpp PRIVATE FT_TEST_BUILD=1)
target_compile_definitions(${PROJECT_NAME}_test PRIVATE FT_TEST_BUILD=1)
endif()
# ------------------------------------------------------------------------------
# Setup text formatting via astyle.
@ -252,11 +256,21 @@ endif()
# ------------------------------------------------------------------------------
# Add examples and unit tests to ctest driver.
# ------------------------------------------------------------------------------
enable_testing()
list(APPEND ${PROJECT_NAME}_ctests
if(FORT_ENABLE_TESTING)
enable_testing()
list(APPEND ${PROJECT_NAME}_ctests
${${PROJECT_NAME}_tests}
${${PROJECT_NAME}_examples})
foreach(exe ${${PROJECT_NAME}_ctests})
foreach(exe ${${PROJECT_NAME}_ctests})
add_test(NAME ${exe} COMMAND ${exe})
endforeach()
endforeach()
endif()
# ------------------------------------------------------------------------------
# Exported targets for outer applications.
# ------------------------------------------------------------------------------
export(
TARGETS fort
FILE ${PROJECT_NAME}-targets.cmake
)

View File

@ -17,6 +17,9 @@
### Internal
- Refactoring of code that uses vectors.
- Add target export in cmake.
- Add option `FORT_ENABLE_TESTING` to turn on/off building tests and examples.
- Add option `POSITION_INDEPENDENT_CODE` for library target (libfort::fort).
### Docs

View File

@ -0,0 +1,5 @@
if(NOT TARGET @PROJECT_NAME@::fort)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")
endif()
set(@PROJECT_NAME@_LIBRARIES @PROJECT_NAME@::fort)

View File

@ -6,12 +6,16 @@ add_library(fort
target_include_directories(fort
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
set_target_properties(fort
PROPERTIES VERSION ${libfort_VERSION}
SOVERSION ${libfort_SOVERSION})
PROPERTIES
VERSION ${libfort_VERSION}
SOVERSION ${libfort_SOVERSION}
POSITION_INDEPENDENT_CODE ON
)
if(NOT FORT_HAVE_WCHAR)
target_compile_definitions(fort
@ -30,14 +34,45 @@ endif()
include(GNUInstallDirs)
install(
TARGETS
fort
TARGETS fort
EXPORT ${PROJECT_NAME}-targets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(FILES fort.h fort.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(
FILES fort.h fort.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
configure_file(libfort.pc.in libfort.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libfort.pc DESTINATION lib/pkgconfig)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/libfort.pc
DESTINATION lib/pkgconfig
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/../cmake/${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
COMPATIBILITY SameMajorVersion
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
install(
EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}-targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

View File

@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.0)
project(foo)
set(FORT_ENABLE_TESTING OFF CACHE INTERNAL "")
add_subdirectory(libfort)
# 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 fort
)
add_library(foo-lib
foo-lib.cpp)
target_link_libraries(foo-lib
PRIVATE fort)
add_library(foo-lib-shared SHARED
foo-lib.cpp)
target_link_libraries(foo-lib-shared
PRIVATE fort)
include(GNUInstallDirs)
install(
TARGETS foo-lib foo-lib-shared
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}
)

View File

@ -0,0 +1,16 @@
#include <iostream>
#include "fort.hpp"
int main()
{
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;
std::cout << table.to_string() << std::endl;
}

View File

@ -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();
}

View File

@ -0,0 +1,57 @@
cmake_minimum_required(VERSION 3.0)
project(foo)
find_package(libfort)
# Assert exports of libfort
if (NOT libfort_FOUND)
message(FATAL_ERROR "libfort was not found")
endif()
if (NOT TARGET libfort::fort)
message(FATAL_ERROR "TARGET libfort::fort not found")
endif()
if (NOT DEFINED libfort_LIBRARIES)
message(FATAL_ERROR "libfort_LIBRARIES are not defined")
endif()
if (NOT ${libfort_VERSION} EQUAL "0.4.0")
message(FATAL_ERROR "libfort_VERSION is incorrect")
endif()
# 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)
add_library(foo-lib-shared SHARED
foo-lib.cpp)
target_link_libraries(foo-lib-shared
PRIVATE libfort::fort)
include(GNUInstallDirs)
install(
TARGETS foo-lib foo-lib-shared
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}
)

View File

@ -0,0 +1,16 @@
#include <iostream>
#include "fort.hpp"
int main()
{
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;
std::cout << table.to_string() << std::endl;
}

View File

@ -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();
}