diff --git a/.cmake-format b/.cmake-format new file mode 100644 index 0000000..aa925ec --- /dev/null +++ b/.cmake-format @@ -0,0 +1,62 @@ +format: + tab_size: 2 + line_width: 100 + dangle_parens: true + +parse: + additional_commands: + cpmaddpackage: + pargs: + nargs: '*' + flags: [] + spelling: CPMAddPackage + kwargs: &cpmaddpackagekwargs + NAME: 1 + FORCE: 1 + VERSION: 1 + GIT_TAG: 1 + DOWNLOAD_ONLY: 1 + GITHUB_REPOSITORY: 1 + GITLAB_REPOSITORY: 1 + GIT_REPOSITORY: 1 + SVN_REPOSITORY: 1 + SVN_REVISION: 1 + SOURCE_DIR: 1 + DOWNLOAD_COMMAND: 1 + FIND_PACKAGE_ARGUMENTS: 1 + NO_CACHE: 1 + GIT_SHALLOW: 1 + URL: 1 + URL_HASH: 1 + URL_MD5: 1 + DOWNLOAD_NAME: 1 + DOWNLOAD_NO_EXTRACT: 1 + HTTP_USERNAME: 1 + HTTP_PASSWORD: 1 + OPTIONS: + + cpmfindpackage: + pargs: + nargs: '*' + flags: [] + spelling: CPMFindPackage + kwargs: *cpmaddpackagekwargs + packageproject: + pargs: + nargs: '*' + flags: [] + spelling: packageProject + kwargs: + NAME: 1 + VERSION: 1 + NAMESPACE: 1 + INCLUDE_DIR: 1 + INCLUDE_DESTINATION: 1 + INCLUDE_HEADER_PATTERN: 1 + BINARY_DIR: 1 + COMPATIBILITY: 1 + VERSION_HEADER: 1 + EXPORT_HEADER: 1 + DISABLE_VERSION_SUFFIX: 1 + CPACK: 1 + DEPENDENCIES: + + diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b920b1..b52ffc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,10 @@ cmake_minimum_required(VERSION 3.9) -project(csv) +project(csv VERSION 2.3.0) if(CSV_CXX_STANDARD) - set(CMAKE_CXX_STANDARD ${CSV_CXX_STANDARD}) + set(CMAKE_CXX_STANDARD ${CSV_CXX_STANDARD}) else() - set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD 17) endif(CSV_CXX_STANDARD) option(BUILD_PYTHON "Build Python Binding" OFF) @@ -12,113 +12,182 @@ option(BUILD_PYTHON "Build Python Binding" OFF) message("Building CSV library using C++${CMAKE_CXX_STANDARD}") # Defines CSV_HAS_CXX17 in compatibility.hpp -if (CMAKE_VERSION VERSION_LESS "3.12.0") - add_definitions(-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}) +if(CMAKE_VERSION VERSION_LESS "3.12.0") + add_definitions(-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}) else() - add_compile_definitions(CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}) + add_compile_definitions(CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}) endif() set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads QUIET REQUIRED) if(MSVC) - # Make Visual Studio report accurate C++ version - # See: https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/ + # Make Visual Studio report accurate C++ version See: + # https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/ # /Wall emits warnings about the C++ standard library - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /GS- /Zc:__cplusplus /W4") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /GS- /Zc:__cplusplus /W4") else() - # Ignore Visual Studio pragma regions - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas") + # Ignore Visual Studio pragma regions + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} --coverage -Og") endif(MSVC) -set(CSV_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}) -set(CSV_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}) -set(CSV_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/) -set(CSV_SOURCE_DIR ${CSV_INCLUDE_DIR}/internal/) -set(CSV_TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/tests) - -include_directories(${CSV_INCLUDE_DIR}) - -## Load developer specific CMake settings -if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - SET(CSV_DEVELOPER TRUE) +if(CSV_TEST_INSTALLED_VERSION) + find_package(${PROJECT_NAME} REQUIRED) +else() + set(CSV_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}) + set(CSV_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}) + set(CSV_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include/) + # set(CSV_SOURCE_DIR ${CSV_INCLUDE_DIR}/internal/) + set(CSV_TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/tests) + + # Load developer specific CMake settings + if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(CSV_DEVELOPER TRUE) + endif() + + # Main Library + add_library( + ${PROJECT_NAME} STATIC + ${CSV_INCLUDE_DIR}/internal/basic_csv_parser.hpp + ${CSV_INCLUDE_DIR}/internal/basic_csv_parser.cpp + ${CSV_INCLUDE_DIR}/internal/col_names.cpp + ${CSV_INCLUDE_DIR}/internal/col_names.hpp + ${CSV_INCLUDE_DIR}/internal/common.hpp + ${CSV_INCLUDE_DIR}/internal/csv_format.hpp + ${CSV_INCLUDE_DIR}/internal/csv_format.cpp + ${CSV_INCLUDE_DIR}/internal/csv_reader.hpp + ${CSV_INCLUDE_DIR}/internal/csv_reader.cpp + ${CSV_INCLUDE_DIR}/internal/csv_reader_iterator.cpp + ${CSV_INCLUDE_DIR}/internal/csv_row.hpp + ${CSV_INCLUDE_DIR}/internal/csv_row.cpp + ${CSV_INCLUDE_DIR}/internal/csv_row_json.cpp + ${CSV_INCLUDE_DIR}/internal/csv_stat.cpp + ${CSV_INCLUDE_DIR}/internal/csv_stat.hpp + ${CSV_INCLUDE_DIR}/internal/csv_utility.cpp + ${CSV_INCLUDE_DIR}/internal/csv_utility.hpp + ${CSV_INCLUDE_DIR}/internal/csv_writer.hpp + ${CSV_INCLUDE_DIR}/internal/data_type.hpp + ${CSV_INCLUDE_DIR}/external/hedley.h + ${CSV_INCLUDE_DIR}/external/mio.hpp + ${CSV_INCLUDE_DIR}/external/string_view.hpp) + + set_target_properties(csv PROPERTIES LINKER_LANGUAGE CXX) + target_link_libraries(csv PRIVATE Threads::Threads) + target_include_directories( + ${PROJECT_NAME} PUBLIC $ + $) + + include(${CMAKE_CURRENT_LIST_DIR}/cmake/getCPM.cmake) + + set(packageProject_VERSION 1.12.0) + cpmaddpackage( + NAME + PackageProject.cmake + VERSION + ${packageProject_VERSION} + URL + "https://github.com/TheLartians/PackageProject.cmake/archive/refs/tags/v${packageProject_VERSION}.zip" + ) + + string(TOLOWER ${PROJECT_NAME}/version.h VERSION_HEADER_LOCATION) + string(TOLOWER ${PROJECT_NAME}/export.h EXPORT_HEADER_LOCATION) + + set_property(TARGET ${PROJECT_NAME} PROPERTY VERSION ${PROJECT_VERSION}) + set_property(TARGET ${PROJECT_NAME} PROPERTY SOVERSION ${PROJECT_VERSION}) + + packageproject( + NAME + ${PROJECT_NAME} + VERSION + ${PROJECT_VERSION} + NAMESPACE + ${PROJECT_NAME} + BINARY_DIR + ${PROJECT_BINARY_DIR} + INCLUDE_DIR + ${PROJECT_SOURCE_DIR}/include + INCLUDE_DESTINATION + include/${PROJECT_NAME} + VERSION_HEADER + "${VERSION_HEADER_LOCATION}" + EXPORT_HEADER + "${EXPORT_HEADER_LOCATION}" + COMPATIBILITY + "AnyNewerVersion" + DISABLE_VERSION_SUFFIX + ON + DEPENDENCIES "Threads;" + ) endif() -## Main Library -add_subdirectory(${CSV_SOURCE_DIR}) - -# build the python binding for the library -if (${BUILD_PYTHON}) - message("Building Python bindings for the library.") - add_subdirectory(python) +# build the python binding for the library +if(${BUILD_PYTHON}) + message("Building Python bindings for the library.") + add_subdirectory(python) endif() -## Executables +# Executables option(CSV_BUILD_PROGRAMS "Allow to disable building of programs" ON) -if (CSV_BUILD_PROGRAMS) - add_subdirectory("programs") +if(CSV_BUILD_PROGRAMS) + add_subdirectory("programs") endif() -## Developer settings -if (CSV_DEVELOPER) - # Allow for performance profiling - if (MSVC) - target_link_options(csv PUBLIC /PROFILE) - endif() - - # More error messages. - if (UNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ +# Developer settings +if(CSV_DEVELOPER) + # Allow for performance profiling + if(MSVC) + target_link_options(csv PUBLIC /PROFILE) + endif() + + # More error messages. + if(UNIX) + set(CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} \ -Wall -Wextra -Wsign-compare \ -Wwrite-strings -Wpointer-arith -Winit-self \ -Wconversion -Wno-sign-conversion") - endif() - - # Generate a single header library - if(CMAKE_VERSION VERSION_LESS "3.12") - find_package(PythonInterp 3 QUIET) - else() - find_package(Python3 COMPONENTS Interpreter) - endif() - if(Python3_Interpreter_FOUND OR PYTHONINTERP_FOUND) - add_custom_target(generate_single_header - COMMAND ${Python3_EXECUTABLE} single_header.py > single_include/csv.hpp - COMMAND ${Python3_EXECUTABLE} single_header.py > single_include_test/csv.hpp - WORKING_DIRECTORY ${CSV_ROOT_DIR} - ) - # Single header compilation test - add_subdirectory(single_include_test) - else() - message(WARNING "Python3 not found, skipping target 'generate_single_header'.") - endif() - - # Documentation - find_package(Doxygen QUIET) - if(DOXYGEN_FOUND) - add_custom_target(doxygen - COMMAND ${DOXYGEN_EXECUTABLE} ${CSV_ROOT_DIR}/Doxyfile - WORKING_DIRECTORY ${CSV_ROOT_DIR} - ) - else() - message(WARNING "Doxygen not found, skipping target 'doxygen'.") - endif() - - ## Tests - enable_testing() - add_subdirectory("tests") - - # Code coverage - #find_program( GCOV_PATH gcov ) - #if(GCOV_PATH) - # set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/modules") - # include(CodeCoverage) - # append_coverage_compiler_flags() - # set(ENV{CSV_TEST_ROOT} ${CSV_TEST_DIR}) - # setup_target_for_coverage_gcovr_html( - # NAME csv_coverage - # EXECUTABLE csv_test - # EXCLUDE "tests/*" - # ) - #endif() + endif() + + # Generate a single header library + if(CMAKE_VERSION VERSION_LESS "3.12") + find_package(PythonInterp 3 QUIET) + else() + find_package(Python3 COMPONENTS Interpreter) + endif() + if(Python3_Interpreter_FOUND OR PYTHONINTERP_FOUND) + add_custom_target( + generate_single_header + COMMAND ${Python3_EXECUTABLE} single_header.py > single_include/csv.hpp + COMMAND ${Python3_EXECUTABLE} single_header.py > + single_include_test/csv.hpp + WORKING_DIRECTORY ${CSV_ROOT_DIR}) + # Single header compilation test + add_subdirectory(single_include_test) + else() + message( + WARNING "Python3 not found, skipping target 'generate_single_header'.") + endif() + + # Documentation + find_package(Doxygen QUIET) + if(DOXYGEN_FOUND) + add_custom_target( + doxygen + COMMAND ${DOXYGEN_EXECUTABLE} ${CSV_ROOT_DIR}/Doxyfile + WORKING_DIRECTORY ${CSV_ROOT_DIR}) + else() + message(WARNING "Doxygen not found, skipping target 'doxygen'.") + endif() + + # Tests + enable_testing() + add_subdirectory("tests") + + # Code coverage find_program( GCOV_PATH gcov ) if(GCOV_PATH) + # set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/modules") + # include(CodeCoverage) append_coverage_compiler_flags() + # set(ENV{CSV_TEST_ROOT} ${CSV_TEST_DIR}) + # setup_target_for_coverage_gcovr_html( NAME csv_coverage EXECUTABLE csv_test + # EXCLUDE "tests/*" ) endif() endif() diff --git a/cmake/getCPM.cmake b/cmake/getCPM.cmake new file mode 100644 index 0000000..b0ba04d --- /dev/null +++ b/cmake/getCPM.cmake @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.40.2) +set(CPM_HASH_SUM "c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) + +include(${CPM_DOWNLOAD_LOCATION}) + diff --git a/include/internal/CMakeLists.txt b/include/internal/CMakeLists.txt deleted file mode 100644 index 4cbf58c..0000000 --- a/include/internal/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -add_library(csv STATIC "") - -target_sources(csv - PRIVATE - basic_csv_parser.hpp - basic_csv_parser.cpp - col_names.cpp - col_names.hpp - common.hpp - csv_format.hpp - csv_format.cpp - csv_reader.hpp - csv_reader.cpp - csv_reader_iterator.cpp - csv_row.hpp - csv_row.cpp - csv_row_json.cpp - csv_stat.cpp - csv_stat.hpp - csv_utility.cpp - csv_utility.hpp - csv_writer.hpp - "data_type.hpp" - ) - -set_target_properties(csv PROPERTIES LINKER_LANGUAGE CXX) -target_link_libraries(csv PRIVATE Threads::Threads) -target_include_directories(csv INTERFACE ../)