1
1
Fix the targets and output files handling to make the symbols to be
updated correctly when a symbol is added or removed.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
Anderson Toshiyuki Sasaki 2018-08-27 14:39:51 +02:00
родитель f0a4c1e888
Коммит f49bb1b6a3
2 изменённых файлов: 127 добавлений и 82 удалений

Просмотреть файл

@ -37,7 +37,7 @@
# #
# generate_map_file(target_name # generate_map_file(target_name
# RELEASE_NAME_VERSION release_name # RELEASE_NAME_VERSION release_name
# SYMBOLS symbols_file # SYMBOLS symbols_target
# [CURRENT_MAP cur_map] # [CURRENT_MAP cur_map]
# [FINAL] # [FINAL]
# [BREAK_ABI] # [BREAK_ABI]
@ -55,8 +55,9 @@
# added to the symbols in the format ``lib_name_1_2_3``. # added to the symbols in the format ``lib_name_1_2_3``.
# #
# ``SYMBOLS``: # ``SYMBOLS``:
# Required, expects a file containing the list of symbols to be added to the # Required, expects a target with the property ``LIST_FILE`` containing a path
# symbol version script. # to a file containing the list of symbols to be added to the symbol version
# script.
# #
# ``CURRENT_MAP``: # ``CURRENT_MAP``:
# Optional. If given, the new set of symbols will be checked against the # Optional. If given, the new set of symbols will be checked against the
@ -87,9 +88,14 @@
# find_package(ABIMap) # find_package(ABIMap)
# generate_map_file("lib.map" # generate_map_file("lib.map"
# RELEASE_NAME_VERSION "lib_1_0_0" # RELEASE_NAME_VERSION "lib_1_0_0"
# SYMBOLS "symbol1;symbol2" # SYMBOLS symbols
# ) # )
# #
# Where the target ``symbols`` has its property ``LIST_FILE`` set to the path to
# a file containing::
#
# ``symbol1;symbol2``
#
# This example would result in the symbol version script to be created in # This example would result in the symbol version script to be created in
# ``${CMAKE_CURRENT_BINARY_DIR}/lib.map`` containing the provided symbols. # ``${CMAKE_CURRENT_BINARY_DIR}/lib.map`` containing the provided symbols.
# #
@ -102,8 +108,8 @@
# ) # )
# #
# ``target_name``: # ``target_name``:
# Required, expects the name of the target to be created. A file named after # Required, expects the name of the target to be created. A file named as
# the string given in ``target_name`` will be created in # ``${target_name}.list`` will be created in
# ``${CMAKE_CURRENT_BINARY_DIR}`` to receive the list of files found. # ``${CMAKE_CURRENT_BINARY_DIR}`` to receive the list of files found.
# #
# ``DIRECTORIES``: # ``DIRECTORIES``:
@ -112,7 +118,7 @@
# #
# ``FILES_PATTERN``: # ``FILES_PATTERN``:
# Required, expects a list of matching expressions to find the files to be # Required, expects a list of matching expressions to find the files to be
# considered. # considered in the directories.
# #
# ``COPY_TO``: # ``COPY_TO``:
# Optional, expects a string containing the path to where the file containing # Optional, expects a string containing the path to where the file containing
@ -120,7 +126,9 @@
# #
# This command searches the directories provided in ``DIRECTORIES`` for files # This command searches the directories provided in ``DIRECTORIES`` for files
# matching any of the patterns provided in ``FILES_PATTERNS``. The obtained list # matching any of the patterns provided in ``FILES_PATTERNS``. The obtained list
# is written to the path specified by ``output``. # is written to the path specified by ``output``. A target named ``target_name``
# will be created and its property ``LIST_FILE`` will be set to contain
# ``${CMAKE_CURRENT_BINARY_DIR}/${target_name}.list``
# #
# Example: # Example:
# #
@ -140,10 +148,13 @@
# #
# ``h1.h;h2.h`` # ``h1.h;h2.h``
# #
# And the target ``target`` will have its property ``LIST_FILE`` set to contain
# ``${CMAKE_CURRENT_BINARY_DIR}/target.list``
#
# :: # ::
# #
# extract_symbols(target_name # extract_symbols(target_name
# HEADERS_LIST_FILE headers_list # HEADERS_LIST headers_list_target
# [FILTER_PATTERN pattern] # [FILTER_PATTERN pattern]
# [COPY_TO output] # [COPY_TO output]
# ) # )
@ -153,9 +164,9 @@
# the string given in ``target_name`` will be created in # the string given in ``target_name`` will be created in
# ``${CMAKE_CURRENT_BINARY_DIR}`` to receive the list of symbols. # ``${CMAKE_CURRENT_BINARY_DIR}`` to receive the list of symbols.
# #
# ``HEADERS_LIST_FILE``: # ``HEADERS_LIST``:
# Required, expects a path to a file containing the list of header files to be # Required, expects a target with the property ``LIST_FILE`` set, containing a
# parsed. # file path. Such file must contain a list of files paths.
# #
# ``FILTER_PATTERN``: # ``FILTER_PATTERN``:
# Optional, expects a string. Only the lines containing the filter pattern # Optional, expects a string. Only the lines containing the filter pattern
@ -170,7 +181,9 @@
# is provided, then only the lines containing the string given in ``pattern`` # is provided, then only the lines containing the string given in ``pattern``
# will be considered. It is recommended to provide a ``FILTER_PATTERN`` to mark # will be considered. It is recommended to provide a ``FILTER_PATTERN`` to mark
# the lines containing exported function declaration, since this function is # the lines containing exported function declaration, since this function is
# experimental and can return wrong symbols when parsing the header files. # experimental and can return wrong symbols when parsing the header files. A
# target named ``target_name`` will be created with the property ``LIST_FILE``
# set to contain ``${CMAKE_CURRENT_BINARY_DIR}/${target_name}.list``.
# #
# Example: # Example:
# #
@ -178,11 +191,12 @@
# #
# find_package(ABIMap) # find_package(ABIMap)
# extract_symbols("lib.symbols" # extract_symbols("lib.symbols"
# HEADERS_LIST_FILE "headers_list" # HEADERS_LIST "headers_target"
# FILTER_PATTERN "API_FUNCTION" # FILTER_PATTERN "API_FUNCTION"
# ) # )
# #
# Where headers_list contains:: # Where ``LIST_FILE`` property in ``headers_target`` points to a file
# containing::
# #
# header1.h;header2.h # header1.h;header2.h
# #
@ -196,7 +210,8 @@
# #
# int private_func2(int b); # int private_func2(int b);
# #
# Will result in a file ``lib.symbols`` in ``${CMAKE_CURRENT_BINARY_DIR}`` containing:: # Will result in a file ``lib.symbols.list`` in ``${CMAKE_CURRENT_BINARY_DIR}``
# containing::
# #
# ``exported_func1;exported_func2`` # ``exported_func1;exported_func2``
# #
@ -235,42 +250,41 @@ set(_GET_FILES_LIST_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/GetFilesList.cmake)
function(get_file_list _TARGET_NAME) function(get_file_list _TARGET_NAME)
set(one_value_arguments set(one_value_arguments
COPY_TO COPY_TO
) )
set(multi_value_arguments set(multi_value_arguments
DIRECTORIES DIRECTORIES
FILES_PATTERNS FILES_PATTERNS
) )
cmake_parse_arguments(_get_files_list cmake_parse_arguments(_get_files_list
"" ""
"${one_value_arguments}" "${one_value_arguments}"
"${multi_value_arguments}" "${multi_value_arguments}"
${ARGN} ${ARGN}
) )
# The DIRS argument is required # The DIRS argument is required
if (NOT DEFINED _get_files_list_DIRECTORIES) if (NOT DEFINED _get_files_list_DIRECTORIES)
message(FATAL_ERROR "No directories paths provided. Provide a list of" message(FATAL_ERROR "No directories paths provided. Provide a list of"
" directories paths containing header files." " directories paths containing header files.")
) endif()
endif()
# The FILES_PATTERNS argument is required # The FILES_PATTERNS argument is required
if (NOT DEFINED _get_files_list_FILES_PATTERNS) if (NOT DEFINED _get_files_list_FILES_PATTERNS)
message(FATAL_ERROR "No matching expressions provided. Provide a list" message(FATAL_ERROR "No matching expressions provided. Provide a list"
" of matching patterns for the header files." " of matching patterns for the header files.")
)
endif() endif()
get_filename_component(_get_files_list_OUTPUT_PATH set(_FILES_LIST_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${_TARGET_NAME}.list)
"${CMAKE_CURRENT_BINARY_DIR}/${_TARGET_NAME}"
ABSOLUTE
)
add_custom_command( get_filename_component(_get_files_list_OUTPUT_PATH
OUTPUT ${_TARGET_NAME} "${_FILES_LIST_OUTPUT_PATH}"
ABSOLUTE)
add_custom_target(
${_TARGET_NAME} ALL
COMMAND ${CMAKE_COMMAND} COMMAND ${CMAKE_COMMAND}
-DOUTPUT_PATH="${_get_files_list_OUTPUT_PATH}" -DOUTPUT_PATH="${_get_files_list_OUTPUT_PATH}"
-DDIRECTORIES="${_get_files_list_DIRECTORIES}" -DDIRECTORIES="${_get_files_list_DIRECTORIES}"
@ -280,58 +294,75 @@ function(get_file_list _TARGET_NAME)
"Searching for files" "Searching for files"
) )
set_target_properties(${_TARGET_NAME}
PROPERTIES LIST_FILE ${_FILES_LIST_OUTPUT_PATH}
)
if (DEFINED _get_files_list_COPY_TO) if (DEFINED _get_files_list_COPY_TO)
# Copy the generated file back to the COPY_TO # Copy the generated file back to the COPY_TO
add_custom_target(copy_headers_list_${TARGET_NAME} ALL add_custom_target(copy_${TARGET_NAME} ALL
COMMAND COMMAND
${CMAKE_COMMAND} -E copy_if_different ${_TARGET_NAME} ${_get_files_list_COPY_TO} ${CMAKE_COMMAND} -E copy_if_different
DEPENDS "${_TARGET_NAME}" ${_FILES_LIST_OUTPUT_PATH} ${_get_files_list_COPY_TO}
DEPENDS ${_TARGET_NAME}
COMMENT "Copying ${_TARGET_NAME} to ${_get_files_list_COPY_TO}" COMMENT "Copying ${_TARGET_NAME} to ${_get_files_list_COPY_TO}"
) )
endif() endif()
endfunction() endfunction()
function(extract_symbols _TARGET_NAME) function(extract_symbols _TARGET_NAME)
set(one_value_arguments set(one_value_arguments
FILTER_PATTERN FILTER_PATTERN
HEADERS_LIST_FILE HEADERS_LIST
COPY_TO COPY_TO
) )
set(multi_value_arguments set(multi_value_arguments
) )
cmake_parse_arguments(_extract_symbols cmake_parse_arguments(_extract_symbols
"" ""
"${one_value_arguments}" "${one_value_arguments}"
"${multi_value_arguments}" "${multi_value_arguments}"
${ARGN} ${ARGN}
) )
# The HEADERS_LIST_FILE argument is required # The HEADERS_LIST_FILE argument is required
if (NOT DEFINED _extract_symbols_HEADERS_LIST_FILE) if (NOT DEFINED _extract_symbols_HEADERS_LIST)
message(FATAL_ERROR "No header files given. Provide a list of header" message(FATAL_ERROR "No target provided in HEADERS_LIST. Provide a"
" files containing exported symbols." " target with the property LIST_FILE set as the"
) " path to the file containing the list of headers.")
endif() endif()
get_filename_component(_extract_symbols_OUTPUT_PATH get_filename_component(_SYMBOLS_OUTPUT_PATH
"${CMAKE_CURRENT_BINARY_DIR}/${_TARGET_NAME}" "${CMAKE_CURRENT_BINARY_DIR}/${_TARGET_NAME}.list"
ABSOLUTE ABSOLUTE
) )
add_custom_target(${_TARGET_NAME} get_target_property(_HEADERS_LIST_FILE
COMMAND ${CMAKE_COMMAND} ${_extract_symbols_HEADERS_LIST}
-DOUTPUT_PATH="${_extract_symbols_OUTPUT_PATH}" LIST_FILE
-DHEADERS_LIST_FILE="${_extract_symbols_HEADERS_LIST_FILE}" )
-DFILTER_PATTERN=${_extract_symbols_FILTER_PATTERN}
-P ${_EXTRACT_SYMBOLS_SCRIPT} add_custom_target(
DEPENDS ${_extract_symbols_HEADERS_LIST_FILE} ${_TARGET_NAME} ALL
COMMENT "Extracting symbols from headers") COMMAND ${CMAKE_COMMAND}
-DOUTPUT_PATH="${_SYMBOLS_OUTPUT_PATH}"
-DHEADERS_LIST_FILE="${_HEADERS_LIST_FILE}"
-DFILTER_PATTERN=${_extract_symbols_FILTER_PATTERN}
-P ${_EXTRACT_SYMBOLS_SCRIPT}
DEPENDS ${_extract_symbols_HEADERS_LIST}
COMMENT "Extracting symbols from headers"
)
set_target_properties(${_TARGET_NAME}
PROPERTIES LIST_FILE ${_SYMBOLS_OUTPUT_PATH}
)
if (DEFINED _extract_symbols_COPY_TO) if (DEFINED _extract_symbols_COPY_TO)
file(READ "${CMAKE_CURRENT_BINARY_DIR}/${_TARGET_NAME}" SYMBOL_CONTENT) file(READ "${_SYMBOLS_OUTPUT_PATH}" SYMBOL_CONTENT)
string(REPLACE ";" "\n" SYMBOL_CONTENT_NEW "${SYMBOL_CONTENT}") string(REPLACE ";" "\n" SYMBOL_CONTENT_NEW "${SYMBOL_CONTENT}")
file(WRITE "${_extract_symbols_COPY_TO}" "${SYMBOL_CONTENT_NEW}") file(WRITE "${_extract_symbols_COPY_TO}" "${SYMBOL_CONTENT_NEW}")
endif() endif()
@ -355,36 +386,42 @@ function(generate_map_file _TARGET_NAME)
) )
cmake_parse_arguments(_generate_map_file cmake_parse_arguments(_generate_map_file
"${options}" "${options}"
"${one_value_arguments}" "${one_value_arguments}"
"${multi_value_arguments}" "${multi_value_arguments}"
${ARGN} ${ARGN}
) )
if (NOT DEFINED _generate_map_file_SYMBOLS) if (NOT DEFINED _generate_map_file_SYMBOLS)
message(FATAL_ERROR "No symbols file provided." message(FATAL_ERROR "No target provided in SYMBOLS. Provide a target"
) " with the property LIST_FILE set as the path to"
" the file containing the list of symbols.")
endif() endif()
if (NOT DEFINED _generate_map_file_RELEASE_NAME_VERSION) if (NOT DEFINED _generate_map_file_RELEASE_NAME_VERSION)
message(FATAL_ERROR "Release name and version not provided." message(FATAL_ERROR "Release name and version not provided."
" (e.g. libname_1_0_0" " (e.g. libname_1_0_0)")
)
endif() endif()
# Set generated map file path
get_filename_component(_generate_map_file_OUTPUT_PATH get_target_property(_SYMBOLS_FILE
"${CMAKE_CURRENT_BINARY_DIR}/${_TARGET_NAME}" ${_generate_map_file_SYMBOLS}
ABSOLUTE LIST_FILE
) )
add_custom_command( # Set generated map file path
OUTPUT ${_TARGET_NAME} get_filename_component(_MAP_OUTPUT_PATH
"${CMAKE_CURRENT_BINARY_DIR}/${_TARGET_NAME}"
ABSOLUTE
)
add_custom_target(
${_TARGET_NAME} ALL
COMMAND ${CMAKE_COMMAND} COMMAND ${CMAKE_COMMAND}
-DABIMAP_EXECUTABLE=${ABIMAP_EXECUTABLE} -DABIMAP_EXECUTABLE=${ABIMAP_EXECUTABLE}
-DSYMBOLS="${_generate_map_file_SYMBOLS}" -DSYMBOLS="${_SYMBOLS_FILE}"
-DCURRENT_MAP=${_generate_map_file_CURRENT_MAP} -DCURRENT_MAP=${_generate_map_file_CURRENT_MAP}
-DOUTPUT_PATH="${_generate_map_file_OUTPUT_PATH}" -DOUTPUT_PATH="${_MAP_OUTPUT_PATH}"
-DFINAL=${_generate_map_file_FINAL} -DFINAL=${_generate_map_file_FINAL}
-DBREAK_ABI=${_generate_map_file_BREAK_ABI} -DBREAK_ABI=${_generate_map_file_BREAK_ABI}
-DRELEASE_NAME_VERSION=${_generate_map_file_RELEASE_NAME_VERSION} -DRELEASE_NAME_VERSION=${_generate_map_file_RELEASE_NAME_VERSION}
@ -393,13 +430,21 @@ function(generate_map_file _TARGET_NAME)
COMMENT "Generating the map ${_TARGET_NAME}" COMMENT "Generating the map ${_TARGET_NAME}"
) )
# Add a custom command setting the map as OUTPUT to allow it to be added as
# a generated source
add_custom_command(
OUTPUT ${_MAP_OUTPUT_PATH}
DEPENDS ${_TARGET_NAME}
)
if (DEFINED _generate_map_file_COPY_TO) if (DEFINED _generate_map_file_COPY_TO)
# Copy the generated map back to the COPY_TO # Copy the generated map back to the COPY_TO
add_custom_target(copy_map_${_TARGET_NAME} ALL add_custom_target(copy_${_TARGET_NAME} ALL
COMMAND COMMAND
${CMAKE_COMMAND} -E copy_if_different ${_TARGET_NAME} ${_generate_map_file_COPY_TO} ${CMAKE_COMMAND} -E copy_if_different ${_MAP_OUTPUT_PATH}
DEPENDS "${_TARGET_NAME}" ${_generate_map_file_COPY_TO}
COMMENT "Copying ${_TARGET_NAME} to ${_generate_map_file_COPY_TO}" DEPENDS ${_TARGET_NAME}
COMMENT "Copying ${_MAP_OUTPUT_PATH} to ${_generate_map_file_COPY_TO}"
) )
endif() endif()
endfunction() endfunction()

