CMake: add LLVM_STATIC as cmake build option, so linux distributions can link
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 15 Apr 2013 16:18:35 +0000 (16:18 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 15 Apr 2013 16:18:35 +0000 (16:18 +0000)
LLVM dynamically. Patch by Dan Eicher.

CMakeLists.txt

index 80008e24d95751f25d964acbc157588b5e632c4d..ea22951f674e00a3db50186b0cac50fd579f8df9 100644 (file)
@@ -270,6 +270,8 @@ unset(PLATFORM_DEFAULT)
 
 # LLVM
 option(WITH_LLVM                                       "Use LLVM" OFF)
+option(LLVM_STATIC                                     "Link with LLVM static libraries" ON)
+mark_as_advanced(LLVM_STATIC)
 
 # disable for now, but plan to support on all platforms eventually
 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
@@ -755,7 +757,7 @@ if(UNIX AND NOT APPLE)
                if(NOT LLVM_VERSION)
                        set(LLVM_VERSION "3.0")
                endif()
-               set(LLVM_STATIC YES)
+
                if(LLVM_DIRECTORY)
                        FIND_PROGRAM(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
                        if(NOT LLVM_CONFIG)
@@ -776,9 +778,17 @@ if(UNIX AND NOT APPLE)
                execute_process(COMMAND ${LLVM_CONFIG} --libdir
                                OUTPUT_VARIABLE LLVM_LIB_DIR
                                OUTPUT_STRIP_TRAILING_WHITESPACE)
-               find_library(LLVM_LIBRARY
-                            NAMES LLVMAnalysis # first of a whole bunch of libs to get
-                            PATHS ${LLVM_LIB_DIR})
+
+               if(LLVM_STATIC)
+                       find_library(LLVM_LIBRARY
+                                    NAMES LLVMAnalysis # first of a whole bunch of libs to get
+                                    PATHS ${LLVM_LIB_DIR})
+               else()
+                       find_library(LLVM_LIBRARY
+                                    NAMES LLVM-${LLVM_VERSION}
+                                    PATHS ${LLVM_LIB_DIR})
+               endif()
+
                message(STATUS "LLVM version  = ${LLVM_VERSION}")
                message(STATUS "LLVM dir      = ${LLVM_DIRECTORY}")
                message(STATUS "LLVM lib dir  = ${LLVM_LIB_DIR}")
@@ -1205,7 +1215,6 @@ elseif(WIN32)
                if(WITH_LLVM)
                        set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
                        file(GLOB LLVM_LIBRARY ${LLVM_DIRECTORY}/lib/*.lib)
-                       set(LLVM_STATIC YES)
                endif()
        
                if(WITH_OPENCOLORIO)
@@ -1414,7 +1423,6 @@ elseif(WIN32)
                                LLVMipo LLVMCore)
                        #imagehelp is needed by LLVM 3.1 on MinGW, check lib\Support\Windows\Signals.inc
                        set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -limagehlp")
-                       set(LLVM_STATIC YES)
                endif()
                
                if(WITH_OPENCOLORIO)
@@ -1674,7 +1682,6 @@ elseif(APPLE)
        if(WITH_LLVM)
                set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
                set(LLVM_VERSION "3.1" CACHE STRING     "Version of LLVM to use")
-               set(LLVM_STATIC YES)
                if(EXISTS "${LLVM_DIRECTORY}/bin/llvm-config")
                        set(LLVM_CONFIG "${LLVM_DIRECTORY}/bin/llvm-config")
                else()