]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/blobdiff - cmake/modules/LLVMConfig.cmake
CMake: defines and uses macro add_llvm_definitions for keeping track
[opencl/llvm.git] / cmake / modules / LLVMConfig.cmake
index 3d5e3bc55a4659c2784d2df0378acf40514d0c00..63f9ded19fd6d255718ee0a5b27624b9fc40aa5d 100755 (executable)
@@ -1,28 +1,37 @@
-macro(llvm_config executable link_components)
+include(FindPerl)
+
+macro(llvm_config executable)
+  # extra args is the list of link components.
   if( MSVC )
-    msvc_llvm_config(${executable} ${link_components})
+    msvc_llvm_config(${executable} ${ARGN})
   else( MSVC )
-    nix_llvm_config(${executable} ${link_components})
+    nix_llvm_config(${executable} ${ARGN})
   endif( MSVC )
-endmacro(llvm_config executable link_components)
+endmacro(llvm_config)
 
 
-function(msvc_llvm_config executable link_components)
+function(msvc_llvm_config executable)
+  set( link_components ${ARGN} )
+  if( CMAKE_CL_64 )
+    set(include_lflag "/INCLUDE:")
+  else( CMAKE_CL_64 )
+    set(include_lflag "/INCLUDE:_")
+  endif()
   foreach(c ${link_components})
     if( c STREQUAL "jit" )
-      set(lfgs "${lfgs} /INCLUDE:_X86TargetMachineModule")
+      set(lfgs "${lfgs} ${include_lflag}X86TargetMachineModule")
     endif( c STREQUAL "jit" )
     list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
     if( NOT idx LESS 0 )
-      set(lfgs "${lfgs} /INCLUDE:_${c}TargetMachineModule")
+      set(lfgs "${lfgs} ${include_lflag}${c}TargetMachineModule")
       list(FIND LLVM_ASMPRINTERS_FORCE_LINK ${c} idx)
       if( NOT idx LESS 0 )
-       set(lfgs "${lfgs} /INCLUDE:_${c}AsmPrinterForceLink")
+       set(lfgs "${lfgs} ${include_lflag}${c}AsmPrinterForceLink")
       endif()
     endif()
   endforeach(c)
 
-  msvc_map_components_to_libraries(${link_components} LIBRARIES)
+  msvc_map_components_to_libraries(LIBRARIES ${link_components})
   target_link_libraries(${executable} ${LIBRARIES})
 
   if( lfgs )
@@ -30,15 +39,26 @@ function(msvc_llvm_config executable link_components)
       PROPERTIES
       LINK_FLAGS ${lfgs})
   endif()
-endfunction(msvc_llvm_config executable link_components)
+endfunction(msvc_llvm_config)
 
 
-function(msvc_map_components_to_libraries link_components out_libs)
+function(msvc_map_components_to_libraries out_libs)
+  set( link_components ${ARGN} )
   foreach(c ${link_components})
     # add codegen/asmprinter
     list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
     if( NOT idx LESS 0 )
-      list(APPEND expanded_components "LLVM${c}CodeGen")
+      list(FIND llvm_libs "LLVM${c}CodeGen" idx)
+      if( NOT idx LESS 0 )
+       list(APPEND expanded_components "LLVM${c}CodeGen")
+      else()
+       list(FIND llvm_libs "LLVM${c}" idx)
+       if( NOT idx LESS 0 )
+         list(APPEND expanded_components "LLVM${c}")
+       else()
+         message(FATAL_ERROR "Target ${c} is not in the set of libraries.")
+       endif()
+      endif()
       list(FIND llvm_libs "LLVM${c}AsmPrinter" asmidx)
       if( NOT asmidx LESS 0 )
         list(APPEND expanded_components "LLVM${c}AsmPrinter")
@@ -62,6 +82,7 @@ function(msvc_map_components_to_libraries link_components out_libs)
   endforeach(c)
   # We must match capitalization.
   string(TOUPPER "${llvm_libs}" capitalized_libs)
+  list(REMOVE_DUPLICATES expanded_components)
   set(curr_idx 0)
   list(LENGTH expanded_components lst_size)
   while( ${curr_idx} LESS ${lst_size} )
@@ -75,6 +96,7 @@ function(msvc_map_components_to_libraries link_components out_libs)
     list(APPEND result ${canonical_lib})
     list(APPEND result ${MSVC_LIB_DEPS_${canonical_lib}})
     list(APPEND expanded_components ${MSVC_LIB_DEPS_${canonical_lib}})
+    list(REMOVE_DUPLICATES expanded_components)
     list(LENGTH expanded_components lst_size)
     math(EXPR curr_idx "${curr_idx} + 1")
   endwhile( ${curr_idx} LESS ${lst_size} )
@@ -83,9 +105,9 @@ function(msvc_map_components_to_libraries link_components out_libs)
 endfunction(msvc_map_components_to_libraries)
 
 
-macro(nix_llvm_config executable link_components)
+macro(nix_llvm_config executable)
   set(lc "")
-  foreach(c ${LLVM_LINK_COMPONENTS})
+  foreach(c ${ARGN})
     set(lc "${lc} ${c}")
   endforeach(c)
   if( NOT HAVE_LLVM_CONFIG )
@@ -93,9 +115,9 @@ macro(nix_llvm_config executable link_components)
       "`${LLVM_TOOLS_BINARY_DIR}/llvm-config --libs ${lc}`")
   else( NOT HAVE_LLVM_CONFIG )
     # tbi: Error handling.
-    if( NOT PERL_FOUND )
+    if( NOT PERL_EXECUTABLE )
       message(FATAL_ERROR "Perl required but not found!")
-    endif( NOT PERL_FOUND )
+    endif( NOT PERL_EXECUTABLE )
     execute_process(
       COMMAND sh -c "${PERL_EXECUTABLE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/llvm-config --libs ${lc}"
       RESULT_VARIABLE rv
@@ -109,14 +131,14 @@ macro(nix_llvm_config executable link_components)
       if(c MATCHES ".*\\.o")
        get_filename_component(fn ${c} NAME)
        target_link_libraries(${executable}
-         ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${fn})
+         ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${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)
+endmacro(nix_llvm_config)
 
 
 # This data is used on MSVC for stablishing executable/library