Merge pull request #18 from red0124/improvement/cmake_update

Update CMake files
This commit is contained in:
red0124 2023-02-09 20:20:27 +01:00 committed by GitHub
commit 8dcb69aa2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 39 deletions

View File

@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.14)
project(
ssp
VERSION 0.0.1
DESCRIPTION "Static split parser"
VERSION 1.3.0
DESCRIPTION "csv parser"
HOMEPAGE_URL "https://github.com/red0124/ssp"
LANGUAGES CXX
)
@ -11,22 +11,23 @@ project(
# ---- Warning guard ----
# Protect dependents from this project's warnings if the guard isn't disabled
set(ssp_warning_guard SYSTEM)
if(ssp_INCLUDE_WITHOUT_SYSTEM)
set(ssp_warning_guard "")
set(SSP_WARNING_GUARD SYSTEM)
if(SSP_INCLUDE_WITHOUT_SYSTEM)
set(SSP_WARNING_GUARD "")
endif()
# ---- Dependencies ----
include(FetchContent)
FetchContent_Declare(
fast_float
GIT_REPOSITORY https://github.com/red0124/fast_float.git
GIT_TAG origin/meson
GIT_SHALLOW TRUE)
fetchcontent_declare(
fast_float
GIT_REPOSITORY https://github.com/red0124/fast_float.git
GIT_TAG origin/meson
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(fast_float)
set(fast_float_source_dir "${FETCHCONTENT_BASE_DIR}/fast_float-src")
fetchcontent_makeavailable(fast_float)
set(FAST_FLOAT_SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/fast_float-src")
# ---- Declare library ----
@ -35,10 +36,10 @@ add_library(ssp::ssp ALIAS ssp)
target_include_directories(
ssp
${ssp_warning_guard}
${SSP_WARNING_GUARD}
INTERFACE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/fast_float>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/fast_float>"
)
target_compile_features(ssp INTERFACE cxx_std_17)
@ -46,8 +47,8 @@ target_compile_features(ssp INTERFACE cxx_std_17)
target_link_libraries(
ssp
INTERFACE
"$<$<AND:$<CXX_COMPILER_ID:AppleClang,Clang>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:c++fs>"
"$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.1>>:stdc++fs>"
"$<$<AND:$<CXX_COMPILER_ID:AppleClang,Clang>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:c++fs>"
"$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.1>>:stdc++fs>"
)
# ---- Install ----
@ -55,19 +56,21 @@ target_link_libraries(
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
set(ssp_directory "ssp-${PROJECT_VERSION}")
set(ssp_include_directory "${CMAKE_INSTALL_INCLUDEDIR}")
set(SSP_DIRECTORY "ssp-${PROJECT_VERSION}")
set(SSP_INCLUDE_DIRECTORY "${CMAKE_INSTALL_INCLUDEDIR}")
install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include/" "${fast_float_source_dir}/include/"
DESTINATION "${ssp_include_directory}"
DIRECTORY
"${PROJECT_SOURCE_DIR}/include/"
"${FAST_FLOAT_SOURCE_DIR}/include/"
DESTINATION "${SSP_INCLUDE_DIRECTORY}"
COMPONENT ssp_Development
)
install(
TARGETS ssp
EXPORT sspTargets
INCLUDES DESTINATION "${ssp_include_directory}"
INCLUDES DESTINATION "${SSP_INCLUDE_DIRECTORY}"
)
write_basic_package_version_file(
@ -76,11 +79,11 @@ write_basic_package_version_file(
ARCH_INDEPENDENT
)
set(ssp_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/${ssp_directory}")
set(SSP_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${SSP_DIRECTORY}")
install(
FILES "${PROJECT_BINARY_DIR}/ssp-config-version.cmake"
DESTINATION "${ssp_install_cmakedir}"
DESTINATION "${SSP_INSTALL_CMAKEDIR}"
COMPONENT ssp_Development
)
@ -88,10 +91,10 @@ install(
EXPORT sspTargets
FILE ssp-config.cmake
NAMESPACE ssp::
DESTINATION "${ssp_install_cmakedir}"
DESTINATION "${SSP_INSTALL_CMAKEDIR}"
COMPONENT ssp_Development
)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
include(CPack)
include(CPack)
endif()

View File

@ -4,20 +4,17 @@ project(ssp_tests CXX)
# ---- Dependencies ----
set(
ssp_INCLUDE_WITHOUT_SYSTEM
YES
CACHE
INTERNAL
set(SSP_INCLUDE_WITHOUT_SYSTEM YES
CACHE INTERNAL
"Turn the warning guard off to have errors appear in test builds"
)
include(FetchContent)
FetchContent_Declare(ssp SOURCE_DIR "${PROJECT_SOURCE_DIR}/..")
FetchContent_MakeAvailable(ssp)
fetchcontent_declare(ssp SOURCE_DIR "${PROJECT_SOURCE_DIR}/..")
fetchcontent_makeavailable(ssp)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(ssp INTERFACE -Wall -Wextra)
target_compile_options(ssp INTERFACE -Wall -Wextra)
endif()
find_package(doctest 2.4.4 CONFIG REQUIRED)
@ -29,9 +26,14 @@ include(doctest)
enable_testing()
foreach(name IN ITEMS test_splitter test_parser test_converter test_extractions)
add_executable("${name}" "${name}.cpp")
target_link_libraries("${name}" PRIVATE ssp::ssp fast_float doctest::doctest)
target_compile_definitions("${name}" PRIVATE
DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN CMAKE_GITHUB_CI)
doctest_discover_tests("${name}")
add_executable("${name}" "${name}.cpp")
target_link_libraries(
"${name}"
PRIVATE ssp::ssp fast_float doctest::doctest
)
target_compile_definitions(
"${name}"
PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN CMAKE_GITHUB_CI
)
doctest_discover_tests("${name}")
endforeach()