Просмотреть файл

@ -268,13 +268,13 @@ set(MAP_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.map")
if (WITH_SYMBOL_VERSIONING AND HAVE_LD_VERSION_SCRIPT AND ABIMAP_FOUND) if (WITH_SYMBOL_VERSIONING AND HAVE_LD_VERSION_SCRIPT AND ABIMAP_FOUND)
# Get the list of header files # Get the list of header files
get_file_list("dev_header_list" get_file_list(dev_header_list
DIRECTORIES "${LIBSSH_PUBLIC_INCLUDE_DIRS}/libssh" DIRECTORIES "${LIBSSH_PUBLIC_INCLUDE_DIRS}/libssh"
FILES_PATTERNS "*.h") FILES_PATTERNS "*.h")
# Extract the symbols marked as "LIBSSH_API" from the header files # Extract the symbols marked as "LIBSSH_API" from the header files
extract_symbols("${PROJECT_NAME}_dev.symbols" extract_symbols("${PROJECT_NAME}_dev.symbols"
HEADERS_LIST_FILE "dev_header_list" HEADERS_LIST dev_header_list
FILTER_PATTERN "LIBSSH_API") FILTER_PATTERN "LIBSSH_API")
if (WITH_ABI_BREAK) if (WITH_ABI_BREAK)