From b09e2a49f50d0834546b39890e08252dbbf47d18 Mon Sep 17 00:00:00 2001 From: Stephane Letz Date: Mon, 23 Sep 2024 22:35:41 +0200 Subject: [PATCH] Add a cmake LINK_LLVM_STATIC option. --- build/CMakeLists.txt | 2 ++ build/misc/llvm.cmake | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 4603bed555..d4606e9b76 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -39,6 +39,7 @@ option ( INCLUDE_EMCC "Include emcc targets" on ) option ( INCLUDE_WASM_GLUE "Include wasm glue targets" on ) option ( MSVC_STATIC "Use static runtimes with MSVC" off) option ( SELF_CONTAINED_LIBRARY "Don't search system architecture files." off) +option ( LINK_LLVM_STATIC "Link LLVM statically" off ) ####################################### # Check output options @@ -117,6 +118,7 @@ if (INCLUDE_LLVM ) message(STATUS "LLVM_LIB_DIR: ${LLVM_LIB_DIR}") message(STATUS "LLVM_INCLUDE_DIRS: ${LLVM_INCLUDE_DIRS}") message(STATUS "LLVM_DEFINITIONS: ${LLVM_DEFINITIONS}") + message(STATUS "LINK_LLVM_STATIC: ${LINK_LLVM_STATIC}") # the declarations below are redundant but necessary to cope with different cmake behaviors on different platforms set (TMP ${SRCDIR}/generator/llvm) diff --git a/build/misc/llvm.cmake b/build/misc/llvm.cmake index 62865707f2..748204a5d9 100644 --- a/build/misc/llvm.cmake +++ b/build/misc/llvm.cmake @@ -110,11 +110,20 @@ macro (llvm_config) string ( STRIP ${LLVM_INCLUDE} LLVM_INCLUDE_DIRS ) execute_process (COMMAND ${LLVM_CONFIG} --ldflags OUTPUT_VARIABLE LLVM_LDFLAGS_TMP) string ( STRIP ${LLVM_LDFLAGS_TMP} LLVM_LD_FLAGS ) - execute_process (COMMAND ${LLVM_CONFIG} --libs --link-static OUTPUT_VARIABLE LLVM_LIBS_TMP) + + # Check the option to decide whether to link statically or dynamically + if (LINK_LLVM_STATIC) + execute_process(COMMAND ${LLVM_CONFIG} --link-static --libs OUTPUT_VARIABLE LLVM_LIBS_TMP) + execute_process(COMMAND ${LLVM_CONFIG} --link-static --system-libs OUTPUT_VARIABLE LLVM_SYS_LIBS_TMP) + else() + execute_process(COMMAND ${LLVM_CONFIG} --link-shared --libs OUTPUT_VARIABLE LLVM_LIBS_TMP) + execute_process(COMMAND ${LLVM_CONFIG} --link-shared --system-libs OUTPUT_VARIABLE LLVM_SYS_LIBS_TMP) + endif() + string ( STRIP ${LLVM_LIBS_TMP} LLVM_LIBS_TMP2 ) string ( REPLACE "C:\\Program Files\\LLVM\\lib\\" "" LLVM_LIBS ${LLVM_LIBS_TMP2}) - execute_process (COMMAND ${LLVM_CONFIG} --link-static --system-libs OUTPUT_VARIABLE LLVM_SYS_LIBS_TMP) string ( STRIP ${LLVM_SYS_LIBS_TMP} LLVM_SYS_LIBS) + # on ubuntu, expecting to find "-lz -lpthread -ledit -lcurses -lm" # on macos, expecting to find "-lm -lcurses -lxml2"