From 00728a67ada72c2a9e49a6b11f19aaa528ed745c Mon Sep 17 00:00:00 2001 From: KOLANICH Date: Fri, 13 Aug 2021 20:42:46 +0300 Subject: [PATCH] Added building using CMake and packaging using CPack --- .gitmodules | 11 +++++ CMakeLists.txt | 79 +++++++++++++++++++++++++++++++++++ cmake/thirdParty/Boilerplate | 1 + cmake/thirdParty/DoxygenUtils | 1 + 4 files changed, 92 insertions(+) create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 160000 cmake/thirdParty/Boilerplate create mode 160000 cmake/thirdParty/DoxygenUtils diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..37a0379 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,11 @@ +[submodule "cmake/thirdParty/Boilerplate"] + path = cmake/thirdParty/Boilerplate + url = https://github.com/KOLANICH-libs/Boilerplate.cmake + branch = master + shallow = true + +[submodule "cmake/thirdParty/DoxygenUtils"] + path = cmake/thirdParty/DoxygenUtils + url = https://github.com/KOLANICH-libs/DoxygenUtils.cmake + branch = master + shallow = true diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..810b896 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,79 @@ +cmake_minimum_required(VERSION 3.7.2) + +set(CMAKE_USE_RELATIVE_PATHS TRUE) +project("SimpleOpt") +set("PROJECT_DESCRIPTION" "An another command-line parser class for C++ that has features not available in alternative solutions (getopt, boost, argtable, argstream, gflags) and doesn't require a steep learning curve.") +set("PROJECT_HOMEPAGE_URL" "https://github.com/brofield/simpleopt") + +set(CPACK_PACKAGE_VENDOR "Brodie Thiesfield et al.") +set(CPACK_PACKAGE_VERSION_MAJOR "0") +set(CPACK_PACKAGE_VERSION_MINOR "2") +set(CPACK_PACKAGE_VERSION_PATCH "2") +set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") + +set(OUR_CMAKE_MODULES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +set(OUR_CMAKE_3PARTY_MODULES_DIR "${OUR_CMAKE_MODULES_DIR}/thirdParty") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${OUR_CMAKE_MODULES_DIR}" "${OUR_CMAKE_3PARTY_MODULES_DIR}" "${OUR_CMAKE_3PARTY_MODULES_DIR}/Boilerplate" "${OUR_CMAKE_3PARTY_MODULES_DIR}/DoxygenUtils") + + +include(Boilerplate) +include(DoxygenUtils) + +set(Include_dir "${CMAKE_CURRENT_SOURCE_DIR}/include") +set(Examples_Dir "${CMAKE_CURRENT_SOURCE_DIR}/examples") + +buildAndPackageLib(${PROJECT_NAME} + TYPE INTERFACE + COMPONENT "lib" + DESCRIPTION "${PROJECT_DESCRIPTION}" + PUBLIC_INCLUDES ${Include_dir} + DO_NOT_PASSTHROUGH +) + +option(WITH_EXAMPLES "Build examples" OFF) +if(WITH_EXAMPLES) + file(GLOB_RECURSE EXAMPLES "${Examples_Dir}/*.cpp") + foreach(example ${EXAMPLES}) + get_filename_component(exampleName "${example}" NAME_WE) + add_executable("${exampleName}" "${example}") + harden("${exampleName}") + add_sanitizers("${exampleName}") + target_include_directories("${exampleName}" PRIVATE "${Include_dir}") + endforeach() +endif() + +option(WITH_DOCS "Build docs" ON) +if(WITH_DOCS) + find_package(Doxygen REQUIRED dot) + load_doxyfile("${CMAKE_CURRENT_SOURCE_DIR}/simpleopt.doxy") + + set(DOXYGEN_PROJECT_BRIEF "${CPACK_PACKAGE_DESCRIPTION}") + set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "${CPACK_RESOURCE_FILE_README}") + + set("DOXYGEN_GENERATE_HTML" YES) + set("DOXYGEN_GENERATE_MAN" YES) + + set("DOXYGEN_PROJECT_BRIEF" "${PROJECT_DESCRIPTION}") + + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + message(STATUS "Compiler is CLang, enabling CLang-assisted parsing in Doxygen.") + set(DOXYGEN_CLANG_ASSISTED_PARSING YES) + set(DOXYGEN_CLANG_OPTIONS "-I${Include_dir}") + endif() + + set(DOXYGEN_EXAMPLE_PATH "${Examples_Dir}") + set(DOXYGEN_STRIP_FROM_PATH "${Include_dir}") + set(DOXYGEN_STRIP_FROM_INC_PATH "${Include_dir}") + + + file(GLOB HEADERS "${Include_dir}/*.h" "${Include_dir}/*.hxx" "${Include_dir}/*.hpp") + doxygen_add_docs(docs + "${HEADERS}" + ALL + USE_STAMP_FILE + ) +endif() + +#pass_through_cpack_vars() + +include(CPack) diff --git a/cmake/thirdParty/Boilerplate b/cmake/thirdParty/Boilerplate new file mode 160000 index 0000000..81002ed --- /dev/null +++ b/cmake/thirdParty/Boilerplate @@ -0,0 +1 @@ +Subproject commit 81002ed36d2e5017f493a19530802f0d3da550b6 diff --git a/cmake/thirdParty/DoxygenUtils b/cmake/thirdParty/DoxygenUtils new file mode 160000 index 0000000..ad6b4d2 --- /dev/null +++ b/cmake/thirdParty/DoxygenUtils @@ -0,0 +1 @@ +Subproject commit ad6b4d201738fdd27b2694e3d1c56b467b3335c0