From 6b82763a88211da5ab6cd482854df8a888a136bf Mon Sep 17 00:00:00 2001 From: freemine Date: Mon, 2 May 2022 09:27:44 +0800 Subject: [PATCH] 1. odbc requirement check in CMakeLists.txt(s) (#12087) * 1. odbc requirement check in CMakeLists.txt(s) 2. remove unnecessary LINK_DIRECTORIES directives in several tests CMakeLists.txt(s) * revert LINK_DIRECTORIES directive for googletest --- src/connector/odbc/CMakeLists.txt | 134 ++++++++++--------- src/connector/odbc/examples/c/CMakeLists.txt | 8 +- src/connector/odbc/src/CMakeLists.txt | 9 +- src/connector/odbc/src/base/CMakeLists.txt | 5 +- src/connector/odbc/tools/CMakeLists.txt | 7 +- 5 files changed, 83 insertions(+), 80 deletions(-) diff --git a/src/connector/odbc/CMakeLists.txt b/src/connector/odbc/CMakeLists.txt index 49a9ceb067..5e8095c7dd 100644 --- a/src/connector/odbc/CMakeLists.txt +++ b/src/connector/odbc/CMakeLists.txt @@ -1,71 +1,74 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20) PROJECT(TDengine) -IF (TD_LINUX_64) - find_program(HAVE_ODBCINST NAMES odbcinst) - IF (HAVE_ODBCINST) - include(CheckSymbolExists) - # shall we revert CMAKE_REQUIRED_LIBRARIES and how? - set(CMAKE_REQUIRED_LIBRARIES odbc) - check_symbol_exists(SQLExecute "sql.h" HAVE_ODBC_DEV) - if(NOT (HAVE_ODBC_DEV)) - unset(HAVE_ODBC_DEV CACHE) - message(WARNING "unixodbc-dev is not installed yet, you may install it under Ubuntu by typing: sudo apt install unixodbc-dev") - else () - message(STATUS "unixodbc/unixodbc-dev are installed, and odbc connector will be built") - find_package(FLEX) - if(NOT FLEX_FOUND) - message(WARNING "you need to install flex first") - else () - if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0.0) - message(WARNING "gcc 4.8.0 will complain too much about flex-generated code, we just bypass building ODBC driver in such case") - else () - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ") - SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ") - ADD_SUBDIRECTORY(src) - ADD_SUBDIRECTORY(tools) - ADD_SUBDIRECTORY(examples) - endif () - endif() - endif() - ELSE () - message(WARNING "unixodbc is not installed yet, you may install it under Ubuntu by typing: sudo apt install unixodbc") +macro(check_odbc_requirement) + find_package(FLEX) + IF (NOT FLEX_FOUND) + message(WARNING "you need to install flex first") + return () + ENDIF () + IF (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0.0) + message(WARNING "gcc 4.8.0 will complain too much about flex-generated code, we just bypass building ODBC driver in such case") + return () ENDIF () -ENDIF () -IF (TD_DARWIN) - find_program(HAVE_ODBCINST NAMES odbcinst) - IF (HAVE_ODBCINST) - include(CheckSymbolExists) - # shall we revert CMAKE_REQUIRED_LIBRARIES and how? - set(CMAKE_REQUIRED_LIBRARIES odbc) - set(CMAKE_REQUIRED_INCLUDES /usr/local/include /opt/homebrew/include) - set(CMAKE_REQUIRED_LINK_OPTIONS -L/usr/local/lib -L/opt/homebrew/lib) - check_symbol_exists(SQLExecute "sql.h" HAVE_ODBC_DEV) - if(NOT (HAVE_ODBC_DEV)) - unset(HAVE_ODBC_DEV CACHE) + find_program(TD_ODBCINST_INSTALLED NAMES odbcinst) + IF (NOT TD_ODBCINST_INSTALLED) + IF (TD_DARWIN) message(WARNING "unixodbc is not installed yet, you may install it under macOS by typing: brew install unixodbc") - else () - message(STATUS "unixodbc is installed, and odbc connector will be built") - find_package(FLEX) - if(NOT FLEX_FOUND) - message(WARNING "you need to install flex first") - else () - if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0.0) - message(WARNING "gcc 4.8.0 will complain too much about flex-generated code, we just bypass building ODBC driver in such case") - else () - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wconversion") - SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wconversion") - ADD_SUBDIRECTORY(src) - ADD_SUBDIRECTORY(tools) - ADD_SUBDIRECTORY(examples) - endif () - endif() - endif() - ELSE () - message(WARNING "unixodbc is not installed yet, you may install it under macOS by typing: brew install unixodbc") + ELSE () + message(WARNING "odbcinst is not installed yet, you may install it under Ubuntu by typing: sudo apt install odbcinst") + ENDIF () + return () + ENDIF () + + find_program(TD_ISQL_INSTALLED NAMES isql) + IF (NOT TD_ISQL_INSTALLED) + IF (TD_DARWIN) + message(WARNING "unixodbc is not installed yet, you may install it under macOS by typing: brew install unixodbc") + ELSE () + message(WARNING "unixodbc is not installed yet, you may install it under Ubuntu by typing: sudo apt install unixodbc") + ENDIF () + return () + ENDIF () + + find_program(TD_PKG_CONFIG_INSTALLED NAMES pkg-config) + IF (NOT TD_PKG_CONFIG_INSTALLED) + IF (TD_DARWIN) + message(WARNING "pkg-config is not installed yet, you may install it under macOS by typing: brew install pkg-config") + ELSE () + message(WARNING "pkg-config is not installed yet, you may install it under Ubuntu by typing: sudo apt install pkg-config") + ENDIF () + return () ENDIF () -ENDIF () + + EXECUTE_PROCESS(COMMAND pkg-config --variable=includedir odbc ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE ODBC_INCLUDE_DIRECTORY) + EXECUTE_PROCESS(COMMAND pkg-config --variable=libdir odbc ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE ODBC_LIBRARY_DIRECTORY) + EXECUTE_PROCESS(COMMAND pkg-config --libs-only-L odbc ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE ODBC_LINK_OPTIONS) + + EXECUTE_PROCESS(COMMAND pkg-config --variable=includedir odbcinst ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE ODBCINST_INCLUDE_DIRECTORY) + EXECUTE_PROCESS(COMMAND pkg-config --variable=libdir odbcinst ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE ODBCINST_LIBRARY_DIRECTORY) + EXECUTE_PROCESS(COMMAND pkg-config --libs-only-L odbcinst ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE ODBCINST_LINK_OPTIONS) + + include(CheckSymbolExists) + + set(CMAKE_REQUIRED_LIBRARIES odbc odbcinst) + set(CMAKE_REQUIRED_INCLUDES ${ODBC_INCLUDE_DIRECTORY} ${ODBCINST_INCLUDE_DIRECTORY}) + set(CMAKE_REQUIRED_LINK_OPTIONS ${ODBC_LINK_OPTIONS} ${ODBCINST_LINK_OPTIONS}) + + check_symbol_exists(SQLExecute "sql.h" HAVE_ODBC_DEV) + IF (NOT HAVE_ODBC_DEV) + message(WARNING "odbc requirement not satisfied, check detail in ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeError.log") + return () + ENDIF () + + check_symbol_exists(SQLInstallODBC "odbcinst.h" HAVE_ODBCINST_DEV) + IF (NOT HAVE_ODBCINST_DEV) + message(WARNING "odbc requirement not satisfied, check detail in ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeError.log") + return () + ENDIF () + +endmacro() IF (TD_WINDOWS_64) find_package(ODBC) @@ -86,5 +89,14 @@ IF (TD_WINDOWS_64) ADD_SUBDIRECTORY(tools) ADD_SUBDIRECTORY(examples) endif() +ELSE () + check_odbc_requirement() + IF (TD_DARWIN) + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wconversion") + SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wconversion") + ENDIF () + ADD_SUBDIRECTORY(src) + ADD_SUBDIRECTORY(tools) + ADD_SUBDIRECTORY(examples) ENDIF () diff --git a/src/connector/odbc/examples/c/CMakeLists.txt b/src/connector/odbc/examples/c/CMakeLists.txt index f06b4d0986..4298549655 100644 --- a/src/connector/odbc/examples/c/CMakeLists.txt +++ b/src/connector/odbc/examples/c/CMakeLists.txt @@ -3,15 +3,11 @@ PROJECT(TDengine) ADD_EXECUTABLE(tcodbc main.c ../../src/todbc_log.c) IF (TD_LINUX OR TD_DARWIN) + target_include_directories(tcodbc PRIVATE ${ODBC_INCLUDE_DIRECTORY}) + target_link_directories(tcodbc PUBLIC ${ODBC_LIBRARY_DIRECTORY}) TARGET_LINK_LIBRARIES(tcodbc taos odbc) ENDIF () -IF (TD_DARWIN) - # TODO: later we shall specify directories according to the specific target intel/arm64 - target_include_directories(tcodbc PRIVATE /usr/local/include /opt/homebrew/include) - target_link_directories(tcodbc PUBLIC /usr/local/lib /opt/homebrew/lib) -ENDIF () - IF (TD_WINDOWS_64) SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /GL") SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL") diff --git a/src/connector/odbc/src/CMakeLists.txt b/src/connector/odbc/src/CMakeLists.txt index 1564934cfd..f0df94795a 100644 --- a/src/connector/odbc/src/CMakeLists.txt +++ b/src/connector/odbc/src/CMakeLists.txt @@ -18,7 +18,8 @@ IF (TD_LINUX_64) SET_TARGET_PROPERTIES(todbc PROPERTIES CLEAN_DIRECT_OUTPUT 1) SET_TARGET_PROPERTIES(todbc PROPERTIES VERSION ${TD_VER_NUMBER} SOVERSION 1) TARGET_LINK_LIBRARIES(todbc todbc_base taos odbcinst) - target_include_directories(todbc PUBLIC .) + target_include_directories(todbc PRIVATE . ${ODBC_INCLUDE_DIRECTORY}) + target_link_directories(todbc PUBLIC ${ODBC_LIBRARY_DIRECTORY}) install(CODE "execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/install.sh ${CMAKE_BINARY_DIR})") ENDIF () @@ -39,10 +40,8 @@ IF (TD_DARWIN) SET_TARGET_PROPERTIES(todbc PROPERTIES CLEAN_DIRECT_OUTPUT 1) SET_TARGET_PROPERTIES(todbc PROPERTIES VERSION ${TD_VER_NUMBER} SOVERSION 1) TARGET_LINK_LIBRARIES(todbc todbc_base taos odbcinst) - target_include_directories(todbc PUBLIC .) - # TODO: later we shall specify directories according to the specific target intel/arm64 - target_include_directories(todbc PRIVATE /usr/local/include /opt/homebrew/include) - target_link_directories(todbc PUBLIC /usr/local/lib /opt/homebrew/lib) + target_include_directories(todbc PRIVATE . ${ODBCINST_INCLUDE_DIRECTORY}) + target_link_directories(todbc PUBLIC ${ODBCINST_LIBRARY_DIRECTORY}) install(CODE "execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/install.sh ${CMAKE_BINARY_DIR})") ENDIF () diff --git a/src/connector/odbc/src/base/CMakeLists.txt b/src/connector/odbc/src/base/CMakeLists.txt index 8f1e62c50a..40f2aaf972 100644 --- a/src/connector/odbc/src/base/CMakeLists.txt +++ b/src/connector/odbc/src/base/CMakeLists.txt @@ -4,8 +4,7 @@ PROJECT(TDengine) aux_source_directory(. SRC) add_library(todbc_base STATIC ${SRC}) -if (TD_DARWIN) - # TODO: later we shall specify directories according to the specific target intel/arm64 - target_include_directories(todbc_base PRIVATE /usr/local/include /opt/homebrew/include) +if (TD_LINUX OR TD_DARWIN) + target_include_directories(todbc_base PRIVATE ${ODBC_INCLUDE_DIRECTORY}) endif () diff --git a/src/connector/odbc/tools/CMakeLists.txt b/src/connector/odbc/tools/CMakeLists.txt index b51f424fc5..d49d334ef5 100644 --- a/src/connector/odbc/tools/CMakeLists.txt +++ b/src/connector/odbc/tools/CMakeLists.txt @@ -4,15 +4,12 @@ ADD_EXECUTABLE(todbcinst main.c) ADD_EXECUTABLE(tconv tconv.c) IF (TD_LINUX OR TD_DARWIN) + target_include_directories(todbcinst PRIVATE . ${ODBC_INCLUDE_DIRECTORY} ${ODBCINST_INCLUDE_DIRECTORY}) + target_link_directories(todbcinst PUBLIC ${ODBC_LIBRARY_DIRECTORY} ${ODBCINST_LIBRARY_DIRECTORY}) TARGET_LINK_LIBRARIES(todbcinst odbc odbcinst) ENDIF () IF (TD_DARWIN) - # TODO: later we shall specify directories according to the specific target intel/arm64 - target_include_directories(todbcinst PRIVATE /usr/local/include /opt/homebrew/include) - target_link_directories(todbcinst PUBLIC /usr/local/lib /opt/homebrew/lib) - target_include_directories(tconv PRIVATE /usr/local/include /opt/homebrew/include) - target_link_directories(tconv PUBLIC /usr/local/lib /opt/homebrew/lib) TARGET_LINK_LIBRARIES(tconv iconv) ENDIF () -- GitLab