mirror of
https://github.com/gperftools/gperftools
synced 2025-01-02 20:52:03 +00:00
35 lines
1.3 KiB
CMake
35 lines
1.3 KiB
CMake
|
function(find_objcopy_with_weaken result objcopy_path)
|
||
|
find_program(objcopy_exe "objcopy" PATHS ${objcopy_path})
|
||
|
if(objcopy_exe)
|
||
|
set(objcopy_found "found")
|
||
|
else()
|
||
|
set(objcopy_found "not found")
|
||
|
endif()
|
||
|
message(STATUS "Looking for objcopy that supports weaken - ${objcopy_found}")
|
||
|
if(objcopy_exe)
|
||
|
set(objcopy_test_src "${CMAKE_CURRENT_BINARY_DIR}/objcopy_test.c")
|
||
|
set(objcopy_test_exe "${CMAKE_CURRENT_BINARY_DIR}/objcopy_test")
|
||
|
file(WRITE ${objcopy_test_src} "void foo() {} int main() { return 0; }")
|
||
|
try_compile(objcopy_test_compiled
|
||
|
${CMAKE_CURRENT_BINARY_DIR} ${objcopy_test_src}
|
||
|
COPY_FILE ${objcopy_test_exe})
|
||
|
if(objcopy_test_compiled AND EXISTS ${objcopy_test_exe})
|
||
|
execute_process(
|
||
|
COMMAND ${objcopy_exe} -W foo ${objcopy_test_exe}
|
||
|
RESULT_VARIABLE objcopy_result)
|
||
|
file(REMOVE ${objcopy_test_exe})
|
||
|
endif()
|
||
|
if(objcopy_result EQUAL 0)
|
||
|
set(objcopy_weaken ON)
|
||
|
endif()
|
||
|
file(REMOVE ${objcopy_test_src})
|
||
|
if(objcopy_weaken)
|
||
|
set(objcopy_has_weaken "Success")
|
||
|
set(${result} objcopy_exe PARENT_SCOPE)
|
||
|
else()
|
||
|
set(objcopy_has_weaken "Failed")
|
||
|
endif()
|
||
|
message(STATUS "objcopy has weaken support - ${objcopy_has_weaken}")
|
||
|
endif()
|
||
|
endfunction(find_objcopy_with_weaken)
|