未验证 提交 6b82763a 编写于 作者: F freemine 提交者: GitHub

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
上级 ec3bb3ee
CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20) CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20)
PROJECT(TDengine) PROJECT(TDengine)
IF (TD_LINUX_64) macro(check_odbc_requirement)
find_program(HAVE_ODBCINST NAMES odbcinst) find_package(FLEX)
IF (HAVE_ODBCINST) IF (NOT FLEX_FOUND)
include(CheckSymbolExists) message(WARNING "you need to install flex first")
# shall we revert CMAKE_REQUIRED_LIBRARIES and how? return ()
set(CMAKE_REQUIRED_LIBRARIES odbc) ENDIF ()
check_symbol_exists(SQLExecute "sql.h" HAVE_ODBC_DEV) IF (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0.0)
if(NOT (HAVE_ODBC_DEV)) message(WARNING "gcc 4.8.0 will complain too much about flex-generated code, we just bypass building ODBC driver in such case")
unset(HAVE_ODBC_DEV CACHE) return ()
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")
ENDIF () ENDIF ()
ENDIF ()
IF (TD_DARWIN) find_program(TD_ODBCINST_INSTALLED NAMES odbcinst)
find_program(HAVE_ODBCINST NAMES odbcinst) IF (NOT TD_ODBCINST_INSTALLED)
IF (HAVE_ODBCINST) IF (TD_DARWIN)
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)
message(WARNING "unixodbc is not installed yet, you may install it under macOS by typing: brew install unixodbc") message(WARNING "unixodbc is not installed yet, you may install it under macOS by typing: brew install unixodbc")
else () ELSE ()
message(STATUS "unixodbc is installed, and odbc connector will be built") message(WARNING "odbcinst is not installed yet, you may install it under Ubuntu by typing: sudo apt install odbcinst")
find_package(FLEX) ENDIF ()
if(NOT FLEX_FOUND) return ()
message(WARNING "you need to install flex first") ENDIF ()
else ()
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0.0) find_program(TD_ISQL_INSTALLED NAMES isql)
message(WARNING "gcc 4.8.0 will complain too much about flex-generated code, we just bypass building ODBC driver in such case") IF (NOT TD_ISQL_INSTALLED)
else () IF (TD_DARWIN)
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wconversion") message(WARNING "unixodbc is not installed yet, you may install it under macOS by typing: brew install unixodbc")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wconversion") ELSE ()
ADD_SUBDIRECTORY(src) message(WARNING "unixodbc is not installed yet, you may install it under Ubuntu by typing: sudo apt install unixodbc")
ADD_SUBDIRECTORY(tools) ENDIF ()
ADD_SUBDIRECTORY(examples) return ()
endif () ENDIF ()
endif()
endif() find_program(TD_PKG_CONFIG_INSTALLED NAMES pkg-config)
ELSE () IF (NOT TD_PKG_CONFIG_INSTALLED)
message(WARNING "unixodbc is not installed yet, you may install it under macOS by typing: brew install unixodbc") 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 ()
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) IF (TD_WINDOWS_64)
find_package(ODBC) find_package(ODBC)
...@@ -86,5 +89,14 @@ IF (TD_WINDOWS_64) ...@@ -86,5 +89,14 @@ IF (TD_WINDOWS_64)
ADD_SUBDIRECTORY(tools) ADD_SUBDIRECTORY(tools)
ADD_SUBDIRECTORY(examples) ADD_SUBDIRECTORY(examples)
endif() 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 () ENDIF ()
...@@ -3,15 +3,11 @@ PROJECT(TDengine) ...@@ -3,15 +3,11 @@ PROJECT(TDengine)
ADD_EXECUTABLE(tcodbc main.c ../../src/todbc_log.c) ADD_EXECUTABLE(tcodbc main.c ../../src/todbc_log.c)
IF (TD_LINUX OR TD_DARWIN) 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) TARGET_LINK_LIBRARIES(tcodbc taos odbc)
ENDIF () 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) IF (TD_WINDOWS_64)
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /GL") SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /GL")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL") SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL")
......
...@@ -18,7 +18,8 @@ IF (TD_LINUX_64) ...@@ -18,7 +18,8 @@ IF (TD_LINUX_64)
SET_TARGET_PROPERTIES(todbc PROPERTIES CLEAN_DIRECT_OUTPUT 1) SET_TARGET_PROPERTIES(todbc PROPERTIES CLEAN_DIRECT_OUTPUT 1)
SET_TARGET_PROPERTIES(todbc PROPERTIES VERSION ${TD_VER_NUMBER} SOVERSION 1) SET_TARGET_PROPERTIES(todbc PROPERTIES VERSION ${TD_VER_NUMBER} SOVERSION 1)
TARGET_LINK_LIBRARIES(todbc todbc_base taos odbcinst) 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})") install(CODE "execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/install.sh ${CMAKE_BINARY_DIR})")
ENDIF () ENDIF ()
...@@ -39,10 +40,8 @@ IF (TD_DARWIN) ...@@ -39,10 +40,8 @@ IF (TD_DARWIN)
SET_TARGET_PROPERTIES(todbc PROPERTIES CLEAN_DIRECT_OUTPUT 1) SET_TARGET_PROPERTIES(todbc PROPERTIES CLEAN_DIRECT_OUTPUT 1)
SET_TARGET_PROPERTIES(todbc PROPERTIES VERSION ${TD_VER_NUMBER} SOVERSION 1) SET_TARGET_PROPERTIES(todbc PROPERTIES VERSION ${TD_VER_NUMBER} SOVERSION 1)
TARGET_LINK_LIBRARIES(todbc todbc_base taos odbcinst) TARGET_LINK_LIBRARIES(todbc todbc_base taos odbcinst)
target_include_directories(todbc PUBLIC .) target_include_directories(todbc PRIVATE . ${ODBCINST_INCLUDE_DIRECTORY})
# TODO: later we shall specify directories according to the specific target intel/arm64 target_link_directories(todbc PUBLIC ${ODBCINST_LIBRARY_DIRECTORY})
target_include_directories(todbc PRIVATE /usr/local/include /opt/homebrew/include)
target_link_directories(todbc PUBLIC /usr/local/lib /opt/homebrew/lib)
install(CODE "execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/install.sh ${CMAKE_BINARY_DIR})") install(CODE "execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/install.sh ${CMAKE_BINARY_DIR})")
ENDIF () ENDIF ()
......
...@@ -4,8 +4,7 @@ PROJECT(TDengine) ...@@ -4,8 +4,7 @@ PROJECT(TDengine)
aux_source_directory(. SRC) aux_source_directory(. SRC)
add_library(todbc_base STATIC ${SRC}) add_library(todbc_base STATIC ${SRC})
if (TD_DARWIN) if (TD_LINUX OR TD_DARWIN)
# TODO: later we shall specify directories according to the specific target intel/arm64 target_include_directories(todbc_base PRIVATE ${ODBC_INCLUDE_DIRECTORY})
target_include_directories(todbc_base PRIVATE /usr/local/include /opt/homebrew/include)
endif () endif ()
...@@ -4,15 +4,12 @@ ADD_EXECUTABLE(todbcinst main.c) ...@@ -4,15 +4,12 @@ ADD_EXECUTABLE(todbcinst main.c)
ADD_EXECUTABLE(tconv tconv.c) ADD_EXECUTABLE(tconv tconv.c)
IF (TD_LINUX OR TD_DARWIN) 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) TARGET_LINK_LIBRARIES(todbcinst odbc odbcinst)
ENDIF () ENDIF ()
IF (TD_DARWIN) 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) TARGET_LINK_LIBRARIES(tconv iconv)
ENDIF () ENDIF ()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册