From f1bf5955d4cef39f98e98bda9105a9dcdefaf1e4 Mon Sep 17 00:00:00 2001 From: James Yang Date: Tue, 31 Dec 2019 00:00:46 -0500 Subject: [PATCH 1/7] Create CMakeLists.txt --- CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..6e42a54 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.7) + +project("Docgen" VERSION 1.0.0 + DESCRIPTION "A fast documentation generator.") + +# This will perform memcheck +include(CTest) + +# This is to make this library portable to other machines. +# This will be used for install. +include(GNUInstallDirs) + From 221b58ae9a77b02077ad969ada300e2acf34e22d Mon Sep 17 00:00:00 2001 From: James Yang Date: Tue, 31 Dec 2019 16:50:54 -0500 Subject: [PATCH 2/7] Add googlebenchmark as a submodule --- .gitmodules | 3 +++ libs/benchmark | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 libs/benchmark diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b1ca637 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libs/benchmark"] + path = libs/benchmark + url = https://github.com/google/benchmark.git diff --git a/libs/benchmark b/libs/benchmark new file mode 160000 index 0000000..0811f1d --- /dev/null +++ b/libs/benchmark @@ -0,0 +1 @@ +Subproject commit 0811f1d782455b3c80285bebf934a7045d845ed3 From 784dbfa18831a30099c8e5334d49c2d139841ec0 Mon Sep 17 00:00:00 2001 From: James Yang Date: Tue, 31 Dec 2019 16:51:21 -0500 Subject: [PATCH 3/7] Add CMakeLists in libs that builds googletest --- libs/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 libs/CMakeLists.txt diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt new file mode 100644 index 0000000..2a9448d --- /dev/null +++ b/libs/CMakeLists.txt @@ -0,0 +1,4 @@ +# Build googletest +add_library(gtest_main STATIC ${GTEST_DIR}/src/gtest-all.cc ${GTEST_DIR}/src/gtest_main.cc) +target_compile_features(gtest_main PRIVATE cxx_std_11) +target_include_directories(gtest_main PRIVATE ${GTEST_DIR}/include ${GTEST_DIR}) From f0ce2c166e66a9f15984a6f94a3f2a892b5203bd Mon Sep 17 00:00:00 2001 From: James Yang Date: Tue, 31 Dec 2019 16:53:07 -0500 Subject: [PATCH 4/7] Add root CMakeLists.txt --- CMakeLists.txt | 52 ++++++++++++++++++++++++++++++++++++++++++++++++-- configure.sh | 15 +++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100755 configure.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e42a54..68dc5d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.0) project("Docgen" VERSION 1.0.0 - DESCRIPTION "A fast documentation generator.") + DESCRIPTION "A C++ documentation generator.") # This will perform memcheck include(CTest) @@ -10,3 +10,51 @@ include(CTest) # This will be used for install. include(GNUInstallDirs) +# enables testing +enable_testing() + +# Set C++11 standard for project target +set(CMAKE_CXX_STANDARD 11) + +# Create DocgenConfigVersion.cmake which contains current project version +# This is supposed to help with (major) version compatibility. +include(CMakePackageConfigHelpers) +write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion) +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION + ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) + +install(EXPORT ${PROJECT_NAME}_Targets + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) + +install(FILES + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) + +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include DESTINATION ${CMAKE_INSTALL_PREFIX}) + +# Automate the choosing of config +# if CMAKE_BUILD_TYPE not defined +if (NOT CMAKE_BUILD_TYPE) + # if binary directory ends with "release", use release mode + if (${PROJECT_BINARY_DIR} MATCHES "release$") + set(CMAKE_BUILD_TYPE RELEASE) + # otherwise, use debug mode + else() + set(CMAKE_BUILD_TYPE DEBUG) + endif() +endif() +message(STATUS "Compiling in ${CMAKE_BUILD_TYPE} mode") + +# add test subdirectory +add_subdirectory(${PROJECT_SOURCE_DIR}/test ${PROJECT_BINARY_DIR}/test) + +# add libs subdirectory +add_subdirectory(${PROJECT_SOURCE_DIR}/libs ${PROJECT_BINARY_DIR}/libs) diff --git a/configure.sh b/configure.sh new file mode 100755 index 0000000..62d5db9 --- /dev/null +++ b/configure.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# If setup.sh was called before +if [ -d "libs/benchmark/googletest" ]; then + rm -rf libs/benchmark +fi + +# Update submodule if needed +git submodule update --remote +# Setup google benchmark and googletest +git clone https://github.com/google/googletest.git libs/benchmark/googletest +cd libs/benchmark +mkdir -p build && cd build +cmake ../ -GNinja +cmake --build . -- -j12 From be90180b9660105c835a8461844a306dc3309287 Mon Sep 17 00:00:00 2001 From: James Yang Date: Tue, 31 Dec 2019 16:56:20 -0500 Subject: [PATCH 5/7] Add cmake config.in --- cmake/DocgenConfig.cmake.in | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 cmake/DocgenConfig.cmake.in diff --git a/cmake/DocgenConfig.cmake.in b/cmake/DocgenConfig.cmake.in new file mode 100644 index 0000000..9c15f36 --- /dev/null +++ b/cmake/DocgenConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@") From a353b3d1a9cf9d97b4f787ea5eec098e12efa6ad Mon Sep 17 00:00:00 2001 From: James Yang Date: Tue, 31 Dec 2019 17:14:13 -0500 Subject: [PATCH 6/7] Add build script and take away some installers in CMakeLists --- CMakeLists.txt | 17 ++++++++--------- build.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) create mode 100755 build.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 68dc5d9..fe08082 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,11 @@ enable_testing() # Set C++11 standard for project target set(CMAKE_CXX_STANDARD 11) +# Set install destinations +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) + # Create DocgenConfigVersion.cmake which contains current project version # This is supposed to help with (major) version compatibility. include(CMakePackageConfigHelpers) @@ -28,18 +33,11 @@ configure_package_config_file( INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) -install(EXPORT ${PROJECT_NAME}_Targets - FILE ${PROJECT_NAME}Targets.cmake - NAMESPACE ${PROJECT_NAME}:: - DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) - install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) -install(DIRECTORY ${PROJECT_SOURCE_DIR}/include DESTINATION ${CMAKE_INSTALL_PREFIX}) - # Automate the choosing of config # if CMAKE_BUILD_TYPE not defined if (NOT CMAKE_BUILD_TYPE) @@ -53,8 +51,9 @@ if (NOT CMAKE_BUILD_TYPE) endif() message(STATUS "Compiling in ${CMAKE_BUILD_TYPE} mode") -# add test subdirectory -add_subdirectory(${PROJECT_SOURCE_DIR}/test ${PROJECT_BINARY_DIR}/test) +# Points to the root of Google Test +set(GTEST_DIR ${PROJECT_SOURCE_DIR}/libs/benchmark/googletest/googletest) +set(GBENCH_DIR ${PROJECT_SOURCE_DIR}/libs/benchmark) # add libs subdirectory add_subdirectory(${PROJECT_SOURCE_DIR}/libs ${PROJECT_BINARY_DIR}/libs) diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..39dfc25 --- /dev/null +++ b/build.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# directory where current shell script resides +PROJECTDIR=$(dirname "$BASH_SOURCE") + +cd "$PROJECTDIR" + +mode=$1 # debug/release mode +shift # shift command-line arguments + # the rest are cmake command-line arguments + +mkdir -p build && cd build + +# if debug directory does not exist, create it +mkdir -p debug +# if release directory does not exist, create it +mkdir -p release + +# if debug mode +if [ "$mode" = "debug" ]; then + cd debug +# if release mode +elif [ "$mode" = "release" ]; then + cd release +else + echo "Usage: ./build.sh [cmake options]" 1>&2 + exit 1 +fi + +rm -rf ./* +cmake ../../ -GNinja "$@" +cmake --build . -- -j12 From ba6307fbf60026777b9cabd46ad8d841d1f4feb1 Mon Sep 17 00:00:00 2001 From: James Yang Date: Tue, 31 Dec 2019 20:56:34 -0500 Subject: [PATCH 7/7] Add json library in CMake --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe08082..52fa367 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,5 +55,8 @@ message(STATUS "Compiling in ${CMAKE_BUILD_TYPE} mode") set(GTEST_DIR ${PROJECT_SOURCE_DIR}/libs/benchmark/googletest/googletest) set(GBENCH_DIR ${PROJECT_SOURCE_DIR}/libs/benchmark) +# find json library +find_package(nlohmann_json 3.2.0 REQUIRED) + # add libs subdirectory add_subdirectory(${PROJECT_SOURCE_DIR}/libs ${PROJECT_BINARY_DIR}/libs)