Skip to content

Commit

Permalink
enable unit test build with driver together
Browse files Browse the repository at this point in the history
* build driver static library together with dll on Windows
  • Loading branch information
RoyZhang2022 committed Nov 22, 2023
1 parent d81565f commit 75ce49a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/failover.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
working-directory: ./scripts
if: steps.cache-static-aws-sdk.outputs.cache-hit != 'true'
run: |
.\build_aws_sdk_win.ps1 x64 ${{ env.WINDOWS_BUILD_TYPE}} OFF "${{env.CMAKE_GENERATOR}}"
.\build_aws_sdk_win.ps1 x64 ${{ env.WINDOWS_BUILD_TYPE}} ON "${{env.CMAKE_GENERATOR}}"
- name: Create build environment
shell: bash
Expand Down
54 changes: 26 additions & 28 deletions driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT})
LIST(GET CONNECTOR_DRIVER_TYPE_LIST ${DRIVER_INDEX} DRIVER_TYPE)

SET(DRIVER_NAME "awsmysqlodbc${CONNECTOR_DRIVER_TYPE_SHORT}")
SET(DRIVER_NAME_STATIC "awsmysqlodbc${CONNECTOR_DRIVER_TYPE_SHORT}-static")

SET(DRIVER_SRCS
aws_sdk_helper.cc
Expand Down Expand Up @@ -151,12 +152,8 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT})
# but a dynamic module that will be loaded by ODBC manager. One
# consequence of this is that on Windows import libraries will not
# be generated nor installed.
IF(WIN32)
ADD_LIBRARY(${DRIVER_NAME}-static STATIC ${DRIVER_SRCS} ${AWSSDK_LIB_DIR})
ADD_LIBRARY(${DRIVER_NAME} SHARED ${DRIVER_SRCS} ${AWSSDK_LIB_DIR})
ELSE(WIN32)
ADD_LIBRARY(${DRIVER_NAME} SHARED ${DRIVER_SRCS} ${AWSSDK_LIB_DIR})
ENDIF(WIN32)
ADD_LIBRARY(${DRIVER_NAME_STATIC} STATIC ${DRIVER_SRCS} ${AWSSDK_LIB_DIR})
ADD_LIBRARY(${DRIVER_NAME} SHARED ${DRIVER_SRCS} ${AWSSDK_LIB_DIR})

ADD_COVERAGE(${DRIVER_NAME})

Expand All @@ -169,34 +166,38 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT})
CONFIGURATIONS Debug
DESTINATION "${LIB_SUBDIR}/debug")

