diff --git a/cmake/test/AST_BUILDOPT_SUM.cmake b/cmake/test/AST_BUILDOPT_SUM.cmake index a1770ae9..872ec215 100644 --- a/cmake/test/AST_BUILDOPT_SUM.cmake +++ b/cmake/test/AST_BUILDOPT_SUM.cmake @@ -4,20 +4,19 @@ # CMAKE_MINIMUM_REQUIRED(VERSION 3.20) -IF(NOT DEFINED CMAKE_ARGV3) +IF(NOT DEFINED MODULE_PATH) MESSAGE(FATAL_ERROR "Library not specified") ENDIF() -IF(NOT DEFINED CMAKE_ARGV4) +IF(NOT DEFINED AST_BUILDOPT_SUM) MESSAGE(FATAL_ERROR "Checksum not specified") ENDIF() -MESSAGE(DEBUG "DLL:\t${CMAKE_ARGV3}") -STRING(TOLOWER "${CMAKE_ARGV4}" AST_BUILDOPT_SUM) +MESSAGE(DEBUG "DLL:\t${MODULE_PATH}") MESSAGE(DEBUG "CHECKSUM:\t${AST_BUILDOPT_SUM}") EXECUTE_PROCESS( - COMMAND grep -Eao "[0-9abcdef]{32}" ${CMAKE_ARGV3} + COMMAND grep -Eao "[0-9abcdef]{32}" ${MODULE_PATH} OUTPUT_VARIABLE CHECKSUM_CANDIDATES_ML OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY @@ -27,20 +26,19 @@ EXECUTE_PROCESS( STRING(REGEX MATCHALL "[^\n\r]+" CHECKSUM_CANDIDATES ${CHECKSUM_CANDIDATES_ML}) LIST(LENGTH CHECKSUM_CANDIDATES CHECKSUM_CANDIDATES_CNT) IF (${CHECKSUM_CANDIDATES_CNT} EQUAL 0) - MESSAGE(FATAL_ERROR "Could not find checksums in ${${CMAKE_ARGV3}}") + MESSAGE(FATAL_ERROR "Could not find checksums in ${MODULE_PATH}") ENDIF() SET(TEST_PASSED) FOREACH(l IN LISTS CHECKSUM_CANDIDATES) IF(${l} STREQUAL ${AST_BUILDOPT_SUM}) - MESSAGE(STATUS "AST_BUILDOPT_SUM: ${l} ✓") + MESSAGE(STATUS "[checksum] ${l} ✓") SET(TEST_PASSED ON) ELSE() - MESSAGE(STATUS "AST_BUILDOPT_SUM: ${l} ⍻") + MESSAGE(STATUS "[checksum] ${l} ⍻") ENDIF() ENDFOREACH() IF(NOT TEST_PASSED) - MESSAGE(FATAL_ERROR "Checksum ${AST_BUILDOPT_SUM} not found") + MESSAGE(FATAL_ERROR "Checksum not found") ENDIF() - diff --git a/cmake/test/arch-specific.cmake b/cmake/test/arch-specific.cmake new file mode 100644 index 00000000..5a68ff58 --- /dev/null +++ b/cmake/test/arch-specific.cmake @@ -0,0 +1,31 @@ +# +# arch-specific +# +CMAKE_MINIMUM_REQUIRED(VERSION 3.20) + +IF(NOT DEFINED CMAKE_READELF) + MESSAGE(FATAL_ERROR "readelf utility not specified") +ENDIF() + +IF(NOT DEFINED MODULE_PATH) + MESSAGE(FATAL_ERROR "Library not specified") +ENDIF() + +EXECUTE_PROCESS( + COMMAND ${CMAKE_READELF} -AW ${MODULE_PATH} + OUTPUT_VARIABLE ARCH_SPECIFIC_NL + OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND_ERROR_IS_FATAL ANY + TIMEOUT 15 +) + +IF(ARCH_SPECIFIC_NL) + STRING(REGEX MATCHALL "[^\n\r]+" ARCH_SPECIFIC ${ARCH_SPECIFIC_NL}) + FOREACH(l IN LISTS ARCH_SPECIFIC) + IF("${l}" MATCHES "^[\t ]*(.+):[\t ]*\"(.+)\"$") + MESSAGE(STATUS "[arch-specific] ${CMAKE_MATCH_1}: ${CMAKE_MATCH_2}") + ELSEIF("${l}" MATCHES "^[\t ]*(.+):[\t ]*(.+)$") + MESSAGE(STATUS "[arch-specific] ${CMAKE_MATCH_1}: ${CMAKE_MATCH_2}") + ENDIF() + ENDFOREACH() +ENDIF() diff --git a/cmake/test/comment-section.cmake b/cmake/test/comment-section.cmake index 6b33414e..f35d6b58 100644 --- a/cmake/test/comment-section.cmake +++ b/cmake/test/comment-section.cmake @@ -4,27 +4,27 @@ # CMAKE_MINIMUM_REQUIRED(VERSION 3.20) -IF(NOT DEFINED CMAKE_ARGV3) +IF(NOT DEFINED CMAKE_READELF) MESSAGE(FATAL_ERROR "readelf not specified") ENDIF() -IF(NOT DEFINED CMAKE_ARGV4) +IF(NOT DEFINED MODULE_PATH) MESSAGE(FATAL_ERROR "Library not specified") ENDIF() -IF(NOT DEFINED CMAKE_ARGV5) +IF(NOT DEFINED COMPILER_VERSION) MESSAGE(FATAL_ERROR "Compiler version not specified") ENDIF() EXECUTE_PROCESS( - COMMAND ${CMAKE_ARGV3} -p ".comment" -W ${CMAKE_ARGV4} + COMMAND ${CMAKE_READELF} -p ".comment" -W ${MODULE_PATH} OUTPUT_VARIABLE COMMENTS_NL OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY TIMEOUT 15 ) -STRING(REPLACE "." "\\." ${CMAKE_ARGV5} GCC_VERSION_MATCHER) +STRING(REPLACE "." "\\." ${COMPILER_VERSION} GCC_VERSION_MATCHER) SET(TEST_PASSED) SET(COMMENT_LINES) STRING(REGEX MATCHALL "[^\n\r]+" COMMENTS ${COMMENTS_NL}) @@ -36,14 +36,14 @@ FOREACH(l IN LISTS COMMENTS) IF("${COMMENT_LINE}" MATCHES "GCC\\:" AND "${COMMENT_LINE}" MATCHES "${GCC_VERSION_MATCHER}") SET(TEST_PASSED ON) LIST(APPEND COMMENT_LINES "${COMMENT_LINE}") - MESSAGE(STATUS "Comment: ${COMMENT_LINE} ✓") + MESSAGE(STATUS "[comment] ${COMMENT_LINE} ✓") ELSE() - MESSAGE(VERBOSE "Comment: ${COMMENT_LINE}") + MESSAGE(VERBOSE "[comment] ${COMMENT_LINE}") ENDIF() ENDFOREACH() LIST(LENGTH COMMENT_LINES COMMENT_LINES_CNT) -MESSAGE(STATUS "Status: ${COMMENT_LINES_CNT} comment(s) found") +MESSAGE(STATUS "[status] comments:${COMMENT_LINES_CNT}") IF(NOT TEST_PASSED) MESSAGE(FATAL_ERROR "Check failed") diff --git a/cmake/test/dump-header.cmake b/cmake/test/dump-header.cmake new file mode 100644 index 00000000..7c1a393e --- /dev/null +++ b/cmake/test/dump-header.cmake @@ -0,0 +1,30 @@ +# +# dump-header +# +CMAKE_MINIMUM_REQUIRED(VERSION 3.20) + +IF(NOT DEFINED CMAKE_READELF) + MESSAGE(FATAL_ERROR "readelf utility not specified") +ENDIF() + +IF(NOT DEFINED MODULE_PATH) + MESSAGE(FATAL_ERROR "Library not specified") +ENDIF() + +EXECUTE_PROCESS( + COMMAND ${CMAKE_READELF} -hW ${MODULE_PATH} + OUTPUT_VARIABLE DUMP_HEADER_NL + OUTPUT_STRIP_TRAILING_WHITESPACE + COMMAND_ERROR_IS_FATAL ANY + TIMEOUT 15 +) + +STRING(REGEX MATCHALL "[^\n\r]+" DUMP_HEADER ${DUMP_HEADER_NL}) +FOREACH(l IN LISTS DUMP_HEADER) + IF("${l}" MATCHES "^[\t ]*(.+):[\t ]*\"(.+)\"$") + MESSAGE(STATUS "[header] ${CMAKE_MATCH_1}: ${CMAKE_MATCH_2}") + ELSEIF("${l}" MATCHES "^[\t ]*(.+):[\t ]*(.+)$") + MESSAGE(STATUS "[header] ${CMAKE_MATCH_1}: ${CMAKE_MATCH_2}") + ENDIF() +ENDFOREACH() + diff --git a/cmake/test/needed-libs.cmake b/cmake/test/needed-libs.cmake index 065cebdc..7df3fd84 100644 --- a/cmake/test/needed-libs.cmake +++ b/cmake/test/needed-libs.cmake @@ -4,8 +4,7 @@ # CMAKE_MINIMUM_REQUIRED(VERSION 3.20) -CMAKE_POLICY(SET CMP0057 NEW) -SET(ALLOWED_LIBS libasound libsqlite3 libc libpthread) +SET(ALLOWED_LIBS libasound libsqlite3 libc libpthread libgcc_s) FUNCTION(GetNeededLib NEEDED_LIB) STRING(REGEX REPLACE "^\\[" "" NEEDED_LIB1 ${NEEDED_LIB}) @@ -25,18 +24,16 @@ FUNCTION(CheckLibrary LIB_NAME OUT_VAR) SET("${OUT_VAR}_RESULT" PARENT_SCOPE) ENDFUNCTION() -IF(NOT DEFINED CMAKE_ARGV3) - MESSAGE(FATAL_ERROR "readelf not specified") +IF(NOT DEFINED CMAKE_READELF) + MESSAGE(FATAL_ERROR "readelf utility not specified") ENDIF() -IF(NOT DEFINED CMAKE_ARGV4) +IF(NOT DEFINED MODULE_PATH) MESSAGE(FATAL_ERROR "Library not specified") ENDIF() -MESSAGE(DEBUG "DLL:\t${CMAKE_ARGV4}") - EXECUTE_PROCESS( - COMMAND ${CMAKE_ARGV3} -d -W ${CMAKE_ARGV4} + COMMAND ${CMAKE_READELF} -d -W ${MODULE_PATH} OUTPUT_VARIABLE NEEDED_LIBRARIES_NL OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY @@ -56,21 +53,21 @@ FOREACH(l IN LISTS NEEDED_LIBRARIES) CheckLibrary(${NEEDED_LIB} LIB_CHECK) IF(LIB_CHECK_RESULT) LIST(APPEND EXPECTED_LIBS ${LIB_CHECK_RESULT}) - MESSAGE(STATUS "${LIB_CHECK_RESULT} ✓") + MESSAGE(STATUS "[lib] ${LIB_CHECK_RESULT} ✓") ELSE() LIST(APPEND UNEXPECTED_LIBS ${NEEDED_LIB}) - MESSAGE(STATUS "${NEEDED_LIB} ⍻") + MESSAGE(STATUS "[lib] ${NEEDED_LIB} ⍻") ENDIF() ENDFOREACH() LIST(LENGTH UNEXPECTED_LIBS UNEXPECTED_LIBS_CNT) LIST(LENGTH EXPECTED_LIBS EXPECTED_LIBS_CNT) -MESSAGE(STATUS "Status - expected:${EXPECTED_LIBS_CNT} unexpected:${UNEXPECTED_LIBS_CNT}") +MESSAGE(STATUS "[status] expected:${EXPECTED_LIBS_CNT}, unexpected:${UNEXPECTED_LIBS_CNT}") IF(${UNEXPECTED_LIBS_CNT} GREATER 0) - MESSAGE(FATAL_ERROR "There are ${UNEXPECTED_LIBS_CNT} unexpected libraries") + MESSAGE(FATAL_ERROR "Unexpected libraries found") ENDIF() IF(${EXPECTED_LIBS_CNT} EQUAL 0) - MESSAGE(FATAL_ERROR "Internal error - zero libraries checked") -ENDIF() \ No newline at end of file + MESSAGE(FATAL_ERROR "Internal error — zero libraries checked") +ENDIF() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 36fff1d1..c1ca2b25 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,17 +50,21 @@ INSTALL( IF(IS_GIT_REPO) IF(DEFINED CMAKE_READELF) - ADD_TEST(NAME "Load library" COMMAND ${CMAKE_READELF} -h -W $) + ADD_TEST(NAME "Load library" COMMAND ${CMAKE_COMMAND} + -DCMAKE_READELF=${CMAKE_READELF} + -DMODULE_PATH=$ + -P ${CMAKE_SOURCE_DIR}/cmake/test/dump-header.cmake + ) ADD_TEST(NAME "Check library dependencies" COMMAND ${CMAKE_COMMAND} + -DCMAKE_READELF=${CMAKE_READELF} + -DMODULE_PATH=$ -P ${CMAKE_SOURCE_DIR}/cmake/test/needed-libs.cmake - ${CMAKE_READELF} - $ ) ADD_TEST(NAME "Check comment section" COMMAND ${CMAKE_COMMAND} + -DCMAKE_READELF=${CMAKE_READELF} + -DMODULE_PATH=$ + -DCOMPILER_VERSION=${CMAKE_C_COMPILER_VERSION} -P ${CMAKE_SOURCE_DIR}/cmake/test/comment-section.cmake - ${CMAKE_READELF} - $ - ${CMAKE_C_COMPILER_VERSION} ) SET_TESTS_PROPERTIES( "Load library" @@ -71,13 +75,27 @@ IF(IS_GIT_REPO) TIMEOUT 20 WORKING_DIRECTORY $ ) + IF(CMAKE_CROSSCOMPILING) + ADD_TEST(NAME "Check architecture-specific metadata" COMMAND ${CMAKE_COMMAND} + -DCMAKE_READELF=${CMAKE_READELF} + -DMODULE_PATH=$ + -P ${CMAKE_SOURCE_DIR}/cmake/test/arch-specific.cmake + ) + SET_TESTS_PROPERTIES( + "Check architecture-specific metadata" + PROPERTIES + LABELS "DLL;READELF" + TIMEOUT 20 + WORKING_DIRECTORY $ + ) + ENDIF() ELSE() MESSAGE(WARNING Cannot find readelf utility) ENDIF() ADD_TEST(NAME "Check AST_BUILDOPT_SUM" COMMAND ${CMAKE_COMMAND} + -DMODULE_PATH=$ + -DAST_BUILDOPT_SUM=${AST_BUILDOPT_SUM} -P ${CMAKE_SOURCE_DIR}/cmake/test/AST_BUILDOPT_SUM.cmake - $ - ${AST_BUILDOPT_SUM} ) SET_TESTS_PROPERTIES( "Check AST_BUILDOPT_SUM"