diff --git a/CMakeLists.txt b/CMakeLists.txt index f4a1c45..d567ad1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2023 Myvas Foundation # SPDX-License-Identifier: MIT +# Copyright (c) 2023 Myvas Foundation cmake_minimum_required(VERSION 3.25) @@ -10,12 +10,15 @@ cmake_minimum_required(VERSION 3.25) # (2) Add a new tag; # (3) Sync the download url in `README.md`. ############################################################################### -project(cmdout VERSION 0.1.23) +project(cmdout VERSION 0.2.0 + DESCRIPTION "a C++ library for executing a shell command and get its output." + LANGUAGES CXX +) set(CMDOUT_VERSION ${PROJECT_VERSION}) set(CMDOUT_SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}) # include modules -find_package(Threads) +find_package(Threads REQUIRED) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") include(utils) @@ -39,30 +42,13 @@ option(CMDOUT_BUILD_TESTING "Build tests" ${CMDOUT_MASTER_PROJECT}) option(CMDOUT_BUILD_EXAMPLES "Builds examples" ${CMDOUT_MASTER_PROJECT}) option(CMDOUT_BUILD_BENCHMARKS "Build benchmarks" ${CMDOUT_MASTER_PROJECT}) option(CMDOUT_INSTALL "Generate intall rules for the cmdout library" ON) -option(CMDOUT_DOCS_DOXYGEN "Build documentation with Doxygen." ${CMDOUT_MASTER_PROJECT}) -option(CMDOUT_DOCS_INSTALL "Install the cmdout docs" ${CMDOUT_MASTER_PROJECT}) -mark_as_advanced(CMDOUT_BUILD_TESTING CMDOUT_BUILD_EXAMPLES CMDOUT_BUILD_BENCHMARKS - CMDOUT_DOCS_DOXYGEN CMDOUT_DOCS_INSTALL - CMDOUT_INSTALL +option(CMDOUT_BUILD_SHARED_LIBS "Build a shared library, otherwise a static library" OFF) +mark_as_advanced(CMDOUT_BUILD_TESTING + CMDOUT_BUILD_EXAMPLES CMDOUT_BUILD_BENCHMARKS ) -message(STATUS "Build type: " ${CMAKE_BUILD_TYPE}) -message(STATUS "CMDOUT_BUILD_TESTING: ${CMDOUT_BUILD_TESTING}") -message(STATUS "CMDOUT_BUILD_EXAMPLES: ${CMDOUT_BUILD_EXAMPLES}") -message(STATUS "CMDOUT_BUILD_BENCHMARKS: ${CMDOUT_BUILD_BENCHMARKS}") message(STATUS "CMDOUT_INSTALL: ${CMDOUT_INSTALL}") -message(STATUS "CMDOUT_DOCS_DOXYGEN: ${CMDOUT_DOCS_DOXYGEN}") -message(STATUS "CMDOUT_DOCS_INSTALL: ${CMDOUT_DOCS_INSTALL}") - -# Advanced settings -option(CMDOUT_BUILD_SHARED "Build shared library" OFF) -option(CMDOUT_BUILD_PIC "Build position independent code (-fPIC)" ON) -option(CMDOUT_SANITIZE_ADDRESS "Enable address sanitizer in tests" OFF) -option(CMDOUT_BUILD_WARNINGS "Enable compiler warnings" OFF) -mark_as_advanced(CMDOUT_BUILD_SHARED CMDOUT_BUILD_PIC CMDOUT_SANITIZE_ADDRESS CMDOUT_BUILD_WARNINGS) -message(STATUS "CMDOUT_BUILD_SHARED: ${CMDOUT_BUILD_SHARED}") -message(STATUS "CMDOUT_BUILD_PIC: ${CMDOUT_BUILD_PIC}") -message(STATUS "CMDOUT_SANITIZE_ADDRESS: ${CMDOUT_SANITIZE_ADDRESS}") -message(STATUS "CMDOUT_BUILD_WARNINGS: ${CMDOUT_BUILD_WARNINGS}") +message(STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") +message(STATUS "CMDOUT_BUILD_SHARED_LIBS: ${CMDOUT_BUILD_SHARED_LIBS}") ############################## # main project: cmdout @@ -77,10 +63,6 @@ if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) set(CMAKE_CXX_EXTENSIONS OFF) endif() -if(CMDOUT_BUILD_PIC) - set(CMAKE_POSITION_INDEPENDENT_CODE ON) -endif() - ################################ # Build Static/Shared library ################################ @@ -90,36 +72,25 @@ set(CMDOUT_SRCS "src/cmdout_ext.cpp" "src/experimental/std_system_out.cpp" ) -if(CMDOUT_BUILD_SHARED OR BUILD_SHARED_LIBS) +if(CMDOUT_BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS) if(WIN32) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY) list(APPEND CMDOUT_SRCS ${CMAKE_CURRENT_BINARY_DIR}/version.rc) endif() - add_library(cmdout SHARED ${CMDOUT_SRCS} ${CMDOUT_ALL_HEADERS}) - target_compile_definitions(cmdout PUBLIC CMDOUT_SHARED_LIB) + add_library(cmdout SHARED ${CMDOUT_SRCS}) else() - add_library(cmdout STATIC ${CMDOUT_SRCS} ${CMDOUT_ALL_HEADERS}) + add_library(cmdout STATIC ${CMDOUT_SRCS}) endif() -add_library(myvas::cmdout ALIAS cmdout) - -target_compile_definitions(cmdout PUBLIC CMDOUT_COMPILED_LIB) -set(CMDOUT_TARGET_INCLUDE_DIRECTORIES - "$" - "$" +target_include_directories(cmdout PUBLIC + "$" + "$" ) -target_include_directories(cmdout PUBLIC ${CMDOUT_TARGET_INCLUDE_DIRECTORIES}) -message(STATUS "INCLUDE_DIRECTORIES: $") target_link_libraries(cmdout PUBLIC ${CMAKE_THREAD_LIBS_INIT}) -#set_target_properties(cmdout PROPERTIES COMPILE_FLAGS "-pthread" LINK_FLAGS "-pthread") -cmdout_enable_warnings(cmdout) - set_target_properties(cmdout PROPERTIES VERSION ${CMDOUT_VERSION} SOVERSION ${CMDOUT_SOVERSION} ) -if(CMDOUT_MASTER_PROJECT) - set_target_properties(cmdout PROPERTIES DEBUG_POSTFIX d) -endif() +add_library(myvas::cmdout ALIAS cmdout) ######################## # subprojects @@ -138,11 +109,11 @@ if(CMDOUT_BUILD_BENCHMARKS) add_subdirectory(benchmarks) endif() -################### -# install docs -################### include(GNUInstallDirs) -if (CMDOUT_DOCS_DOXYGEN) +if (CMDOUT_INSTALL) + ################### + # install docs + ################### # Require Doxygen 1.9.4 # apt install doxygen # Require GraphViz (dot) 2.43.0 @@ -185,80 +156,170 @@ if (CMDOUT_DOCS_DOXYGEN) docs include examples/src ALL WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMENT "Building documentation with Doxygen." - ) - - if (CMDOUT_INSTALL AND CMDOUT_DOCS_INSTALL) - install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html/" - DESTINATION ${CMAKE_INSTALL_DOCDIR} - ) - endif() -else() - if(CMDOUT_INSTALL AND CMDOUT_DOCS_INSTALL) - install(DIRECTORY "${PROJECT_SOURCE_DIR}/docs/" - DESTINATION ${CMAKE_INSTALL_DOCDIR} - ) - endif() -endif() - -########################## -# install cmdout library -########################## -include(GNUInstallDirs) -if(CMDOUT_INSTALL) - message(STATUS "Generating install") - - set(project_config_in "${CMAKE_CURRENT_LIST_DIR}/cmake/cmdoutConfig.cmake.in") - set(project_config_out "${CMAKE_CURRENT_BINARY_DIR}/cmdoutConfig.cmake") - set(config_targets_file "cmdoutConfigTargets.cmake") - set(version_config_file "${CMAKE_CURRENT_BINARY_DIR}/cmdoutConfigVersion.cmake") - set(export_dest_dir "${CMAKE_INSTALL_LIBDIR}/cmake/cmdout") - set(pkgconfig_install_dir "${CMAKE_INSTALL_LIBDIR}/pkgconfig") - set(pkg_config "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc") + ) + install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html/" + DESTINATION ${CMAKE_INSTALL_DOCDIR} + ) ################# # Install files - ################# - install(TARGETS cmdout - EXPORT cmdout - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - ) + ################# + # /include/xxx + install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) + # /lib/libxxx.a, libxxx.so + install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}Targets + # these get default values from GNUInstallDirs, no need to set them + #RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # bin + #LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # lib + #ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # lib + ) - ########################### - # Install pkg-config files - ########################### - set(PKG_CONFIG_VERSION_STRING ${CMD_VERSION}) - if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") - set(PKG_CONFIG_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}") - else() - set(PKG_CONFIG_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") - endif() - if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") - set(PKG_CONFIG_LIBDIR "${CMAKE_INSTALL_LIBDIR}") - else() - set(PKG_CONFIG_LIBDIR "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") - endif() - get_target_property(PKG_CONFIG_DEFINES cmdout INTERFACE_COMPILE_DEFINITIONS) - string(REPLACE ";" " -D" PKG_CONFIG_DEFINES "${PKG_CONFIG_DEFINES}") - string(CONCAT PKG_CONFIG_DEFINES "-D" "${PKG_CONFIG_DEFINES}") - configure_file("cmake/${PROJECT_NAME}.pc.in" "${pkg_config}" @ONLY) - install(FILES "${pkg_config}" DESTINATION "${pkgconfig_install_dir}") + # pkg-config files: /share/pkgconfig/xxx.pc + message(STATUS "Generating pkg-config files") + set(PKG_CONFIG_VERSION_STRING ${PROJECT_VERSION}) + if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") + set(PKG_CONFIG_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}") + else() + set(PKG_CONFIG_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") + endif() + if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") + set(PKG_CONFIG_LIBDIR "${CMAKE_INSTALL_LIBDIR}") + else() + set(PKG_CONFIG_LIBDIR "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") + endif() + get_target_property(PKG_CONFIG_CFLAGS ${PROJECT_NAME} INTERFACE_COMPILE_DEFINITIONS) + if(PKG_CONFIG_CFLAGS) + string(REPLACE ";" " -D" PKG_CONFIG_CFLAGS "${PKG_CONFIG_CFLAGS}") + string(CONCAT PKG_CONFIG_CFLAGS "-D" "${PKG_CONFIG_CFLAGS}") + else() + set(PKG_CONFIG_CFLAGS "") + endif() + configure_file("cmake/${PROJECT_NAME}.pc.in" "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc" @ONLY) + install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig" + ) - ############################# - # Install CMake config files - ############################# - export(TARGETS cmdout NAMESPACE myvas:: FILE "${CMAKE_CURRENT_BINARY_DIR}/${config_targets_file}") - install(EXPORT cmdout DESTINATION ${export_dest_dir} NAMESPACE myvas:: FILE ${config_targets_file}) + # CMake files + # /usr/lib/cmake/ + # Targets: xxxTargets.cmake + # find_package in Config mode: xxxConfig.cmake, xxxConfigVersion.cmake + export(TARGETS ${PROJECT_NAME} + #NAMESPACE myvas:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake" + ) + install(EXPORT ${PROJECT_NAME}Targets + #NAMESPACE myvas:: + FILE "${PROJECT_NAME}Targets.cmake" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}" + ) + include(CMakePackageConfigHelpers) + configure_package_config_file("${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}" + ) + write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + COMPATIBILITY SameMajorVersion + ) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}" + ) + + ###################################################### + # CPack + ###################################################### + # options + option(CAE_CPACK_BINARY_DEB "Pack a .deb file for deployment" ON) + option(CAE_CPACK_BINARY_STGZ "Pack a .sh file for deployment" OFF) + option(CAE_CPACK_BINARY_TGZ "Pack a .tar.gz file for deployment" OFF) + option(CAE_CPACK_BINARY_TXZ "Pack a .tar.xz file for deployment" OFF) + option(CAE_CPACK_SOURCE_TGZ "Pack a .tar.gz file for sourcecodes" OFF) + option(CAE_CPACK_SOURCE_TXZ "Pack a .tar.gz file for sourcecodes" ON) - include(CMakePackageConfigHelpers) - configure_package_config_file("${project_config_in}" "${project_config_out}" INSTALL_DESTINATION ${export_dest_dir}) + # config and properties + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPackOptions.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/CPackOptions.cmake" @ONLY) + set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/CPackOptions.cmake") - write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion) - install(FILES "${project_config_out}" "${version_config_file}" DESTINATION "${export_dest_dir}") + unset(CAE_CPACK_BINARY_GENERATOR_LIST) + if(CAE_CPACK_BINARY_DEB) + set(CPACK_BINARY_DEB "ON") + list(APPEND CAE_CPACK_BINARY_GENERATOR_LIST "DEB") + else() + set(CPACK_BINARY_DEB "OFF") + endif() + if(CAE_CPACK_BINARY_STGZ) + set(CPACK_BINARY_STGZ "ON") + list(APPEND CAE_CPACK_BINARY_GENERATOR_LIST "STGZ") + else() + set(CPACK_BINARY_STGZ "OFF") + endif() + if(CAE_CPACK_BINARY_TGZ) + set(CPACK_BINARY_TGZ "ON") + list(APPEND CAE_CPACK_BINARY_GENERATOR_LIST "TGZ") + else() + set(CPACK_BINARY_TGZ "OFF") + endif() + if(CAE_CPACK_BINARY_TXZ) + set(CPACK_BINARY_TXZ "ON") + list(APPEND CAE_CPACK_BINARY_GENERATOR_LIST "TXZ") + else() + set(CPACK_BINARY_TXZ "OFF") + endif() + set(CPACK_BINARY_TZ "OFF") + message(STATUS "CAE_CPACK_BINARY_GENERATOR_LIST: ${CAE_CPACK_BINARY_GENERATOR_LIST}") + set(CPACK_GENERATOR ${CAE_CPACK_BINARY_GENERATOR_LIST}) + + set(CPACK_SOURCE_IGNORE_FILES + # default ignore files in CPack.cmake + "/CVS/" + "/\\\\.svn/" + "/\\\\.bzr/" + "/\\\\.hg/" + "/\\\\.git/" + "\\\\.swp$" + "\\\\.#" + "/#" + + # Files specific to version control. + #"/\\\\.git/" + "/\\\\.gitattributes$" + "/\\\\.github/" + "/\\\\.gitignore$" + "/\\\\.hooks-config$" + + # Files produced by IDE. + "/\\\\.vs/" + "/\\\\.vscode/" + "/out/" + "/\\\\.build/" + + # Temporary files. + "~$" + + # Others + "/\\\\.readthedocs\\\\.yaml" + ) + unset(CAE_CPACK_SOURCE_GENERATOR_LIST) + if(CAE_CPACK_SOURCE_TGZ) + set(CPACK_SOURCE_TGZ "ON") + list(APPEND CAE_CPACK_SOURCE_GENERATOR_LIST "TGZ") + else() + set(CPACK_SOURCE_TGZ "OFF") + endif() + if(CAE_CPACK_SOURCE_TXZ) + set(CPACK_SOURCE_TXZ "ON") + list(APPEND CAE_CPACK_SOURCE_GENERATOR_LIST "TXZ") + else() + set(CPACK_SOURCE_TXZ "OFF") + endif() + set(CPACK_SOURCE_TZ "OFF") + set(CPACK_SOURCE_TBZ2 "OFF") + message(STATUS "CAE_CPACK_SOURCE_GENERATOR_LIST: ${CAE_CPACK_SOURCE_GENERATOR_LIST}") + set(CPACK_SOURCE_GENERATOR ${CAE_CPACK_SOURCE_GENERATOR_LIST}) - ########################################### - # Support creation of installable packages - ########################################### - include(cmake/cmdoutCPack.cmake) + include(CPack) endif() diff --git a/README.md b/README.md index 080687f..522354c 100644 --- a/README.md +++ b/README.md @@ -18,13 +18,13 @@ target_link_libraries( PRIVATE cmdout) ``` ### Include the header file ``` -#include +#include ``` ### Examples C++17 on GNU/Linux Debian 11 (bullseye) ``` -#include +#include #include //... int main() { diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index a7df559..46785bf 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2023 Myvas Foundation # SPDX-License-Identifier: MIT +# Copyright (c) 2023 Myvas Foundation cmake_minimum_required(VERSION 3.19) project(cmdout_benchmarks LANGUAGES CXX) diff --git a/benchmarks/cmake/benchmark.cmake b/benchmarks/cmake/benchmark.cmake index 3f55b10..15fe761 100644 --- a/benchmarks/cmake/benchmark.cmake +++ b/benchmarks/cmake/benchmark.cmake @@ -1,14 +1,18 @@ -# Copyright (c) 2023 Myvas Foundation # SPDX-License-Identifier: MIT +# Copyright (c) 2023 Myvas Foundation ############################################################################### # Find or fetch a CMake package: benchmark >=1.8.3 ############################################################################### set(benchmark_VERSION_REQUIRED 1.8.3) -find_package(benchmark ${benchmark_VERSION_REQUIRED} QUIET) -if(benchmark_FOUND) - message(STATUS "Found benchmark: ${benchmark_VERSION}") +if(TARGET benchmark::benchmark) + get_target_property(benchmark_VERSION benchmark::benchmark VERSION) + if(benchmark_VERSION VERSION_GREATER_EQUAL benchmark_VERSION_REQUIRED) + message(STATUS "Found benchmark: ${benchmark_VERSION}") + else() + message(FATAL_ERROR "Found benchmark: ${benchmark_VERSION}, but we need ${benchmark_VERSION_REQUIRED} or leater!") + endif() else() set(benchmark_DOWNLOAD_URL https://github.com/google/benchmark/archive/refs/tags/v${benchmark_VERSION_REQUIRED}.tar.gz) message(STATUS "CMake package benchmark ${benchmark_VERSION_REQUIRED} or later not found!" diff --git a/benchmarks/src/benchmarks.cpp b/benchmarks/src/benchmarks.cpp index 68dcc1e..46a5bab 100644 --- a/benchmarks/src/benchmarks.cpp +++ b/benchmarks/src/benchmarks.cpp @@ -1,14 +1,14 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * * @file benchmark_std_system.cpp * @brief benchmark for function std::system() with output. */ #include -#include -#include +#include +#include static void BM_std_system(benchmark::State &state) { diff --git a/cmake/CPackOptions.cmake.in b/cmake/CPackOptions.cmake.in new file mode 100644 index 0000000..62ce4b3 --- /dev/null +++ b/cmake/CPackOptions.cmake.in @@ -0,0 +1,49 @@ +# SPDX-License-Identifier: MIT +# Copyright (c) 2023 Myvas Foundation + +# CPack project config file + +# values of variables prefixed with CPACK_ will be escaped before being written +# to the configuration files. +set(CPACK_VERBATIM_VARIABLES YES) + +set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0) +set(CPACK_INSTALL_CMAKE_PROJECTS "@CMAKE_BINARY_DIR@" "@PROJECT_NAME@" ALL .) +set(CPACK_PROJECT_URL "https://github.com/myvas/cmdout") +set(CPACK_PACKAGE_VENDOR "Myvas Foundation") +set(CPACK_PACKAGE_CONTACT "FrankH <4848285@qq.com>") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "cmdout library") +set(CPACK_PACKAGE_RELOCATABLE ON CACHE BOOL "Build relocatable package") + +set(CPACK_PACKAGE_DESCRIPTION_FILE "@CMAKE_CURRENT_SOURCE_DIR@/README.md") +set(CPACK_RESOURCE_FILE_WELCOME "@CMAKE_CURRENT_SOURCE_DIR@/README.md") +set(CPACK_RESOURCE_FILE_LICENSE "@CMAKE_CURRENT_SOURCE_DIR@/LICENSE") +set(CPACK_RESOURCE_FILE_README "@CMAKE_CURRENT_SOURCE_DIR@/README.md") + +# that is if you want every group to have its own package, +# although the same will happen if this is not set (so it defaults to ONE_PER_GROUP) +# and CPACK_DEB_COMPONENT_INSTALL is set to YES +#set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP) +set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE) + +if(CPACK_GENERATOR MATCHES "DEB") + set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_CONTACT}") + + # package name for deb. If set, then instead of some-application-0.9.2-Linux.deb + # you'll get some-application_0.9.2_amd64.deb (note the underscores too) + set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) + + # without this you won't be able to pack only specified component + set(CPACK_DEB_COMPONENT_INSTALL YES) + + #set(CPACK_DEBIAN_PACKAGE_DEPENDS "xxx (>= v.v.v)") + + set(CPACK_DEBIAN_PACKAGE_SECTION "libs") + set(CPACK_DEBIAN_PACKAGE_NAME "@PROJECT_NAME@") + set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CPACK_PROJECT_URL}) + set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "@PROJECT_DESCRIPTION@") +endif() + +set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME}) +set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY ${CPACK_PACKAGE_NAME}) +#set(CPACK_OUTPUT_FILE_PREFIX "${CPACK_INSTALL_PREFIX}/../packages") diff --git a/cmake/cmdout.pc.in b/cmake/cmdout.pc.in index 427a359..8aec1a1 100644 --- a/cmake/cmdout.pc.in +++ b/cmake/cmdout.pc.in @@ -3,11 +3,11 @@ exec_prefix=${prefix} includedir=@PKG_CONFIG_INCLUDEDIR@ libdir=@PKG_CONFIG_LIBDIR@ -Name: cmdout -Description: cmdout - a C++ library for executing a shell command and get its output. +Name: @PROJECT_NAME@ +Description: @PROJECT_DESCRIPTION@ URL: https://github.com/myvas/cmdout Version: @PROJECT_VERSION@ -CFlags: -I${includedir} @PKG_CONFIG_DEFINES@ +CFlags: -I${includedir} @PKG_CONFIG_CFLAGS@ Libs: -L${libdir} -lcmdout -pthread -Requires: @PKG_CONFIG_REQUIRES@ +Requires: diff --git a/cmake/cmdoutCPack.cmake b/cmake/cmdoutCPack.cmake deleted file mode 100644 index 2e7a3e7..0000000 --- a/cmake/cmdoutCPack.cmake +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2023 Myvas Foundation -# SPDX-License-Identifier: MIT - -set(CPACK_GENERATOR "TGZ;ZIP" CACHE STRING "Semicolon separated list of generators") - -set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0) -set(CPACK_INSTALL_CMAKE_PROJECTS "${CMAKE_BINARY_DIR}" "${PROJECT_NAME}" ALL .) - -set(CPACK_PROJECT_URL "https://github.com/myvas/cmdout") -set(CPACK_PACKAGE_VENDOR "Myvas Foundation") -set(CPACK_PACKAGE_CONTACT "FrankH <4848285@qq.com>") -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "cmdout library") -set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) -set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) -set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) -set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) -if(PROJECT_VERSION_TWEAK) - set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}.${PROJECT_VERSION_TWEAK}) -endif() -set(CPACK_PACKAGE_RELOCATABLE ON CACHE BOOL "Build relocatable package") - -set(CPACK_RPM_PACKAGE_LICENSE "MIT") -set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries") -set(CPACK_DEBIAN_PACKAGE_SECTION "libs") -set(CPACK_RPM_PACKAGE_URL ${CPACK_PROJECT_URL}) -set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CPACK_PROJECT_URL}) -set(CPACK_RPM_PACKAGE_DESCRIPTION "cmdout library.") -set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "cmdout library.") - -if(CPACK_PACKAGE_NAME) - set(CPACK_RPM_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") - set(CPACK_DEBIAN_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") -else() - set(CPACK_RPM_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}") - set(CPACK_DEBIAN_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}") - set(CPACK_RPM_PACKAGE_NAME "${PROJECT_NAME}") - set(CPACK_DEBIAN_PACKAGE_NAME "${PROJECT_NAME}") -endif() - -if(CPACK_RPM_PACKAGE_RELEASE) - set(CPACK_RPM_FILE_NAME "${CPACK_RPM_FILE_NAME}-${CPACK_RPM_PACKAGE_RELEASE}") -endif() -if(CPACK_DEBIAN_PACKAGE_RELEASE) - set(CPACK_DEBIAN_FILE_NAME "${CPACK_DEBIAN_FILE_NAME}-${CPACK_DEBIAN_PACKAGE_RELEASE}") -endif() - -if(CPACK_RPM_PACKAGE_ARCHITECTURE) - set(CPACK_RPM_FILE_NAME "${CPACK_RPM_FILE_NAME}.${CPACK_RPM_PACKAGE_ARCHITECTURE}") -endif() -if(CPACK_DEBIAN_PACKAGE_ARCHITECTURE) - set(CPACK_DEBIAN_FILE_NAME "${CPACK_DEBIAN_FILE_NAME}.${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}") -endif() -set(CPACK_RPM_FILE_NAME "${CPACK_RPM_FILE_NAME}.rpm") -set(CPACK_DEBIAN_FILE_NAME "${CPACK_DEBIAN_FILE_NAME}.deb") - -if(NOT CPACK_PACKAGE_RELOCATABLE) - # Depend on pkgconfig rpm to create the system pkgconfig folder - set(CPACK_RPM_PACKAGE_REQUIRES pkgconfig) - set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION - "${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig") -endif() - -include(CPack) diff --git a/cmake/cmdoutConfig.cmake.in b/cmake/cmdoutConfig.cmake.in index 3465a72..d49fb5a 100644 --- a/cmake/cmdoutConfig.cmake.in +++ b/cmake/cmdoutConfig.cmake.in @@ -2,8 +2,6 @@ find_package(Threads REQUIRED) -set(config_targets_file @config_targets_file@) +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") -include("${CMAKE_CURRENT_LIST_DIR}/${config_targets_file}") - -check_required_components(cmdout) +check_required_components(@PROJECT_NAME@) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 5a75287..7583dec 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2023 Myvas Foundation # SPDX-License-Identifier: MIT +# Copyright (c) 2023 Myvas Foundation # Turn on warnings on the given target function(cmdout_enable_warnings target_name) @@ -35,4 +35,4 @@ function(cmdout_enable_sanitizer target_name) target_compile_options(${target_name} PRIVATE -fno-sanitize-recover=all) target_compile_options(${target_name} PRIVATE -fno-omit-frame-pointer) target_link_libraries(${target_name} PRIVATE -fsanitize=address,undefined -fuse-ld=gold) -endfunction() \ No newline at end of file +endfunction() diff --git a/docs/quickstart-cmake.md b/docs/quickstart-cmake.md index bdf84a5..f3ea629 100644 --- a/docs/quickstart-cmake.md +++ b/docs/quickstart-cmake.md @@ -79,7 +79,7 @@ As an example, create a file named `hello_test.cc` in your `my_project` directory with the following contents: ```cpp -#include +#include int main() { auto cmd = "ls ~ -C"; diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 911bb60..92627d6 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2023 Myvas Foundation # SPDX-License-Identifier: MIT +# Copyright (c) 2023 Myvas Foundation cmake_minimum_required(VERSION 3.19) project(cmdout_examples LANGUAGES CXX) diff --git a/examples/src/example_myvas_cmdout.cpp b/examples/src/example_myvas_cmdout.cpp index 38e66ca..83911b9 100644 --- a/examples/src/example_myvas_cmdout.cpp +++ b/examples/src/example_myvas_cmdout.cpp @@ -1,11 +1,11 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * * @file example_myvas_cmdout.cpp * @brief example for class myvas::cmdout. */ -#include +#include #include #include diff --git a/examples/src/example_myvas_system.cpp b/examples/src/example_myvas_system.cpp index d09ac6c..c7f1424 100644 --- a/examples/src/example_myvas_system.cpp +++ b/examples/src/example_myvas_system.cpp @@ -1,11 +1,11 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * * @file example_myvas_system.cpp * @brief example for function myvas::system(). */ -#include +#include #include #include diff --git a/examples/src/example_std_system.cpp b/examples/src/example_std_system.cpp index 2c215b5..e23e96d 100644 --- a/examples/src/example_std_system.cpp +++ b/examples/src/example_std_system.cpp @@ -1,6 +1,6 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * * @file example_std_system.cpp * @brief example for function std::system(). diff --git a/examples/src/example_std_system_out.cpp b/examples/src/example_std_system_out.cpp index 68b25de..a9c4683 100644 --- a/examples/src/example_std_system_out.cpp +++ b/examples/src/example_std_system_out.cpp @@ -1,11 +1,11 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * * @file example_std_system_out.cpp * @brief example for function std::system() to execute a shell command and get its output. */ -#include +#include #include #include diff --git a/include/cmdout/cmdout.hpp b/include/cmdout/cmdout.h similarity index 99% rename from include/cmdout/cmdout.hpp rename to include/cmdout/cmdout.h index d7d1012..183f236 100644 --- a/include/cmdout/cmdout.hpp +++ b/include/cmdout/cmdout.h @@ -1,8 +1,8 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * - * @file cmdout.hpp + * @file cmdout.h * @brief Class myvas::cmdout is used to execute a shell command and get its output, within timeout feature. * And function myvas::system() performs the executing logic. * diff --git a/include/cmdout/cmdout_ext.hpp b/include/cmdout/cmdout_ext.h similarity index 87% rename from include/cmdout/cmdout_ext.hpp rename to include/cmdout/cmdout_ext.h index e6427b1..f5ad287 100644 --- a/include/cmdout/cmdout_ext.hpp +++ b/include/cmdout/cmdout_ext.h @@ -1,13 +1,13 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * - * @file cmdout_ext.hpp + * @file cmdout_ext.h * @brief Helpers for myvas::cmdout. */ #pragma once -#include "cmdout.hpp" +#include "cmdout.h" #include diff --git a/include/cmdout/experimental/std_system_out.hpp b/include/cmdout/experimental/std_system_out.h similarity index 94% rename from include/cmdout/experimental/std_system_out.hpp rename to include/cmdout/experimental/std_system_out.h index 9100302..0175346 100644 --- a/include/cmdout/experimental/std_system_out.hpp +++ b/include/cmdout/experimental/std_system_out.h @@ -1,8 +1,8 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * - * @file cmdout_ext.hpp + * @file std_system_out.h * @brief Experimental functions for the benchmark control group. */ #pragma once diff --git a/src/cmdout.cpp b/src/cmdout.cpp index 072670e..2e04e1d 100644 --- a/src/cmdout.cpp +++ b/src/cmdout.cpp @@ -1,11 +1,11 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * * @file cmdout.cpp * @brief Implementation of class myvas::cmdout. */ -#include +#include namespace myvas { @@ -76,4 +76,4 @@ namespace myvas { return *this; } -} // namespace myvas \ No newline at end of file +} // namespace myvas diff --git a/src/cmdout_ext.cpp b/src/cmdout_ext.cpp index d262beb..fa390a4 100644 --- a/src/cmdout_ext.cpp +++ b/src/cmdout_ext.cpp @@ -1,11 +1,11 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * * @file cmdout.cpp * @brief Extensions for class myvas::cmdout. */ -#include +#include namespace myvas { diff --git a/src/experimental/std_system_out.cpp b/src/experimental/std_system_out.cpp index ffc7d66..072d66d 100644 --- a/src/experimental/std_system_out.cpp +++ b/src/experimental/std_system_out.cpp @@ -1,12 +1,12 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * * @file std_system_out.cpp * @brief Implementation of Experimental functions for the benchmark control group, * via function std::system() to execute a shell command and get its output. */ -#include "cmdout/experimental/std_system_out.hpp" +#include "cmdout/experimental/std_system_out.h" #include #include diff --git a/src/system.cpp b/src/system.cpp index d7b05fe..449ba31 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -1,11 +1,11 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * * @file system.cpp * @brief Implementation of function myvas::system(). */ -#include +#include #include #include @@ -90,4 +90,4 @@ cmdout system_timeout(const std::string& cmd, std::chrono::milliseconds timeout) return cmdout(cmd, timeout_ms); } -} // namespace myvas \ No newline at end of file +} // namespace myvas diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 420f3cf..1eac299 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,5 @@ -# Copyright (c) 2023 Myvas Foundation # SPDX-License-Identifier: MIT +# Copyright (c) 2023 Myvas Foundation cmake_minimum_required(VERSION 3.20) project(cmdout_tests LANGUAGES CXX) diff --git a/tests/cmake/Catch2.cmake b/tests/cmake/Catch2.cmake index 73e1ff2..0129280 100644 --- a/tests/cmake/Catch2.cmake +++ b/tests/cmake/Catch2.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2023 Myvas Foundation # SPDX-License-Identifier: MIT +# Copyright (c) 2023 Myvas Foundation #[========================================[.rst: Find or fetch a CMake package: Catch2 >=3.4.0 @@ -8,7 +8,7 @@ Find or fetch a CMake package: Catch2 >=3.4.0 #]========================================] set(Catch2_VERSION_REQUIRED 3.3.2) -find_package(Catch2 ${Catch2_VERSION_REQUIRED} QUIET) +find_package(Catch2 ${Catch2_VERSION_REQUIRED} QUIET CONFIG) if(Catch2_FOUND) message(STATUS "Found Catch2: ${Catch2_VERSION}") else() diff --git a/tests/cmake/GTest.cmake b/tests/cmake/GTest.cmake index f5a5ffa..274ca2c 100644 --- a/tests/cmake/GTest.cmake +++ b/tests/cmake/GTest.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2023 Myvas Foundation # SPDX-License-Identifier: MIT +# Copyright (c) 2023 Myvas Foundation #[========================================[.rst: Find or fetch a CMake package: gtest >=1.12.1 @@ -18,7 +18,7 @@ How to install googletest on Debian 12 (bookworm)? set(GTest_VERSION_REQUIRED 1.12.1) -find_package(GTest ${GTest_VERSION_REQUIRED} QUIET) +find_package(GTest ${GTest_VERSION_REQUIRED} QUIET CONFIG) if(GTest_FOUND) message(STATUS "Found GTest: ${GTest_VERSION}") else() diff --git a/tests/cmake/TestUtils.cmake b/tests/cmake/TestUtils.cmake index 0a55272..d1dee82 100644 --- a/tests/cmake/TestUtils.cmake +++ b/tests/cmake/TestUtils.cmake @@ -1,5 +1,5 @@ -# Copyright (c) 2023 Myvas Foundation # SPDX-License-Identifier: MIT +# Copyright (c) 2023 Myvas Foundation ############################################################################### # test utils diff --git a/tests/src/test_myvas_cmdout.cpp b/tests/src/test_myvas_cmdout.cpp index c8c1636..8e37bde 100644 --- a/tests/src/test_myvas_cmdout.cpp +++ b/tests/src/test_myvas_cmdout.cpp @@ -1,12 +1,12 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * * @file test_myvas_cmdout.cpp * @brief Unit test for class myvas::cmdout. */ -#include +#include #include diff --git a/tests/src/test_myvas_system.cpp b/tests/src/test_myvas_system.cpp index 711aade..2c403f5 100644 --- a/tests/src/test_myvas_system.cpp +++ b/tests/src/test_myvas_system.cpp @@ -1,12 +1,12 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * * @file test_myvas_system.cpp * @brief Unit test for function myvas::system(). */ -#include +#include #include diff --git a/tests/src/test_std_system.cpp b/tests/src/test_std_system.cpp index 166424d..b63cb53 100644 --- a/tests/src/test_std_system.cpp +++ b/tests/src/test_std_system.cpp @@ -1,6 +1,6 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * * @file test_std_system.cpp * @brief Unit test for function std::system(). diff --git a/tests/src/test_std_system_out.cpp b/tests/src/test_std_system_out.cpp index 1d5a624..7f2932d 100644 --- a/tests/src/test_std_system_out.cpp +++ b/tests/src/test_std_system_out.cpp @@ -1,13 +1,13 @@ /** - * Copyright (c) 2023 Myvas Foundation * SPDX-License-Identifier: MIT + * Copyright (c) 2023 Myvas Foundation * * @file test_myvas_system.cpp * @brief Unit test for function myvas::system(). */ #include -#include +#include TEST_CASE("std_system_out") {