Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

James.yang/cmake init #8

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libs/benchmark"]
path = libs/benchmark
url = https://github.com/google/benchmark.git
59 changes: 59 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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)

# add libs subdirectory
add_subdirectory(${PROJECT_SOURCE_DIR}/libs ${PROJECT_BINARY_DIR}/libs)
32 changes: 32 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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 <debug/release> [cmake options]" 1>&2
exit 1
fi

rm -rf ./*
cmake ../../ -GNinja "$@"
cmake --build . -- -j12
4 changes: 4 additions & 0 deletions cmake/DocgenConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")
15 changes: 15 additions & 0 deletions configure.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
1 change: 1 addition & 0 deletions libs/benchmark
Submodule benchmark added at 0811f1