Skip to content

Commit

Permalink
Build static llvm tool binaries.
Browse files Browse the repository at this point in the history
Previously, the binaries built when ENABLE_TOOL=LLVM are all
dynamically linked, there are many .so dependencies that prevent the
tool binaries from be deployed to other systems.

The change is also required when building release binaries.
  • Loading branch information
shenhanc78 committed Jul 18, 2024
1 parent 5282585 commit 3dc3db9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(CMAKE_CXX_STANDARD 17)
set(ABSL_PROPAGATE_CXX_STD on)

project(autofdo)
set (Protobuf_USE_STATIC_LIBS TRUE)

function (execute_perf_protobuf)

Expand Down Expand Up @@ -150,6 +151,11 @@ function (build_llvm)
endif()
endif()

# Build static binaries.
set (BUILD_SHARED_LIBS OFF)
set (WITH_GFLAGS OFF)
set (WITH_UNWIND OFF)

### LLVM Configuration
set (LLVM_INCLUDE_UTILS OFF)
set (LLVM_INCLUDE_TESTS OFF)
Expand All @@ -162,6 +168,10 @@ function (build_llvm)
set (LLVM_TARGETS_TO_BUILD X86 AArch64 CACHE STRING
"Semicolon-separated list of LLVM targets to build, or \"all\".")
set (LLVM_ENABLE_ZSTD FORCE_ON)
set (LLVM_USE_STATIC_ZSTD TRUE CACHE BOOL "use static zstd" FORCE)
set (LLVM_ENABLE_ZLIB OFF CACHE BOOL "turn off zlib" FORCE)
# terminfo is not needed by create_llvm_prof
set (LLVM_ENABLE_TERMINFO OFF CACHE BOOL "disable terminfo" FORCE)
###

add_subdirectory(third_party/abseil)
Expand Down Expand Up @@ -361,8 +371,9 @@ function (build_llvm)
LLVMSupport)
add_test(NAME symbol_map_test COMMAND symbol_map_test)

find_library (LIBELF_LIBRARIES NAMES elf REQUIRED)
find_library (LIBCRYPTO_LIBRARIES NAMES crypto REQUIRED)
find_library (LIBELF_LIBRARIES NAMES libelf.a REQUIRED)
find_library (LIBZ_LIBRARIES NAMES libz.a REQUIRED)
find_library (LIBCRYPTO_LIBRARIES NAMES libcrypto.a REQUIRED)

add_executable(llvm_profile_reader_test llvm_profile_reader_test.cc)
target_link_libraries(llvm_profile_reader_test
Expand Down Expand Up @@ -779,7 +790,7 @@ function (build_llvm)
third_party/perf_data_converter/src/quipper
${PROJECT_BINARY_DIR}/third_party/perf_data_converter/src/quipper)
target_link_libraries(quipper_perf
perf_proto ${LIBELF_LIBRARIES} ${LIBCRYPTO_LIBRARIES})
perf_proto ${LIBELF_LIBRARIES} ${LIBZ_LIBRARIES} ${LIBCRYPTO_LIBRARIES})

add_custom_command(PRE_BUILD
OUTPUT prepare_cmds
Expand Down

0 comments on commit 3dc3db9

Please sign in to comment.