summaryrefslogtreecommitdiff
path: root/cmake/modules/LLVMConfig.cmake
blob: f87d16cd1fb9daedb690aaa73560e7b92683127d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
macro(llvm_config executable link_components)
  if( MSVC )
    msvc_llvm_config(${executable} ${link_components})
  else( MSVC )
    nix_llvm_config(${executable} ${link_components})
  endif( MSVC )
endmacro(llvm_config executable link_components)


macro(msvc_llvm_config executable link_components)
  foreach(c ${link_components})
    message(STATUS ${c})
    if( c STREQUAL "jit" )
      message(STATUS "linking jit")
      set_target_properties(${executable}
	PROPERTIES
	LINK_FLAGS "/INCLUDE:_X86TargetMachineModule")
    endif( c STREQUAL "jit" )
  endforeach(c)
  target_link_libraries(${executable} ${llvm_libs})
endmacro(msvc_llvm_config executable link_components)


macro(nix_llvm_config executable link_components)
  set(lc "")
  foreach(c ${LLVM_LINK_COMPONENTS})
    set(lc "${lc} ${c}")
  endforeach(c)
  if( NOT HAVE_LLVM_CONFIG )
    target_link_libraries(${executable}
      "`${LLVM_TOOLS_BINARY_DIR}/llvm-config --libs ${lc}`")
  else( NOT HAVE_LLVM_CONFIG )
    # tbi: Error handling.
    if( NOT PERL_FOUND )
      message(FATAL_ERROR "Perl required but not found!")
    endif( NOT PERL_FOUND )
    execute_process(
      COMMAND sh -c "${PERL_EXECUTABLE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/llvm-config --libs ${lc}"
      RESULT_VARIABLE rv
      OUTPUT_VARIABLE libs
      OUTPUT_STRIP_TRAILING_WHITESPACE)
    if(NOT rv EQUAL 0)
      message(FATAL_ERROR "llvm-config failed for executable ${executable}")
    endif(NOT rv EQUAL 0)
    string(REPLACE " " ";" libs ${libs})
    foreach(c ${libs})
      if(c MATCHES ".*\\.o")
	get_filename_component(fn ${c} NAME)
	target_link_libraries(${executable}
	  ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${fn})
      else(c MATCHES ".*\\.o")
	string(REPLACE "-l" "" fn ${c})
	target_link_libraries(${executable} ${fn})
      endif(c MATCHES ".*\\.o")
    endforeach(c)
  endif( NOT HAVE_LLVM_CONFIG )
endmacro(nix_llvm_config executable link_components)