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

View File

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