INSTALL(TARGETS ${DRIVER_NAME}-static
INSTALL(TARGETS ${DRIVER_NAME_STATIC}
CONFIGURATIONS Release RelWithDebInfo
DESTINATION ${LIB_SUBDIR})

INSTALL(TARGETS ${DRIVER_NAME}-static
INSTALL(TARGETS ${DRIVER_NAME_STATIC}
CONFIGURATIONS Debug
DESTINATION "${LIB_SUBDIR}/debug")
ELSE()
INSTALL(TARGETS ${DRIVER_NAME} DESTINATION ${LIB_SUBDIR})
INSTALL(TARGETS ${DRIVER_NAME_STATIC} DESTINATION ${LIB_SUBDIR})
ENDIF()

IF(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET_TARGET_PROPERTIES(${DRIVER_NAME} PROPERTIES
LINK_FLAGS "${MYSQLODBCCONN_LINK_FLAGS_ENV} ${MYSQL_LINK_FLAGS}"
PREFIX "")
SET_TARGET_PROPERTIES(${DRIVER_NAME}-static PROPERTIES
SET_TARGET_PROPERTIES(${DRIVER_NAME_STATIC} PROPERTIES
LINK_FLAGS "${MYSQLODBCCONN_LINK_FLAGS_ENV} ${MYSQL_LINK_FLAGS}"
PREFIX "")
ELSE(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET_TARGET_PROPERTIES(${DRIVER_NAME} PROPERTIES
LINK_FLAGS "${MYSQLODBCCONN_LINK_FLAGS_ENV} ${MYSQL_LINK_FLAGS}"
PREFIX "") # -flto
SET_TARGET_PROPERTIES(${DRIVER_NAME_STATIC} PROPERTIES
LINK_FLAGS "${MYSQLODBCCONN_LINK_FLAGS_ENV} ${MYSQL_LINK_FLAGS}"
PREFIX "") # -flto
ENDIF()

IF(UNICODE)
SET_TARGET_PROPERTIES(${DRIVER_NAME} PROPERTIES
COMPILE_DEFINITIONS MYODBC_UNICODEDRIVER)
SET_TARGET_PROPERTIES(${DRIVER_NAME}-static PROPERTIES
SET_TARGET_PROPERTIES(${DRIVER_NAME_STATIC} PROPERTIES
COMPILE_DEFINITIONS MYODBC_UNICODEDRIVER)
ENDIF(UNICODE)

Expand All @@ -214,26 +215,21 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT})
LINK_FLAGS_DEBUG "/NODEFAULTLIB:${WITH_NODEFAULTLIB}"
LINK_FLAGS_RELWITHDEBINFO "/NODEFAULTLIB:${WITH_NODEFAULTLIB}"
LINK_FLAGS_RELEASE "/NODEFAULTLIB:${WITH_NODEFAULTLIB}")
SET_TARGET_PROPERTIES(${DRIVER_NAME}-static PROPERTIES
SET_TARGET_PROPERTIES(${DRIVER_NAME_STATIC} PROPERTIES
LINK_FLAGS_DEBUG "/NODEFAULTLIB:${WITH_NODEFAULTLIB}"
LINK_FLAGS_RELWITHDEBINFO "/NODEFAULTLIB:${WITH_NODEFAULTLIB}"
LINK_FLAGS_RELEASE "/NODEFAULTLIB:${WITH_NODEFAULTLIB}")
ENDIF ()

IF(MYSQL8)
TARGET_LINK_LIBRARIES(${DRIVER_NAME} myodbc-util
${MYSQL_CLIENT_LIBS} ws2_32 ${ODBCINSTLIB} ${SECURE32_LIB} legacy_stdio_definitions.lib)
TARGET_LINK_LIBRARIES(${DRIVER_NAME}-static myodbc-util
${MYSQL_CLIENT_LIBS} ws2_32 ${ODBCINSTLIB} ${SECURE32_LIB} legacy_stdio_definitions.lib)
ELSE(MYSQL8)
TARGET_LINK_LIBRARIES(${DRIVER_NAME}-static myodbc-util
${MYSQL_CLIENT_LIBS} ws2_32 ${ODBCINSTLIB} ${SECURE32_LIB})
TARGET_LINK_LIBRARIES(${DRIVER_NAME} myodbc-util
${MYSQL_CLIENT_LIBS} ws2_32 ${ODBCINSTLIB} ${SECURE32_LIB})
TARGET_LINK_LIBRARIES(${DRIVER_NAME} legacy_stdio_definitions.lib)
TARGET_LINK_LIBRARIES(${DRIVER_NAME_STATIC} legacy_stdio_definitions.lib)
ENDIF(MYSQL8)

TARGET_LINK_LIBRARIES(${DRIVER_NAME} Dnsapi)
TARGET_LINK_LIBRARIES(${DRIVER_NAME}-static Dnsapi)
TARGET_LINK_LIBRARIES(${DRIVER_NAME} myodbc-util
${MYSQL_CLIENT_LIBS} ws2_32 ${ODBCINSTLIB} ${SECURE32_LIB} Dnsapi)
TARGET_LINK_LIBRARIES(${DRIVER_NAME_STATIC} myodbc-util
${MYSQL_CLIENT_LIBS} ws2_32 ${ODBCINSTLIB} ${SECURE32_LIB} Dnsapi)

ELSE(WIN32)

Expand All @@ -245,11 +241,13 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT})

SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ODBC_DRIVER_LINK_FLAGS}")
TARGET_LINK_LIBRARIES(${DRIVER_NAME}
${MYSQL_CLIENT_LIBS} ${CMAKE_THREAD_LIBS_INIT} m)
TARGET_LINK_LIBRARIES(${DRIVER_NAME} myodbc-util)
${MYSQL_CLIENT_LIBS} ${CMAKE_THREAD_LIBS_INIT} m myodbc-util)
TARGET_LINK_LIBRARIES(${DRIVER_NAME_STATIC}
${MYSQL_CLIENT_LIBS} ${CMAKE_THREAD_LIBS_INIT} m myodbc-util)

