diff --git a/.circleci/config.yml b/.circleci/config.yml index 4d1dae7..e5e6f17 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ jobs: steps: - checkout - run: git submodule update --init --recursive --remote - - run: mkdir build - - run: cd build && cmake .. - - run: cd build && cmake --build . - - run: cd build && ctest -VV + - run: mkdir -p tests/build + - run: cd tests/build && cmake .. + - run: cd tests/build && cmake --build . + - run: cd tests/build && ctest -VV diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c13109..1bde05a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,67 +1,48 @@ -cmake_minimum_required (VERSION 3.0.2...3.27) -project (utf8cpp VERSION 3.2.5 LANGUAGES CXX) +cmake_minimum_required (VERSION 3.5...3.27) +project (utf8cpp + VERSION 4.0.0 + LANGUAGES CXX + DESCRIPTION "C++ portable library for working with utf-8 encoding") -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - set(IS_ROOT_PROJECT ON) -else() - set(IS_ROOT_PROJECT OFF) -endif() +add_library(${PROJECT_NAME} INTERFACE) -option(UTF8_TESTS "Enable tests for UTF8-CPP" ${IS_ROOT_PROJECT}) -option(UTF8_INSTALL "Enable installation for UTF8-CPP" ${IS_ROOT_PROJECT}) -option(UTF8_SAMPLES "Enable building samples for UTF8-CPP" ${IS_ROOT_PROJECT}) +include(GNUInstallDirs) -add_library(utf8cpp INTERFACE) target_include_directories(utf8cpp INTERFACE "$" $ ) -add_library(utf8::cpp ALIAS utf8cpp) -if(UTF8_INSTALL) - include(CMakePackageConfigHelpers) - if(MSVC) - set(DEF_INSTALL_CMAKE_DIR CMake) - else() - include(GNUInstallDirs) # define CMAKE_INSTALL_* - set(DEF_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/utf8cpp) - endif() +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) - if(${CMAKE_VERSION} VERSION_GREATER "3.14") - set(OPTIONAL_ARCH_INDEPENDENT "ARCH_INDEPENDENT") - endif() - - write_basic_package_version_file( - ${CMAKE_CURRENT_BINARY_DIR}/utf8cppConfigVersion.cmake - VERSION ${PROJECT_VERSION} - COMPATIBILITY SameMajorVersion - ${OPTIONAL_ARCH_INDEPENDENT} - ) +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}Targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + PUBLIC_HEADER DESTINATION include COMPONENT Development + BUNDLE DESTINATION bin COMPONENT Runtime +) - configure_package_config_file( - ${PROJECT_SOURCE_DIR}/utf8cppConfig.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/utf8cppConfig.cmake - INSTALL_DESTINATION ${DEF_INSTALL_CMAKE_DIR} - ) +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake +) - install(DIRECTORY source/ DESTINATION include/utf8cpp) - install(TARGETS utf8cpp EXPORT utf8cppTargets) - install(EXPORT utf8cppTargets DESTINATION ${DEF_INSTALL_CMAKE_DIR}) - install( - FILES - ${CMAKE_CURRENT_BINARY_DIR}/utf8cppConfig.cmake - ${CMAKE_CURRENT_BINARY_DIR}/utf8cppConfigVersion.cmake - DESTINATION - ${DEF_INSTALL_CMAKE_DIR} - ) -endif() +install(EXPORT ${PROJECT_NAME}Targets + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) -if(UTF8_SAMPLES) - add_executable(docsample ${PROJECT_SOURCE_DIR}/samples/docsample.cpp) - target_link_libraries(docsample PRIVATE utf8::cpp) -endif() +install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) -if(UTF8_TESTS) - enable_testing() - add_subdirectory(tests) -endif() +install(FILES ${PROJECT_SOURCE_DIR}/source/utf8.h DESTINATION include) +install(DIRECTORY ${PROJECT_SOURCE_DIR}/source/utf8 DESTINATION include) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7d56582..8a00a6a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,17 +1,20 @@ -add_executable(negative ${PROJECT_SOURCE_DIR}/tests/negative.cpp) -add_executable(cpp11 ${PROJECT_SOURCE_DIR}/tests/test_cpp11.cpp) -add_executable(cpp17 ${PROJECT_SOURCE_DIR}/tests/test_cpp17.cpp) -add_executable(cpp20 ${PROJECT_SOURCE_DIR}/tests/test_cpp20.cpp) -add_executable(apitests ${PROJECT_SOURCE_DIR}/tests/apitests.cpp) +cmake_minimum_required (VERSION 3.5) +project(utfcpptests LANGUAGES CXX) +enable_testing() + +add_library(${PROJECT_NAME} INTERFACE) + +include_directories("${PROJECT_SOURCE_DIR}/../source") + +add_executable(negative negative.cpp) +add_executable(cpp11 test_cpp11.cpp) +add_executable(cpp17 test_cpp17.cpp) +add_executable(cpp20 test_cpp20.cpp) +add_executable(apitests apitests.cpp) + +add_executable(noexceptionstests noexceptionstests.cpp) -add_executable(noexceptionstests ${PROJECT_SOURCE_DIR}/tests/noexceptionstests.cpp) -target_link_libraries(negative PRIVATE utf8::cpp) -target_link_libraries(cpp11 PRIVATE utf8::cpp) -target_link_libraries(cpp17 PRIVATE utf8::cpp) -target_link_libraries(cpp20 PRIVATE utf8::cpp) -target_link_libraries(apitests PRIVATE utf8::cpp) -target_link_libraries(noexceptionstests PRIVATE utf8::cpp) target_compile_options(${PROJECT_NAME} INTERFACE $<$:/W4> @@ -44,7 +47,7 @@ set_target_properties(cpp20 CXX_EXTENSIONS NO) -add_test(negative_test negative ${PROJECT_SOURCE_DIR}/tests/test_data/utf8_invalid.txt) +add_test(negative_test negative ${PROJECT_SOURCE_DIR}/test_data/utf8_invalid.txt) add_test(cpp11_test cpp11) add_test(cpp17_test cpp17) add_test(cpp20_test cpp20) diff --git a/utf8cppConfig.cmake.in b/utf8cppConfig.cmake.in index fd3480b..9c15f36 100644 --- a/utf8cppConfig.cmake.in +++ b/utf8cppConfig.cmake.in @@ -1,8 +1,4 @@ @PACKAGE_INIT@ -include("${CMAKE_CURRENT_LIST_DIR}/utf8cppTargets.cmake") -check_required_components( "utf8cpp" ) - -if(NOT TARGET utf8::cpp) - add_library(utf8::cpp ALIAS utf8cpp) -endif() +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@")