未验证 提交 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)
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")
macro(check_odbc_requirement)
find_package(FLEX)
if(NOT FLEX_FOUND)
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)
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")
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()
return ()
ENDIF ()
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(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 ()
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 ()
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)
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)
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))
unset(HAVE_ODBC_DEV CACHE)
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")
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 ()
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 ()
......@@ -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")
......
......@@ -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 ()
......
......@@ -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 ()
......@@ -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 ()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册