IF(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
TARGET_LINK_LIBRARIES(${DRIVER_NAME} resolv)
TARGET_LINK_LIBRARIES(${DRIVER_NAME_STATIC} resolv)
ENDIF(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")


Expand All @@ -261,13 +259,13 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT})
SET_TARGET_PROPERTIES(${DRIVER_NAME} PROPERTIES
LINKER_LANGUAGE CXX
COMPILE_FLAGS "${MYSQLODBCCONN_COMPILE_FLAGS_ENV} ${MYSQL_CXXFLAGS}")
SET_TARGET_PROPERTIES(${DRIVER_NAME}-static PROPERTIES
SET_TARGET_PROPERTIES(${DRIVER_NAME_STATIC} PROPERTIES
LINKER_LANGUAGE CXX
COMPILE_FLAGS "${MYSQLODBCCONN_COMPILE_FLAGS_ENV} ${MYSQL_CXXFLAGS}")
ENDIF (MYSQL_CXX_LINKAGE)

set_property(TARGET ${DRIVER_NAME} PROPERTY BUILD_WITH_INSTALL_RPATH ON)
set_property(TARGET ${DRIVER_NAME}-static PROPERTY BUILD_WITH_INSTALL_RPATH ON)
set_property(TARGET ${DRIVER_NAME_STATIC} PROPERTY BUILD_WITH_INSTALL_RPATH ON)

if(APPLE)
set_property(TARGET ${DRIVER_NAME} APPEND PROPERTY INSTALL_RPATH "@loader_path")
Expand Down Expand Up @@ -295,8 +293,8 @@ WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT})

TARGET_INCLUDE_DIRECTORIES(${DRIVER_NAME} PUBLIC ${AWSSDK_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(${DRIVER_NAME} ${AWSSDK_LINK_LIBRARIES})
TARGET_INCLUDE_DIRECTORIES(${DRIVER_NAME}-static PUBLIC ${AWSSDK_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(${DRIVER_NAME}-static ${AWSSDK_LINK_LIBRARIES})
TARGET_INCLUDE_DIRECTORIES(${DRIVER_NAME_STATIC} PUBLIC ${AWSSDK_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(${DRIVER_NAME_STATIC} ${AWSSDK_LINK_LIBRARIES})
#------------------------------

ENDWHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT})
6 changes: 1 addition & 5 deletions unit_testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(googletest)

enable_testing()

add_executable(
unit_testing

Expand Down Expand Up @@ -77,8 +75,6 @@ target_link_libraries(
awsmysqlodbca-static
)

include(GoogleTest)
#gtest_discover_tests(unit_testing PROPERTIES DISCOVERY_TIMEOUT 30)

message(STATUS "PROJECT_BINARY_DIR is ${PROJECT_BINARY_DIR}")
set_target_properties(unit_testing PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
5 changes: 3 additions & 2 deletions unit_testing/efm_proxy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ TEST_F(EFMProxyTest, FailureDetectionEnabled) {

EXPECT_CALL(*mock_monitor_service, start_monitoring(_, _, _, _, _, _, _, _, _)).WillOnce(Return(mock_context));
EXPECT_CALL(*mock_monitor_service, stop_monitoring(mock_context)).Times(1);
EXPECT_CALL(*mock_connection_proxy, query(""));
const char *q = nullptr;
EXPECT_CALL(*mock_connection_proxy, query(q));
EXPECT_CALL(*mock_connection_proxy, mock_connection_proxy_destructor());

EFM_PROXY efm_proxy(dbc, ds, mock_connection_proxy, mock_monitor_service);
efm_proxy.query("");
efm_proxy.query(q);
}

TEST_F(EFMProxyTest, DoesNotNeedMonitoring) {
Expand Down

0 comments on commit 75ce49a

Please sign in to comment.