Skip to content

Commit

Permalink
Introduce CLAD_DISABLE_TESTS flag to build system
Browse files Browse the repository at this point in the history
The testing and benchmarking relies on a hack that temporariliy changes
the compiler flags. This doesn't work in all environments, and it would
be nice if the the tests could be disabled so it's possible to build
Clad without this hack.

This makes it possible to build Clad on NixOS.
  • Loading branch information
guitargeek authored and vgvassilev committed Jul 8, 2024
1 parent c37406d commit 354d7ad
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -324,28 +324,34 @@ if (NOT CLAD_BUILD_STATIC_ONLY)
add_subdirectory(demos/ErrorEstimation/CustomModel)
add_subdirectory(demos/ErrorEstimation/PrintModel)

# 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(stored_cxx_flags ${CMAKE_CXX_FLAGS})

set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang)
# Filter some unsupported flags by clang.
string(REPLACE "-fno-lifetime-dse" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "-Wno-class-memaccess" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
if (NOT CLAD_DISABLE_TESTS OR 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(stored_cxx_flags ${CMAKE_CXX_FLAGS})

set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang)
# Filter some unsupported flags by clang.
string(REPLACE "-fno-lifetime-dse" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "-Wno-class-memaccess" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()

add_subdirectory(unittests)
add_subdirectory(test)
if (NOT CLAD_DISABLE_TESTS)
add_subdirectory(unittests)
add_subdirectory(test)
endif()

# Add benchmarking infrastructure.
if (CLAD_ENABLE_BENCHMARKS)
add_subdirectory(benchmark)
endif(CLAD_ENABLE_BENCHMARKS)

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

# Workaround for MSVS10 to avoid the Dialog Hell
Expand Down

0 comments on commit 354d7ad

Please sign in to comment.