Update requires in xmake.lua of README.md.
[liba.git] / cmake / TargetSupportsRelocatable.cmake
blobf5812bfa06f3ee06b188d3a280c74ed1c3b1ab2f
1 function(TARGET_SUPPORTS_RELOCATABLE)
2   string(RANDOM RANDOM)
3   set(CMAKETMP ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${RANDOM})
4   get_cmake_property(ENABLED_LANGUAGES ENABLED_LANGUAGES)
5   foreach(LANG C ${ENABLED_LANGUAGES})
6     if(CMAKE_${LANG}_COMPILER)
7       set(CMAKE_COMPILER ${CMAKE_${LANG}_COMPILER})
8       break()
9     endif()
10   endforeach()
11   if(NOT CMAKE_COMPILER)
12     return()
13   endif()
14   file(WRITE ${CMAKETMP}/${RANDOM}.c "")
15   execute_process(COMMAND ${CMAKE_COMPILER} -nostdlib -o ${RANDOM}.o -r ${RANDOM}.c
16     WORKING_DIRECTORY ${CMAKETMP} ERROR_QUIET OUTPUT_QUIET RESULT_VARIABLE result
17   )
18   if(${result} EQUAL 0)
19     set(TARGET_SUPPORTS_RELOCATABLE 1 CACHE INTERNAL "Test TARGET_SUPPORTS_RELOCATABLE")
20   else()
21     set(TARGET_SUPPORTS_RELOCATABLE 0 CACHE INTERNAL "Test TARGET_SUPPORTS_RELOCATABLE")
22   endif()
23   file(REMOVE_RECURSE ${CMAKETMP})
24 endfunction()
25 if(NOT DEFINED TARGET_SUPPORTS_RELOCATABLE)
26   TARGET_SUPPORTS_RELOCATABLE()
27 endif()