From 4644f3b0f650746a8068c6ffedbf7475770b81f7 Mon Sep 17 00:00:00 2001 From: Johan Engelen Date: Wed, 8 May 2024 17:20:41 +0200 Subject: [PATCH] Enable user-configuration of LLVM static/shared linking --- cmake/Modules/FindLLVM.cmake | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/cmake/Modules/FindLLVM.cmake b/cmake/Modules/FindLLVM.cmake index 9dfc883a31c..dc406424ab3 100644 --- a/cmake/Modules/FindLLVM.cmake +++ b/cmake/Modules/FindLLVM.cmake @@ -77,9 +77,14 @@ else() if(LLVM_FIND_QUIETLY) set(_quiet_arg ERROR_QUIET) endif() + if (LLVM_IS_SHARED) + set(sharedstatic "--link-shared") + else() + set(sharedstatic "--link-static") + endif() set(result_code) execute_process( - COMMAND ${LLVM_CONFIG} --${flag} + COMMAND ${LLVM_CONFIG} ${sharedstatic} --${flag} RESULT_VARIABLE result_code OUTPUT_VARIABLE LLVM_${var} OUTPUT_STRIP_TRAILING_WHITESPACE @@ -97,9 +102,14 @@ else() if(LLVM_FIND_QUIETLY) set(_quiet_arg ERROR_QUIET) endif() + if (LLVM_IS_SHARED) + set(sharedstatic "--link-shared") + else() + set(sharedstatic "--link-static") + endif() set(result_code) execute_process( - COMMAND ${LLVM_CONFIG} --${flag} ${components} + COMMAND ${LLVM_CONFIG} ${sharedstatic} --${flag} ${components} RESULT_VARIABLE result_code OUTPUT_VARIABLE tmplibs OUTPUT_STRIP_TRAILING_WHITESPACE @@ -113,6 +123,15 @@ else() endif() endmacro() + if (NOT DEFINED LLVM_IS_SHARED) + llvm_set(SHARED_MODE shared-mode) + if(LLVM_SHARED_MODE STREQUAL "shared") + set(LLVM_IS_SHARED ON) + else() + set(LLVM_IS_SHARED OFF) + endif() + endif() + llvm_set(VERSION_STRING version) llvm_set(CXXFLAGS cxxflags) llvm_set(INCLUDE_DIRS includedir true) @@ -124,13 +143,6 @@ else() string(REGEX REPLACE "([0-9]+).*" "\\1" LLVM_VERSION_MAJOR "${LLVM_VERSION_STRING}" ) string(REGEX REPLACE "[0-9]+\\.([0-9]+).*[A-Za-z]*" "\\1" LLVM_VERSION_MINOR "${LLVM_VERSION_STRING}" ) - llvm_set(SHARED_MODE shared-mode) - if(LLVM_SHARED_MODE STREQUAL "shared") - set(LLVM_IS_SHARED ON) - else() - set(LLVM_IS_SHARED OFF) - endif() - llvm_set(LDFLAGS ldflags) llvm_set(SYSTEM_LIBS system-libs) string(REPLACE "\n" " " LLVM_LDFLAGS "${LLVM_LDFLAGS} ${LLVM_SYSTEM_LIBS}")