Skip to content

Commit

Permalink
fixing build when ENABLE_CLANG_JIT is disabled (iovisor#3201)
Browse files Browse the repository at this point in the history
attempting a cmake build with `ENABLE_CLANG_JIT` disabled and not `PYTHON_ONLY` fails with the following output:

root@4ec15b1c6d03:~/src/bcc/tmp# cmake -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD:STRING=20 -DCMAKE_C_FLAGS="-fPIC" -DCMAKE_INSTALL_PREFIX:PATH=/root/opt -DENABLE_CPP_API=ON -DENABLE_LLVM_NATIVECODEGEN=ON -DENABLE_LLVM_SHARED=OFF -DENABLE_MAN=OFF -DENABLE_RTTI=OFF -DINSTALL_CPP_EXAMPLES=OFF -DENABLE_CLANG_JIT=OFF ../src
-- Latest recognized Git tag is v0.17.0
-- Git HEAD is ad5b82a
-- Revision is 0.17.0-ad5b82a5
CMake Error at src/cc/CMakeLists.txt:31 (string):
  string sub-command REGEX, mode MATCH needs at least 5 arguments total to
  command.


CMake Error at src/cc/CMakeLists.txt:61 (if):
  if given arguments:

    "VERSION_EQUAL" "6" "OR" "VERSION_GREATER" "6"

  Unknown arguments specified


-- Configuring incomplete, errors occurred!
See also "/root/src/bcc/tmp/CMakeFiles/CMakeOutput.log".
```

The reason for the failure is that `LLVM` is required by [`src/cc/CMakeLists.txt`](https://github.com/iovisor/bcc/blob/297512a31ecc9ceebf79bda169350dace0f36757/src/cc/CMakeLists.txt#L61), which is included for non `PYTHON_ONLY` builds by [`src/CMakeLists.txt`](https://github.com/iovisor/bcc/blob/297512a31ecc9ceebf79bda169350dace0f36757/src/CMakeLists.txt#L16). Yet, `LLVM` is only looked up by [`/CMakeLists.txt`](https://github.com/iovisor/bcc/blob/297512a31ecc9ceebf79bda169350dace0f36757/CMakeLists.txt#L54) whenever `ENABLE_CLANG_JIT` is enabled.

The proposed fix looks up `LLVM` whenever `PYTHON_ONLY` is disabled, even if `ENABLE_CLANG_JIT` is disabled.

This is the output after the fix is applied:
```
root@4ec15b1c6d03:~/src/bcc/tmp# cmake -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD:STRING=20 -DCMAKE_C_FLAGS="-fPIC" -DCMAKE_INSTALL_PREFIX:PATH=/root/opt -DENABLE_CPP_API=ON -DENABLE_LLVM_NATIVECODEGEN=ON -DENABLE_LLVM_SHARED=OFF -DENABLE_MAN=OFF -DENABLE_RTTI=OFF -DINSTALL_CPP_EXAMPLES=OFF -DENABLE_CLANG_JIT=OFF ../src
-- The C compiler identification is GNU 10.2.1
...
-- Build files have been written to: /root/src/bcc/tmp
root@4ec15b1c6d03:~/src/bcc/tmp# make -j`nproc --all`
Scanning dependencies of target bpf-static
Scanning dependencies of target bpf-shared
[  2%] Building C object src/cc/CMakeFiles/bpf-static.dir/libbpf.c.o
...
[100%] Built target bps
root@4ec15b1c6d03:~/src/bcc/tmp#
  • Loading branch information
juchem committed Dec 29, 2020
1 parent 297512a commit c06208f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ if (CMAKE_USE_LIBBPF_PACKAGE)
find_package(LibBpf)
endif()

if(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
find_package(BISON)
find_package(FLEX)
if(NOT PYTHON_ONLY)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION}")
find_package(LibElf REQUIRED)

if(ENABLE_CLANG_JIT)
find_package(BISON)
find_package(FLEX)
find_package(LibElf REQUIRED)
if(CLANG_DIR)
set(CMAKE_FIND_ROOT_PATH "${CLANG_DIR}")
include_directories("${CLANG_DIR}/include")
Expand Down Expand Up @@ -82,6 +83,7 @@ endif()
FOREACH(DIR ${LLVM_INCLUDE_DIRS})
include_directories("${DIR}/../tools/clang/include")
ENDFOREACH()
endif(ENABLE_CLANG_JIT)

# Set to a string path if system places kernel lib directory in
# non-default location.
Expand Down Expand Up @@ -109,7 +111,7 @@ endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 14)

endif(NOT PYTHON_ONLY AND ENABLE_CLANG_JIT)
endif(NOT PYTHON_ONLY)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${CXX_ISYSTEM_DIRS}")
Expand Down

0 comments on commit c06208f

Please sign in to comment.