-
Notifications
You must be signed in to change notification settings - Fork 709
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Out with Eigen, in with FetchContent and gtest
- Loading branch information
Showing
26 changed files
with
230 additions
and
339 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,53 @@ | ||
# set minimum cmake version | ||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR) | ||
|
||
project(recipe-04 LANGUAGES CXX) | ||
# project name and language | ||
project(recipe-03 LANGUAGES CXX) | ||
|
||
# require C++11 | ||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
set_property(DIRECTORY PROPERTY EP_BASE ${CMAKE_BINARY_DIR}/subprojects) | ||
|
||
option(Eigen3_FORCE_SUPERBUILD "Always build Eigen3 on our own" OFF) | ||
|
||
add_subdirectory(external/upstream) | ||
|
||
include(ExternalProject) | ||
ExternalProject_Add(${PROJECT_NAME}_core | ||
DEPENDS | ||
eigen3_external | ||
SOURCE_DIR | ||
${CMAKE_CURRENT_SOURCE_DIR}/src | ||
CMAKE_ARGS | ||
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} | ||
-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} | ||
-DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS} | ||
-DCMAKE_CXX_STANDARD_REQUIRED=${CMAKE_CXX_STANDARD_REQUIRED} | ||
-DEigen3_DIR=${Eigen3_DIR} | ||
CMAKE_CACHE_ARGS | ||
-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} | ||
-DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH} | ||
BUILD_ALWAYS | ||
1 | ||
INSTALL_COMMAND | ||
"" | ||
) | ||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
|
||
# example library | ||
add_library(sum_integers sum_integers.cpp) | ||
|
||
# main code | ||
add_executable(sum_up main.cpp) | ||
target_link_libraries(sum_up sum_integers) | ||
|
||
# we will use the network to fetch Google Test sources | ||
# make it possible to disable unit tests when not on network | ||
option(ENABLE_UNIT_TESTS "Enable unit tests" ON) | ||
message(STATUS "Enable testing: ${ENABLE_UNIT_TESTS}") | ||
|
||
include(googletest.cmake) | ||
|
||
if(ENABLE_UNIT_TESTS) | ||
fetch_googletest( | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_CURRENT_BINARY_DIR}/googletest | ||
) | ||
|
||
add_executable(cpp_test "") | ||
|
||
target_sources(cpp_test | ||
PRIVATE | ||
test.cpp | ||
) | ||
|
||
target_link_libraries(cpp_test | ||
PRIVATE | ||
sum_integers | ||
gtest_main | ||
) | ||
|
||
enable_testing() | ||
|
||
add_test( | ||
NAME google_test | ||
COMMAND $<TARGET_FILE:cpp_test> | ||
) | ||
endif() |
4 changes: 0 additions & 4 deletions
4
chapter-08/recipe-04/cxx-example-3.5/external/upstream/CMakeLists.txt
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
chapter-08/recipe-04/cxx-example-3.5/external/upstream/eigen3/CMakeLists.txt
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
chapter-08/recipe-04/cxx-example-3.5/googletest-download.cmake
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# code copied from https://crascit.com/2015/07/25/cmake-gtest/ | ||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR) | ||
|
||
project(googletest-download LANGUAGES NONE) | ||
|
||
include(ExternalProject) | ||
|
||
ExternalProject_Add( | ||
googletest | ||
SOURCE_DIR "@GOOGLETEST_DOWNLOAD_ROOT@/googletest-src" | ||
BINARY_DIR "@GOOGLETEST_DOWNLOAD_ROOT@/googletest-build" | ||
GIT_REPOSITORY | ||
https://github.com/google/googletest.git | ||
GIT_TAG | ||
release-1.8.0 | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND "" | ||
INSTALL_COMMAND "" | ||
TEST_COMMAND "" | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# download and unpack googletest at configure time | ||
|
||
# the following code to fetch googletest | ||
# is inspired by and adapted after https://crascit.com/2015/07/25/cmake-gtest/ | ||
|
||
function(fetch_googletest _download_module_path _download_root) | ||
# Variable used in googletest-download.cmake | ||
set(GOOGLETEST_DOWNLOAD_ROOT ${_download_root}) | ||
configure_file( | ||
${_download_module_path}/googletest-download.cmake | ||
${_download_root}/CMakeLists.txt | ||
@ONLY | ||
) | ||
unset(GOOGLETEST_DOWNLOAD_ROOT) | ||
|
||
execute_process( | ||
COMMAND | ||
"${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" . | ||
WORKING_DIRECTORY | ||
${_download_root} | ||
) | ||
execute_process( | ||
COMMAND | ||
"${CMAKE_COMMAND}" --build . | ||
WORKING_DIRECTORY | ||
${_download_root} | ||
) | ||
|
||
# Prevent GoogleTest from overriding our compiler/linker options | ||
# when building with Visual Studio | ||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
# Prevent GoogleTest from using PThreads | ||
set(gtest_disable_pthreads ON CACHE BOOL "" FORCE) | ||
|
||
# adds the targets: gtest, gtest_main, gmock, gmock_main | ||
add_subdirectory( | ||
${_download_root}/googletest-src | ||
${_download_root}/googletest-build | ||
) | ||
|
||
# Silence std::tr1 warning on MSVC | ||
if(MSVC) | ||
foreach(_tgt gtest gtest_main gmock gmock_main) | ||
target_compile_definitions(${_tgt} | ||
PRIVATE | ||
"_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING" | ||
) | ||
endforeach() | ||
endif() | ||
endfunction() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../chapter-04/recipe-01/cxx-example/main.cpp |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,2 @@ | ||
appveyor-vs: | ||
definitions: | ||
- Eigen3_FORCE_SUPERBUILD: 'ON' | ||
|
||
appveyor-msys: | ||
definitions: | ||
- Eigen3_FORCE_SUPERBUILD: 'ON' | ||
|
||
travis-linux: | ||
definitions: | ||
- Eigen3_FORCE_SUPERBUILD: 'ON' | ||
|
||
# OpenMP does not work with clang | ||
travis-osx: | ||
definitions: | ||
- Eigen3_FORCE_SUPERBUILD: 'ON' | ||
failing_generators: | ||
- 'Unix Makefiles' | ||
- 'Ninja' | ||
|
||
local: | ||
definitions: | ||
- Eigen3_FORCE_SUPERBUILD: 'ON' | ||
env: | ||
- VERBOSE_OUTPUT: 'ON' | ||
targets: | ||
- test |
This file was deleted.
Oops, something went wrong.
62 changes: 0 additions & 62 deletions
62
chapter-08/recipe-04/cxx-example-3.5/src/linear-algebra.cpp
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../chapter-04/recipe-01/cxx-example/sum_integers.cpp |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../chapter-04/recipe-01/cxx-example/sum_integers.hpp |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../cxx-example/test.cpp |
Oops, something went wrong.