mdbx-cmake: добавление dll-костыля для Windows для работы исключений в тестах на C++.

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2024-10-07 09:09:35 +03:00
parent 54dfc1f16d
commit b11998de01
2 changed files with 135 additions and 64 deletions

View File

@ -906,8 +906,21 @@ if(MDBX_BUILD_SHARED_LIBRARY AND MDBX_LINK_TOOLS_NONSTATIC)
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib")
endif()
endif()
if(WIN32)
# Windows don't have RPATH feature,
# therefore we should prepare PATH or copy DLL(s)
set(TOOL_MDBX_DLLCRUTCH "Crutch for ${CMAKE_SYSTEM_NAME}")
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_VERSION VERSION_LESS 3.0)
# will use LOCATION property to compose DLLPATH
cmake_policy(SET CMP0026 OLD)
endif()
else()
set(TOOL_MDBX_DLLCRUTCH FALSE)
endif()
else()
set(TOOL_MDBX_LIB mdbx-static)
set(TOOL_MDBX_DLLCRUTCH FALSE)
endif()
# build mdbx-tools

View File

@ -75,63 +75,124 @@ if(WIN32)
target_link_libraries(mdbx_test winmm.lib)
endif()
function(add_extra_test name)
set(options DISABLED)
set(oneValueArgs TIMEOUT)
set(multiValueArgs SOURCE LIBRARY DEPEND DLLPATH)
cmake_parse_arguments(params "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(params_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown keywords given to add_extra_test(): \"${params_UNPARSED_ARGUMENTS}\".")
endif()
macro(oops)
message(FATAL_ERROR "add_extra_test(): Opps, " ${ARGV})
endmacro()
if(NOT params_SOURCE)
set(params_SOURCE extra/${name}.c++)
endif()
set(target "test_extra_${name}")
add_executable(${target} ${params_SOURCE})
target_include_directories(${target} PRIVATE "${PROJECT_SOURCE_DIR}")
target_link_libraries(${target} ${TOOL_MDBX_LIB})
set_target_properties(${target} PROPERTIES
SKIP_BUILD_RPATH FALSE
BUILD_WITH_INSTALL_RPATH FALSE)
if(MDBX_BUILD_CXX AND MDBX_CXX_STANDARD)
set_target_properties(${target} PROPERTIES
CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON)
endif()
if(params_DEPEND)
add_dependencies(${target} ${params_DEPEND})
endif()
if(TOOL_MDBX_DLLCRUTCH)
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPERCASE)
foreach(dep IN LISTS params_LIBRARY)
get_target_property(type ${dep} TYPE)
if(type STREQUAL SHARED_LIBRARY)
# Windows don't have RPATH feature,
# therefore we should prepare PATH or copy DLL(s)...
if(CMAKE_CONFIGURATION_TYPES)
# Could not provide static ENVIRONMENT property with configuration-depended path
set(dir FALSE)
else(CMAKE_CONFIGURATION_TYPES)
get_target_property(filename ${dep} IMPORTED_LOCATION_${CMAKE_BUILD_TYPE_UPPERCASE})
if(NOT filename)
get_target_property(filename ${dep} IMPORTED_LOCATION)
endif()
get_target_property(filename ${dep} LOCATION_${CMAKE_BUILD_TYPE_UPPERCASE})
if(NOT filename)
get_target_property(filename ${dep} LOCATION)
endif()
if(filename)
get_filename_component(dir ${filename} DIRECTORY)
else(filename)
get_target_property(dir ${dep} LIBRARY_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE_UPPERCASE})
if(NOT dir)
get_target_property(dir ${dep} RUNTIME_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE_UPPERCASE})
endif()
if(NOT dir)
get_target_property(dir ${dep} LIBRARY_OUTPUT_DIRECTORY)
endif()
if(NOT dir)
get_target_property(dir ${dep} RUNTIME_OUTPUT_DIRECTORY)
endif()
endif(filename)
endif(CMAKE_CONFIGURATION_TYPES)
if(dir)
list(APPEND params_DLLPATH ${dir})
else(dir)
# Path is configuration-depended or not available, should copy dll
add_custom_command(TARGET ${target} POST_BUILD
COMMAND if exist "$<TARGET_PDB_FILE:${dep}>"
${CMAKE_COMMAND} -E copy_if_different "$<TARGET_PDB_FILE:${dep}>" "$<TARGET_FILE_DIR:${target}>")
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:${dep}>" "$<TARGET_FILE_DIR:${target}>"
COMMENT "${TOOL_MDBX_DLLCRUTCH}: Copy shared library ${dep} for test ${target}")
endif(dir)
endif()
endforeach(dep)
endif(TOOL_MDBX_DLLCRUTCH)
if(NOT params_DISABLED AND NOT (CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR))
add_test(extra_${name} ${MDBX_OUTPUT_DIR}/${target})
if(params_TIMEOUT)
if(MEMORYCHECK_COMMAND OR CMAKE_MEMORYCHECK_COMMAND OR ENABLE_MEMCHECK)
# FIXME: unless there are any other ideas how to fix the
# timeouts problem when testing under Valgrind.
math(EXPR params_TIMEOUT "${params_TIMEOUT} * 42")
endif()
set_tests_properties(extra_${name} PROPERTIES TIMEOUT ${params_TIMEOUT})
endif()
if(params_DLLPATH)
# Compose DLL's path in the ENVIRONMENT property
if(WIN32)
set(params_DLLPATH_ENV "${params_DLLPATH};$ENV{PATH}")
else()
set(params_DLLPATH_ENV "${params_DLLPATH}:$ENV{PATH}")
string(REPLACE ":" ";" params_DLLPATH_ENV "${params_DLLPATH_ENV}")
endif()
list(REMOVE_DUPLICATES params_DLLPATH_ENV)
if(WIN32)
string(REPLACE ";" "\\;" params_DLLPATH_ENV "${params_DLLPATH_ENV}")
else()
string(REPLACE ";" ":" params_DLLPATH_ENV "${params_DLLPATH_ENV}")
endif()
set_tests_properties(extra_${name} PROPERTIES ENVIRONMENT "PATH=${params_DLLPATH_ENV}")
endif()
endif()
endfunction(add_extra_test)
if(NOT SUBPROJECT)
if(UNIX)
add_executable(test_extra_pcrf extra/pcrf/pcrf_test.c)
target_include_directories(test_extra_pcrf PRIVATE "${PROJECT_SOURCE_DIR}")
target_link_libraries(test_extra_pcrf ${TOOL_MDBX_LIB})
add_executable(test_extra_upsert_alldups extra/upsert_alldups.c)
target_include_directories(test_extra_upsert_alldups PRIVATE "${PROJECT_SOURCE_DIR}")
target_link_libraries(test_extra_upsert_alldups ${TOOL_MDBX_LIB})
add_executable(test_extra_dupfix_addodd extra/dupfix_addodd.c)
target_include_directories(test_extra_dupfix_addodd PRIVATE "${PROJECT_SOURCE_DIR}")
target_link_libraries(test_extra_dupfix_addodd ${TOOL_MDBX_LIB})
endif()
if(MDBX_BUILD_CXX)
add_executable(test_extra_maindb_ordinal extra/maindb_ordinal.c++)
target_include_directories(test_extra_maindb_ordinal PRIVATE "${PROJECT_SOURCE_DIR}")
target_link_libraries(test_extra_maindb_ordinal ${TOOL_MDBX_LIB})
if(MDBX_CXX_STANDARD)
set_target_properties(test_extra_maindb_ordinal PROPERTIES
CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON)
endif()
add_executable(test_extra_dupfix_multiple extra/dupfix_multiple.c++)
target_include_directories(test_extra_dupfix_multiple PRIVATE "${PROJECT_SOURCE_DIR}")
target_link_libraries(test_extra_dupfix_multiple ${TOOL_MDBX_LIB})
if(MDBX_CXX_STANDARD)
set_target_properties(test_extra_dupfix_multiple PROPERTIES
CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON)
endif()
add_executable(test_extra_hex_base64_base58 extra/hex_base64_base58.c++)
target_include_directories(test_extra_hex_base64_base58 PRIVATE "${PROJECT_SOURCE_DIR}")
target_link_libraries(test_extra_hex_base64_base58 ${TOOL_MDBX_LIB})
if(MDBX_CXX_STANDARD)
set_target_properties(test_extra_hex_base64_base58 PROPERTIES
CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON)
endif()
add_executable(test_extra_doubtless_positioning extra/doubtless_positioning.c++)
target_include_directories(test_extra_doubtless_positioning PRIVATE "${PROJECT_SOURCE_DIR}")
target_link_libraries(test_extra_doubtless_positioning ${TOOL_MDBX_LIB})
if(MDBX_CXX_STANDARD)
set_target_properties(test_extra_doubtless_positioning PROPERTIES
CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON)
endif()
add_executable(test_extra_crunched_delete extra/crunched_delete.c++)
target_include_directories(test_extra_crunched_delete PRIVATE "${PROJECT_SOURCE_DIR}")
target_link_libraries(test_extra_crunched_delete ${TOOL_MDBX_LIB})
if(MDBX_CXX_STANDARD)
set_target_properties(test_extra_crunched_delete PROPERTIES
CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON)
endif()
add_executable(test_extra_dbi extra/dbi.c++)
target_include_directories(test_extra_dbi PRIVATE "${PROJECT_SOURCE_DIR}")
target_link_libraries(test_extra_dbi ${TOOL_MDBX_LIB})
if(MDBX_CXX_STANDARD)
set_target_properties(test_extra_dbi PROPERTIES
CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON)
endif()
endif()
endif()
@ -213,19 +274,16 @@ else()
if(NOT SUBPROJECT)
if(UNIX)
add_test(NAME extra_upsert_alldups COMMAND test_extra_upsert_alldups)
add_test(NAME extra_dupfix_addodd COMMAND test_extra_dupfix_addodd)
add_extra_test(upsert_alldups SOURCE extra/upsert_alldups.c)
add_extra_test(dupfix_addodd SOURCE extra/dupfix_addodd.c)
endif()
if(MDBX_BUILD_CXX AND NOT (WIN32 AND MDBX_BUILD_SHARED_LIBRARY))
add_test(NAME extra_maindb_ordinal COMMAND test_extra_maindb_ordinal)
add_test(NAME extra_dupfix_multiple COMMAND test_extra_dupfix_multiple)
add_test(NAME extra_hex_base64_base58 COMMAND test_extra_hex_base64_base58)
add_test(NAME extra_doubtless_positioning COMMAND test_extra_doubtless_positioning)
if (ENABLE_MEMCHECK)
set_tests_properties(extra_doubtless_positioning PROPERTIES TIMEOUT 10800)
endif()
add_test(NAME extra_crunched_delete COMMAND test_extra_crunched_delete)
add_test(NAME extra_dbi COMMAND test_extra_dbi)
if(MDBX_BUILD_CXX)
add_extra_test(maindb_ordinal)
add_extra_test(dupfix_multiple)
add_extra_test(hex_base64_base58)
add_extra_test(doubtless_positioning TIMEOUT 10800)
add_extra_test(crunched_delete TIMEOUT 10800)
add_extra_test(dbi)
endif()
endif()