Skip to content

Commit

Permalink
[cmake] Use the compiler clad is built for if compiling benchmarks an…
Browse files Browse the repository at this point in the history
…d tests.

We need to attach the clad plugin to the compiler invocations in order to
either benchmark or test clad's infrastructure. The best way I could find is by
setting/resetting the CMAKE_CXX_COMPILER variable which is a hack that works.
Note that we do not have a cmake guarantee that will work but since that's in
the core of our testing infrastructure we will find out quickly if, when and
where it breaks.
  • Loading branch information
vgvassilev committed Jan 5, 2024
1 parent 7449329 commit ed4238e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,20 @@ if (CLAD_INCLUDE_DOCS)
add_subdirectory(docs)
endif()


if (NOT CLAD_BUILD_STATIC_ONLY)
include(AddClad)

if (CLAD_ENABLE_BENCHMARKS)
include(GoogleBenchmark)
endif(CLAD_ENABLE_BENCHMARKS)

# Change the default compiler to the clang which we run clad upon. Our unittests
# need to use a supported by clad compiler. Note that's a huge hack and it is
# not guaranteed to work with cmake.
set(stored_cxx_compiler ${CMAKE_CXX_COMPILER})
set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang)

add_subdirectory(unittests)
add_subdirectory(test)
add_subdirectory(demos/ErrorEstimation/CustomModel)
Expand All @@ -307,6 +319,8 @@ if (NOT CLAD_BUILD_STATIC_ONLY)
add_subdirectory(benchmark)
endif(CLAD_ENABLE_BENCHMARKS)

# Restore the default compiler.
set(CMAKE_CXX_COMPILER ${stored_cxx_compiler})
endif()

# Workaround for MSVS10 to avoid the Dialog Hell
Expand Down
2 changes: 0 additions & 2 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
set(CTEST_BUILD_NAME ${ROOT_ARCHITECTURE}-${CMAKE_BUILD_TYPE})
enable_testing()

include(GoogleBenchmark)

CB_ADD_GBENCHMARK(Simple Simple.cpp)
CB_ADD_GBENCHMARK(AlgorithmicComplexity AlgorithmicComplexity.cpp)
CB_ADD_GBENCHMARK(ArrayExpressionTemplates ArrayExpressionTemplates.cpp)
Expand Down
3 changes: 0 additions & 3 deletions cmake/modules/AddClad.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ string(REPLACE "/" "" CURRENT_REPO_COMMIT ${CURRENT_REPO_COMMIT})
set_property(DIRECTORY APPEND PROPERTY
CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/.git/HEAD")

# Change the default compiler to the clang which we run clad upon.
set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang)

#-------------------------------------------------------------------------------
# function ENABLE_CLAD_FOR_EXECUTABLE(<executable>
# DEPENDS dependencies...
Expand Down
2 changes: 1 addition & 1 deletion unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ endif()
# Will compile the list of files together and link against clad.
# Produces a binary named 'basename(test_dirname)'.
function(add_clad_unittest test_dirname)

add_unittest(CladUnitTests ${test_dirname} ${ARGN})

# Remove the llvm_gtest_* coming from add_unittest.
Expand All @@ -32,4 +33,3 @@ function(add_clad_unittest test_dirname)
endfunction()

add_subdirectory(Basic)

0 comments on commit ed4238e

Please sign in to comment.