Skip to content

Commit

Permalink
Merge branch 'feat/95' into 'devel'
Browse files Browse the repository at this point in the history
[CMake] Makes unit tests configure time option

Closes #95

See merge request tuda-sc/projects/metacg!121
  • Loading branch information
jplehr committed Aug 14, 2023
2 parents 3cb8d31 + bf40004 commit d40f4ea
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 42 deletions.
16 changes: 16 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ build-dependencies:
#

# Stage: build
build-mcg-no-tests:
<<: *job-setup
stage: build
script:
- module load clang/$LLVM
- cmake -S . -B $MCG_BUILD-no-tests -G Ninja -DCMAKE_BUILD_TYPE=Debug
-DCMAKE_INSTALL_PREFIX=/tmp/metacg/$MCG_BUILD-no-tests
-DCUBE_LIB=$(dirname $(which cube_info))/../lib
-DCUBE_INCLUDE=$(dirname $(which cube_info))/../include/cubelib
-DEXTRAP_INCLUDE=./extern/install/extrap/include
-DEXTRAP_LIB=./extern/install/extrap/lib
-DSPDLOG_BUILD_SHARED=ON -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
-DMETACG_BUILD_UNIT_TESTS=OFF
- cmake --build $MCG_BUILD-no-tests --parallel
- module purge

build-mcg-stripped-all:
<<: *job-setup
stage: build
Expand Down
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ list(

set(METACG_Directory ${CMAKE_CURRENT_SOURCE_DIR})

# Whether the GoogleTest-based unit tests should be built and GoogleTest is downloaded as dependency This needs to be
# here, so ToolchainOptions already "sees" the option's value
option(
METACG_BUILD_UNIT_TESTS
"On or Off"
ON
)

# This also downloads and builds googletest
include(ToolchainOptions)
# Making packaging easier
Expand Down
82 changes: 42 additions & 40 deletions cmake/ToolchainOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,45 +88,47 @@ function(target_project_compile_definitions target)
endif()
endfunction()

# Download and unpack googletest at configure time
configure_file(cmake/GoogleTest.cmake.in googletest-download/CMakeLists.txt)
execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
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_CURRENT_BINARY_DIR}/googletest-download
)
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
if(METACG_BUILD_UNIT_TESTS)
# Download and unpack googletest at configure time
configure_file(cmake/GoogleTest.cmake.in googletest-download/CMakeLists.txt)
execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
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_CURRENT_BINARY_DIR}/googletest-download
)
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()

# Prevent overriding the parent project's compiler/linker settings on Windows
set(gtest_force_shared_crt
ON
CACHE BOOL
""
FORCE
)

# Add googletest directly to our build. This defines the gtest and gtest_main targets.
add_subdirectory(
${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL
)

# The gtest/gtest_main targets carry header search path dependencies automatically when using CMake 2.8.11 or later.
# Otherwise we have to add them here ourselves.
if(CMAKE_VERSION
VERSION_LESS
2.8.11
)
include_directories("${gtest_SOURCE_DIR}/include")
# Prevent overriding the parent project's compiler/linker settings on Windows
set(gtest_force_shared_crt
ON
CACHE BOOL
""
FORCE
)

# Add googletest directly to our build. This defines the gtest and gtest_main targets.
add_subdirectory(
${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL
)

# The gtest/gtest_main targets carry header search path dependencies automatically when using CMake 2.8.11 or later.
# Otherwise we have to add them here ourselves.
if(CMAKE_VERSION
VERSION_LESS
2.8.11
)
include_directories("${gtest_SOURCE_DIR}/include")
endif()
endif()
4 changes: 3 additions & 1 deletion graph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ add_config_include(metacg)
add_json(metacg)
add_spdlog_libraries(metacg)

add_subdirectory(test/unit)
if(METACG_BUILD_UNIT_TESTS)
add_subdirectory(test/unit)
endif()
4 changes: 3 additions & 1 deletion pgis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ enable_testing()

add_subdirectory(lib)
add_subdirectory(tool)
add_subdirectory(test/unit)
if(METACG_BUILD_UNIT_TESTS)
add_subdirectory(test/unit)
endif()

0 comments on commit d40f4ea

Please sign in to comment.