Skip to content

Commit

Permalink
[cmake] Clean up flags and treat warnings as errors in the ci.
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvassilev committed Feb 14, 2024
1 parent 16a652b commit 9f3556d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
clang-runtime: '11'
coverage: true
cuda: true
extra_cmake_options: '-DLLVM_ENABLE_WERROR=On -DCLAD_ENABLE_ENZYME_BACKEND=On'
extra_cmake_options: '-DCLAD_ENABLE_ENZYME_BACKEND=On'
#clang-format: true

- name: ubu20-gcc7-runtime11-benchmarks
Expand Down Expand Up @@ -739,6 +739,7 @@ jobs:
-DCMAKE_BUILD_TYPE=$([[ -z "$BUILD_TYPE" ]] && echo RelWithDebInfo || echo $BUILD_TYPE) \
-DCLAD_CODE_COVERAGE=${CLAD_CODE_COVERAGE} \
-DLLVM_EXTERNAL_LIT="`which lit`" \
-DLLVM_ENABLE_WERROR=On \
$GITHUB_WORKSPACE \
${{ matrix.extra_cmake_options }}
Expand Down
18 changes: 7 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
# In rare cases we might want to have clang installed in a different place
# than llvm and the header files should be found first (even though the
# LLVM_INCLUDE_DIRS) contain clang headers, too.
include_directories(${CLANG_INCLUDE_DIRS})
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(SYSTEM ${CLANG_INCLUDE_DIRS})
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})

# If the llvm sources are present add them with higher priority.
Expand All @@ -176,13 +176,13 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
#
# FIXME: We only support in-tree builds of clang, that is clang being built
# in llvm_src/tools/clang.
include_directories(${LLVM_BUILD_MAIN_SRC_DIR}/tools/clang/include/)
include_directories(SYSTEM ${LLVM_BUILD_MAIN_SRC_DIR}/tools/clang/include/)

if (NOT LLVM_BUILD_BINARY_DIR)
message(FATAL "LLVM_BUILD_* values should be available for the build tree")
endif()

include_directories(${LLVM_BUILD_BINARY_DIR}/tools/clang/include/)
include_directories(SYSTEM ${LLVM_BUILD_BINARY_DIR}/tools/clang/include/)
endif()

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/)
Expand Down Expand Up @@ -224,24 +224,19 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
"`CMakeFiles'. Please delete them.")
endif()

# Add appropriate flags for GCC
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings")
endif ()

if (APPLE)
set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-undefined -Wl,dynamic_lookup")
endif ()

# FIXME: Use merge this with the content from the LLVMConfig and ClangConfig.
if (NOT CLAD_BUILT_STANDALONE)
include_directories(BEFORE
include_directories(BEFORE SYSTEM
${CMAKE_CURRENT_BINARY_DIR}/../clang/include
${CMAKE_CURRENT_SOURCE_DIR}/../clang/include
)
endif()

include_directories(BEFORE
include_directories(BEFORE SYSTEM
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include
)
Expand Down Expand Up @@ -312,6 +307,7 @@ if (NOT CLAD_BUILD_STATIC_ONLY)
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}")

add_subdirectory(unittests)
add_subdirectory(test)
Expand Down
14 changes: 13 additions & 1 deletion cmake/modules/CladGoogleTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,22 @@ endif()

# Remove the coverage flags when compiling external libraries.
string(REPLACE "${GCC_COVERAGE_COMPILE_FLAGS}" "" CMAKE_CXX_FLAGS_NOCOV "${CMAKE_CXX_FLAGS}")
string(REPLACE "${GCC_COVERAGE_COMPILE_FLAGS}" "" CMAKE_C_FLAGS_NOCOV "${CMAKE_C_FLAGS}")
string(REPLACE "${GCC_COVERAGE_COMPILE_FLAGS}" "" CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS_NOCOV "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}")
string(REPLACE "${GCC_COVERAGE_LINK_FLAGS}" "" CMAKE_EXE_LINKER_FLAGS_NOCOV "${CMAKE_EXE_LINKER_FLAGS}")
string(REPLACE "${GCC_COVERAGE_LINK_FLAGS}" "" CMAKE_SHARED_LINKER_FLAGS_NOCOV "${CMAKE_SHARED_LINKER_FLAGS}")

# Turn off -Werror for external packages.
if (LLVM_ENABLE_WERROR)
if (MSVC)
set(CMAKE_CXX_FLAGS_NOCOV "${CMAKE_CXX_FLAGS_NOCOV} /w ")
set(CMAKE_C_FLAGS_NOCOV "${CMAKE_C_FLAGS_NOCOV} /w ")
elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE)
set(CMAKE_CXX_FLAGS_NOCOV "${CMAKE_CXX_FLAGS_NOCOV} -Wno-error ")
set(CMAKE_C_FLAGS_NOCOV "${CMAKE_C_FLAGS_NOCOV} -Wno-error ")
endif()
endif(LLVM_ENABLE_WERROR)

include(ExternalProject)
ExternalProject_Add(
googletest
Expand All @@ -41,7 +53,7 @@ ExternalProject_Add(
CMAKE_ARGS -G ${CMAKE_GENERATOR}
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS_NOCOV}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS_NOCOV}
-DCMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS=${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS_NOCOV}
Expand Down
7 changes: 1 addition & 6 deletions lib/Differentiator/CladUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,8 @@ namespace clad {
}

void VisitBinaryOperator(clang::BinaryOperator* BO) {
if (BO->isAssignmentOp() || BO->isCompoundAssignmentOp()) {
if (BO->isAssignmentOp() || BO->isCompoundAssignmentOp())
Visit(BO->getLHS());
} else if (BO->getOpcode() == clang::BO_Comma) {
/**/
} else {
assert("Unexpected binary operator!!");
}
}

void VisitConditionalOperator(clang::ConditionalOperator* CO) {
Expand Down
2 changes: 2 additions & 0 deletions lib/Differentiator/VisitorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ namespace clad {
#pragma warning(push, 0)
#endif // MSVC
#pragma GCC diagnostic push
#ifdef __clang__
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#endif // __clang__
#pragma GCC diagnostic ignored "-Wnon-template-friend"
friend type get(Tag);
#pragma GCC diagnostic pop
Expand Down

0 comments on commit 9f3556d

Please sign in to comment.