Skip to content

Commit

Permalink
Enable user-configuration of LLVM static/shared linking
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanEngelen committed Jul 12, 2024
1 parent 800b775 commit 4644f3b
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions cmake/Modules/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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}")
Expand Down

0 comments on commit 4644f3b

Please sign in to comment.