Initial support for the CMake build system.
[oota-llvm.git] / cmake / modules / LLVMConfig.cmake
1 macro(llvm_config executable link_components)
2   if( MSVC )
3     msvc_llvm_config(${executable} ${link_components})
4   else( MSVC )
5     nix_llvm_config(${executable} ${link_components})
6   endif( MSVC )
7 endmacro(llvm_config executable link_components)
8
9
10 macro(msvc_llvm_config executable link_components)
11   foreach(c ${link_components})
12     message(STATUS ${c})
13     if( c STREQUAL "jit" )
14       message(STATUS "linking jit")
15       set_target_properties(${executable}
16         PROPERTIES
17         LINK_FLAGS "/INCLUDE:_X86TargetMachineModule")
18     endif( c STREQUAL "jit" )
19   endforeach(c)
20   target_link_libraries(${executable} ${llvm_libs})
21 endmacro(msvc_llvm_config executable link_components)
22
23
24 macro(nix_llvm_config executable link_components)
25   set(lc "")
26   foreach(c ${LLVM_LINK_COMPONENTS})
27     set(lc "${lc} ${c}")
28   endforeach(c)
29   if( NOT HAVE_LLVM_CONFIG )
30     target_link_libraries(${executable}
31       "`${LLVM_TOOLS_BINARY_DIR}/llvm-config --libs ${lc}`")
32   else( NOT HAVE_LLVM_CONFIG )
33     # tbi: Error handling.
34     if( NOT PERL_FOUND )
35       message(FATAL_ERROR "Perl required but not found!")
36     endif( NOT PERL_FOUND )
37     execute_process(
38       COMMAND sh -c "${PERL_EXECUTABLE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/llvm-config --libs ${lc}"
39       RESULT_VARIABLE rv
40       OUTPUT_VARIABLE libs
41       OUTPUT_STRIP_TRAILING_WHITESPACE)
42     if(NOT rv EQUAL 0)
43       message(FATAL_ERROR "llvm-config failed for executable ${executable}")
44     endif(NOT rv EQUAL 0)
45     string(REPLACE " " ";" libs ${libs})
46     foreach(c ${libs})
47       if(c MATCHES ".*\\.o")
48         get_filename_component(fn ${c} NAME)
49         target_link_libraries(${executable}
50           ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${fn})
51       else(c MATCHES ".*\\.o")
52         string(REPLACE "-l" "" fn ${c})
53         target_link_libraries(${executable} ${fn})
54       endif(c MATCHES ".*\\.o")
55     endforeach(c)
56   endif( NOT HAVE_LLVM_CONFIG )
57 endmacro(nix_llvm_config executable link_components)