blob: e84e420d55498f7e3f4fdf134ab2871f90fd0a0d [file] [log] [blame]
Oscar Fuentes3d01fc72008-09-22 01:08:49 +00001macro(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 )
7endmacro(llvm_config executable link_components)
8
9
10macro(msvc_llvm_config executable link_components)
11 foreach(c ${link_components})
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000012 if( c STREQUAL "jit" )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000013 set_target_properties(${executable}
14 PROPERTIES
15 LINK_FLAGS "/INCLUDE:_X86TargetMachineModule")
16 endif( c STREQUAL "jit" )
17 endforeach(c)
18 target_link_libraries(${executable} ${llvm_libs})
19endmacro(msvc_llvm_config executable link_components)
20
21
22macro(nix_llvm_config executable link_components)
23 set(lc "")
24 foreach(c ${LLVM_LINK_COMPONENTS})
25 set(lc "${lc} ${c}")
26 endforeach(c)
27 if( NOT HAVE_LLVM_CONFIG )
28 target_link_libraries(${executable}
29 "`${LLVM_TOOLS_BINARY_DIR}/llvm-config --libs ${lc}`")
30 else( NOT HAVE_LLVM_CONFIG )
31 # tbi: Error handling.
32 if( NOT PERL_FOUND )
33 message(FATAL_ERROR "Perl required but not found!")
34 endif( NOT PERL_FOUND )
35 execute_process(
36 COMMAND sh -c "${PERL_EXECUTABLE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/llvm-config --libs ${lc}"
37 RESULT_VARIABLE rv
38 OUTPUT_VARIABLE libs
39 OUTPUT_STRIP_TRAILING_WHITESPACE)
40 if(NOT rv EQUAL 0)
41 message(FATAL_ERROR "llvm-config failed for executable ${executable}")
42 endif(NOT rv EQUAL 0)
43 string(REPLACE " " ";" libs ${libs})
44 foreach(c ${libs})
45 if(c MATCHES ".*\\.o")
46 get_filename_component(fn ${c} NAME)
47 target_link_libraries(${executable}
48 ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${fn})
49 else(c MATCHES ".*\\.o")
50 string(REPLACE "-l" "" fn ${c})
51 target_link_libraries(${executable} ${fn})
52 endif(c MATCHES ".*\\.o")
53 endforeach(c)
54 endif( NOT HAVE_LLVM_CONFIG )
55endmacro(nix_llvm_config executable link_components)