mirror of
https://github.com/monero-project/monero.git
synced 2024-12-23 20:19:34 +00:00
cmake: comply with the new policy CMP0026
Access to LOCATION property at config time was disallowed by this policy. This patch updates the offending code to comply with the policy and thereby gets rid of the warning printed by cmake. The fix is to use generator expressions instead of that property. NOTE: Had to remove support for multiconfig (only affects MSVC which is not supported anyway; and mutliconf is an IDE thing in any case), because could not see how to support it with generator expressions.
This commit is contained in:
parent
51f0ac09c6
commit
a7498adc03
1 changed files with 47 additions and 102 deletions
|
@ -16,114 +16,59 @@
|
||||||
function(merge_static_libs outlib )
|
function(merge_static_libs outlib )
|
||||||
set(libs ${ARGV})
|
set(libs ${ARGV})
|
||||||
list(REMOVE_AT libs 0)
|
list(REMOVE_AT libs 0)
|
||||||
# Create a dummy file that the target will depend on
|
list(REMOVE_DUPLICATES libs) # just in case
|
||||||
set(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/${outlib}_dummy.c)
|
|
||||||
file(WRITE ${dummyfile} "const char * dummy = \"${dummyfile}\";")
|
|
||||||
|
|
||||||
add_library(${outlib} STATIC ${dummyfile})
|
# First get the file names of the libraries to be merged
|
||||||
|
|
||||||
if("${CMAKE_CFG_INTDIR}" STREQUAL ".")
|
|
||||||
set(multiconfig FALSE)
|
|
||||||
else()
|
|
||||||
set(multiconfig TRUE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# First get the file names of the libraries to be merged
|
|
||||||
foreach(lib ${libs})
|
foreach(lib ${libs})
|
||||||
get_target_property(libtype ${lib} TYPE)
|
get_target_property(libtype ${lib} TYPE)
|
||||||
if(NOT libtype STREQUAL "STATIC_LIBRARY")
|
if(NOT libtype STREQUAL "STATIC_LIBRARY")
|
||||||
message(FATAL_ERROR "Merge_static_libs can only process static libraries")
|
message(FATAL_ERROR "merge_static_libs can only process static libraries")
|
||||||
endif()
|
endif()
|
||||||
if(multiconfig)
|
set(libfiles "${libfiles} $<TARGET_FILE:${lib}>")
|
||||||
foreach(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES})
|
|
||||||
get_target_property("libfile_${CONFIG_TYPE}" ${lib} "LOCATION_${CONFIG_TYPE}")
|
|
||||||
list(APPEND libfiles_${CONFIG_TYPE} ${libfile_${CONFIG_TYPE}})
|
|
||||||
endforeach()
|
|
||||||
else()
|
|
||||||
get_target_property(libfile ${lib} LOCATION)
|
|
||||||
list(APPEND libfiles "${libfile}")
|
|
||||||
endif(multiconfig)
|
|
||||||
endforeach()
|
|
||||||
message(STATUS "will be merging ${libfiles}")
|
|
||||||
# Just to be sure: cleanup from duplicates
|
|
||||||
if(multiconfig)
|
|
||||||
foreach(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES})
|
|
||||||
list(REMOVE_DUPLICATES libfiles_${CONFIG_TYPE})
|
|
||||||
set(libfiles ${libfiles} ${libfiles_${CONFIG_TYPE}})
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
list(REMOVE_DUPLICATES libfiles)
|
|
||||||
|
|
||||||
# Now the easy part for MSVC and for MAC
|
|
||||||
if(MSVC)
|
|
||||||
# lib.exe does the merging of libraries just need to conver the list into string
|
|
||||||
foreach(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES})
|
|
||||||
set(flags "")
|
|
||||||
foreach(lib ${libfiles_${CONFIG_TYPE}})
|
|
||||||
set(flags "${flags} ${lib}")
|
|
||||||
endforeach()
|
|
||||||
string(TOUPPER "STATIC_LIBRARY_FLAGS_${CONFIG_TYPE}" PROPNAME)
|
|
||||||
set_target_properties(${outlib} PROPERTIES ${PROPNAME} "${flags}")
|
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
elseif(APPLE)
|
if(MSVC) # lib.exe does the merging of given a list
|
||||||
# Use OSX's libtool to merge archives
|
set_target_properties(${outlib} PROPERTIES STATIC_LIBRARY_FLAGS "${libfiles}")
|
||||||
if(multiconfig)
|
|
||||||
message(FATAL_ERROR "Multiple configurations are not supported")
|
elseif(APPLE) # Use OSX's libtool to merge archives
|
||||||
endif()
|
|
||||||
get_target_property(outfile ${outlib} LOCATION)
|
|
||||||
add_custom_command(TARGET ${outlib} POST_BUILD
|
add_custom_command(TARGET ${outlib} POST_BUILD
|
||||||
COMMAND rm ${outfile}
|
COMMAND rm "$<TARGET_FILE:${outlib}>"
|
||||||
COMMAND /usr/bin/libtool -static -o ${outfile}
|
COMMAND /usr/bin/libtool -static -o "$<TARGET_FILE:${outlib}>" ${libfiles})
|
||||||
${libfiles}
|
|
||||||
)
|
else() # general UNIX: use "ar" to extract objects and re-add to a common lib
|
||||||
else()
|
foreach(lib ${libs})
|
||||||
# general UNIX - need to "ar -x" and then "ar -ru"
|
set(objlistfile ${lib}.objlist) # list of objects in the input library
|
||||||
if(multiconfig)
|
|
||||||
message(FATAL_ERROR "Multiple configurations are not supported")
|
|
||||||
endif()
|
|
||||||
get_target_property(outfile ${outlib} LOCATION)
|
|
||||||
message(STATUS "outfile location is ${outfile}")
|
|
||||||
foreach(lib ${libfiles})
|
|
||||||
# objlistfile will contain the list of object files for the library
|
|
||||||
set(objlistfile ${lib}.objlist)
|
|
||||||
set(objdir ${lib}.objdir)
|
set(objdir ${lib}.objdir)
|
||||||
set(objlistcmake ${objlistfile}.cmake)
|
|
||||||
# we only need to extract files once
|
add_custom_command(OUTPUT ${objdir}
|
||||||
if(${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/cmake.check_cache IS_NEWER_THAN ${objlistcmake})
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${objdir})
|
||||||
#---------------------------------
|
|
||||||
FILE(WRITE ${objlistcmake}
|
add_custom_command(OUTPUT ${objlistfile}
|
||||||
"# Extract object files from the library
|
COMMAND ${CMAKE_AR} -x "$<TARGET_FILE:${lib}>"
|
||||||
message(STATUS \"Extracting object files from ${lib}\")
|
COMMAND ${CMAKE_AR} -t "$<TARGET_FILE:${lib}>" > ../${objlistfile}
|
||||||
EXECUTE_PROCESS(COMMAND ${CMAKE_AR} -x ${lib}
|
DEPENDS ${lib} ${objdir}
|
||||||
WORKING_DIRECTORY ${objdir})
|
WORKING_DIRECTORY ${objdir})
|
||||||
# save the list of object files
|
|
||||||
EXECUTE_PROCESS(COMMAND ls .
|
# Empty dummy source file that goes into merged library
|
||||||
OUTPUT_FILE ${objlistfile}
|
set(mergebase ${lib}.mergebase.c)
|
||||||
WORKING_DIRECTORY ${objdir})")
|
add_custom_command(OUTPUT ${mergebase}
|
||||||
#---------------------------------
|
COMMAND ${CMAKE_COMMAND} -E touch ${mergebase}
|
||||||
file(MAKE_DIRECTORY ${objdir})
|
DEPENDS ${objlistfile})
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${objlistfile}
|
list(APPEND mergebases "${mergebase}")
|
||||||
COMMAND ${CMAKE_COMMAND} -P ${objlistcmake}
|
endforeach()
|
||||||
DEPENDS ${lib})
|
|
||||||
endif()
|
# We need a target for the output merged library
|
||||||
list(APPEND extrafiles "${objlistfile}")
|
add_library(${outlib} STATIC ${mergebases})
|
||||||
# relative path is needed by ar under MSYS
|
set(outlibfile "$<TARGET_FILE:${outlib}>")
|
||||||
file(RELATIVE_PATH objlistfilerpath ${objdir} ${objlistfile})
|
|
||||||
|
foreach(lib ${libs})
|
||||||
add_custom_command(TARGET ${outlib} POST_BUILD
|
add_custom_command(TARGET ${outlib} POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "Running: ${CMAKE_AR} ru ${outfile} @${objlistfilerpath}"
|
COMMAND ${CMAKE_AR} ru ${outlibfile} @"../${objlistfile}"
|
||||||
COMMAND ${CMAKE_AR} ru "${outfile}" @"${objlistfilerpath}"
|
|
||||||
WORKING_DIRECTORY ${objdir})
|
WORKING_DIRECTORY ${objdir})
|
||||||
endforeach()
|
endforeach()
|
||||||
add_custom_command(TARGET ${outlib} POST_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo "Running: ${CMAKE_RANLIB} ${outfile}"
|
|
||||||
COMMAND ${CMAKE_RANLIB} ${outfile})
|
|
||||||
endif()
|
|
||||||
file(WRITE ${dummyfile}.base "const char* ${outlib}_sublibs=\"${libs}\";")
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${dummyfile}
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy ${dummyfile}.base ${dummyfile}
|
|
||||||
DEPENDS ${libs} ${extrafiles})
|
|
||||||
|
|
||||||
endfunction()
|
add_custom_command(TARGET ${outlib} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_RANLIB} ${outlibfile})
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
Loading…
Reference in a new issue