Skip to content

Commit

Permalink
Fix bugs preventing use as a subproject
Browse files Browse the repository at this point in the history
This commit fixes seveal bugs preventing the project from being used as
a CMake subproject:

* The Commons module cannot be found because the path to the
cmake_modules folder is constructed relative to the CMAKE_SOURCE_DIR
rather than the CMAKE_CURRENT_SOURCE_DIR.

* googletest is downloaded to the CMAKE_BINARY_DIR rather than the
CMAKE_CURRENT_BINARY_DIR.
  • Loading branch information
Technius committed Dec 14, 2023
1 parent 87d93a3 commit f9479dd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.0.2)
project("sparta")

include(CTest)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
include(Commons)

if (NOT CMAKE_BUILD_TYPE)
Expand Down
8 changes: 4 additions & 4 deletions cmake_modules/Commons.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ macro(add_dependent_packages_for_sparta)
configure_file(cmake_modules/gtest.cmake.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download
)
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download
)
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
Expand All @@ -64,8 +64,8 @@ macro(add_dependent_packages_for_sparta)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(
${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build
${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL
)

Expand Down
4 changes: 2 additions & 2 deletions cmake_modules/gtest.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.1
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
Expand Down

0 comments on commit f9479dd

Please sign in to comment.