CMake: defines and uses macro add_llvm_definitions for keeping track
[opencl/llvm.git] / cmake / modules / AddPartiallyLinkedObject.cmake
1 include(LLVMProcessSources)
3 macro(target_name_of_partially_linked_object lib var)
4   if( MSVC )
5     set(${var} ${lib})
6   else( MSVC )
7     set(${var} ${lib}_pll)
8   endif( MSVC )
9 endmacro(target_name_of_partially_linked_object lib var)
12 macro(add_partially_linked_object lib)
13   if( MSVC )
14     add_llvm_library( ${lib} ${ARGN})
15   else( MSVC )
16     set(pll ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${lib}.o)
17     set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/temp_lib)
18     set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/temp_lib)
19     llvm_process_sources( ALL_FILES ${ARGN} )
20     if( BUILD_SHARED_LIBS AND SUPPORTS_FPIC_FLAG )
21       add_definitions(-fPIC)
22     endif()
23     add_library( ${lib} STATIC ${ALL_FILES})
24     if( LLVM_COMMON_DEPENDS )
25       add_dependencies( ${lib} ${LLVM_COMMON_DEPENDS} )
26     endif( LLVM_COMMON_DEPENDS )
27     add_custom_command(OUTPUT ${pll}
28       COMMENT "Building ${lib}.o..."
29       DEPENDS ${lib}
30       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/temp_lib/${CMAKE_CFG_INTDIR}
31       COMMAND ar x ${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${CMAKE_STATIC_LIBRARY_SUFFIX}
32       COMMAND ${CMAKE_LINKER} "${LLVM_PLO_FLAGS}" -r "*${CMAKE_CXX_OUTPUT_EXTENSION}" -o ${pll}
33       COMMAND ${CMAKE_COMMAND} -E remove -f *${CMAKE_CXX_OUTPUT_EXTENSION}
34       )
35     target_name_of_partially_linked_object(${lib} tnplo)
36     add_custom_target(${tnplo} ALL DEPENDS ${pll})
37     set( llvm_libs ${llvm_libs} ${pll} PARENT_SCOPE)
38     set( llvm_lib_targets ${llvm_lib_targets} ${tnplo} PARENT_SCOPE )
39   endif( MSVC )
40   install(FILES ${pll}
41     DESTINATION lib)
42 endmacro(add_partially_linked_object lib)