Created
May 15, 2023 14:57
-
-
Save jpcofr/1bb678c18a3f6fb7cc6b44ea8237e7fb to your computer and use it in GitHub Desktop.
CMake configuration for 'challenge_project' with googletest unit testing and benchmarking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description: Build configuration for the "challenge_project", including unit tests with Google's googletest and performance | |
# benchmarks with Google's benchmark library. The executables generated are "my_test" for testing and "my_bench" | |
# for benchmarking. | |
# Compatibility: Requires CMake version 3.25 and a C++17 compatible compiler. | |
# Dependencies: Google's googletest (v1.13.0) and Google's benchmark (v1.7.1) libraries, pthread library. | |
cmake_minimum_required(VERSION 3.25) | |
set(CMAKE_CXX_STANDARD 17) | |
project(challenge_project) | |
include(ExternalProject) | |
set(EXTERNAL_DEPENDENCIES ${CMAKE_CURRENT_BINARY_DIR}/../external) | |
## Download and configure googletest | |
ExternalProject_Add( | |
gtest | |
GIT_REPOSITORY https://github.com/google/googletest.git | |
GIT_TAG v1.13.0 | |
PREFIX ${EXTERNAL_DEPENDENCIES}/gtest | |
INSTALL_COMMAND "" | |
UPDATE_COMMAND "" | |
) | |
# Get gtest ready for linking and including | |
ExternalProject_Get_Property(gtest SOURCE_DIR BINARY_DIR) | |
set(GTEST_LIB ${BINARY_DIR}/lib/libgtest.a) | |
include_directories(${SOURCE_DIR}/googletest/include) | |
## Download and configure google benchmark | |
ExternalProject_Add( | |
benchmark | |
GIT_REPOSITORY https://github.com/google/benchmark.git | |
GIT_TAG v1.7.1 | |
PREFIX ${EXTERNAL_DEPENDENCIES}/benchmark | |
INSTALL_COMMAND "" | |
UPDATE_COMMAND "" | |
CMAKE_ARGS -DBENCHMARK_ENABLE_TESTING=OFF | |
) | |
ExternalProject_Get_Property(benchmark SOURCE_DIR BINARY_DIR) | |
set(BENCHMARK_LIB ${BINARY_DIR}/src/libbenchmark.a) | |
include_directories(${SOURCE_DIR}/include) | |
## Configure executables | |
add_executable(my_test main.cpp solution.cpp tests.cpp) | |
add_executable(my_bench solution.cpp benchmarks.cpp) | |
target_link_libraries(my_test ${GTEST_LIB} pthread) | |
target_link_libraries(my_bench ${BENCHMARK_LIB} ${GTEST_LIB} pthread) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment