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/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..52fa367 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,62 @@ +cmake_minimum_required(VERSION 3.0) + +project("Docgen" VERSION 1.0.0 + DESCRIPTION "A C++ 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) + +# enables testing +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) +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(FILES + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) + +# 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") + +# 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) + +# find json library +find_package(nlohmann_json 3.2.0 REQUIRED) + +# 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 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@") 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 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}) 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