Skip to content

Commit

Permalink
Merge pull request #7 from bpintea/feature/data_conversion
Browse files Browse the repository at this point in the history
Data conversion: timing data types. Testing
  • Loading branch information
bpintea authored Jun 4, 2018
2 parents 0ac9b79 + 286f200 commit 0c68261
Show file tree
Hide file tree
Showing 22 changed files with 2,184 additions and 285 deletions.
233 changes: 136 additions & 97 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
#
# ELASTICSEARCH CONFIDENTIAL
# __________________
#
# [2018] Elasticsearch Incorporated. All Rights Reserved.
#
# NOTICE: All information contained herein is, and remains
# the property of Elasticsearch Incorporated and its suppliers,
# if any. The intellectual and technical concepts contained
# herein are proprietary to Elasticsearch Incorporated
# and its suppliers and may be covered by U.S. and Foreign Patents,
# patents in process, and are protected by trade secret or copyright law.
# Dissemination of this information or reproduction of this material
# is strictly forbidden unless prior written permission is obtained
# from Elasticsearch Incorporated.
#

# 2.8.6: to generate the _EXPORTS define
cmake_minimum_required(VERSION 2.8.6 FATAL_ERROR)
# 3.1.0: CMAKE_GENERATOR_PLATFORM
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)

set(DRIVER_BASE_NAME elasticodbc CACHE STRING
"The base name to give the driver")

# driver's version
set(DRV_VER_MAJOR 0)
set(DRV_VER_MINOR 1)
set(BASE_NAME elasticodbc)

# build a UNICODE driver? (currently only supported way)
# build a UNICODE driver? (the only supported way currently)
set(IS_UNICODE 1)

#include(GenerateExportHeader)

# https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_PLATFORM.html :
# "The value of this variable should never be modified by project code."
# , BUT:
# https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2015%202017.html :
# "The CMAKE_GENERATOR_PLATFORM variable may be set to specify a target
# platform name (architecture)."
if (${WIN32})
if ($ENV{VSCMD_ARG_TGT_ARCH} MATCHES x64)
set(CMAKE_GENERATOR_PLATFORM x64)
if (${CMAKE_GENERATOR_PLATFORM} MATCHES x64)
#set(CMAKE_GENERATOR_PLATFORM x64)
set(TARCH x64) # target arch
set(BARCH ) # bits architecture (64 is the default, silent)
else ($ENV{VSCMD_ARG_TGT_ARCH} MATCHES x64)
else (${CMAKE_GENERATOR_PLATFORM} MATCHES x64)
set(TARCH x86)
set(BARCH 32)
endif ($ENV{VSCMD_ARG_TGT_ARCH} MATCHES x64)
endif (${CMAKE_GENERATOR_PLATFORM} MATCHES x64)
message("Building on Windows, ${TARCH}.")
else (${WIN32})
message(FATAL_ERROR "No support for current platform yet")
endif (${WIN32})

# explicit languages support (Cs are defaults)
project(${BASE_NAME} CXX C)
project(${DRIVER_BASE_NAME} CXX C)

if (${IS_UNICODE})
set(ENCODING u) # Unicode
Expand All @@ -41,14 +56,34 @@ endif (${IS_UNICODE})

# driver name
# XXX: ANSI/Unicode/32/64
set(DRV_NAME "${BASE_NAME}${DRV_VER_MAJOR}${ENCODING}${BARCH}")
set(DRV_NAME "${DRIVER_BASE_NAME}${DRV_VER_MAJOR}${ENCODING}${BARCH}")

# Turn on the ability to create folders to organize projects (.vcproj)
# It creates "CMakePredefinedTargets" folder by default and adds CMake
# defined projects like INSTALL.vcproj and ZERO_CHECK.vcproj
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Set compiler flags and options.


# which version is the code at?
execute_process(COMMAND
git describe --dirty=+ --broken=X --always --tags
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE CMD_RETURN
OUTPUT_VARIABLE CMD_OUTPUT
ERROR_VARIABLE CMD_OUTERR
)
# WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/${DRV_SRC_DIR}"
if (${CMD_RETURN})
message(WARNING "Git command failed:")
message("\tret: ${CMD_RETURN}")
message("\tout: ${CMD_OUTPUT}")
message("\terr: ${CMD_OUTERR}")
set(DRV_SRC_VER "n/a")
else (${CMD_RETURN})
set(DRV_SRC_VER ${CMD_OUTPUT})
endif (${CMD_RETURN})

# Set compiler flags and options.
if (${WIN32})
# set the Visual Studio warning level to 4
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
Expand All @@ -61,39 +96,48 @@ if (${WIN32})
if (${IS_UNICODE})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DUNICODE /D_UNICODE")
endif (${IS_UNICODE})
# set the version
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DDRV_NAME=${DRV_NAME}")

# set the all identifiers
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DDRV_VER_MAJOR=${DRV_VER_MAJOR}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DDRV_VER_MINOR=${DRV_VER_MINOR}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DDRV_SRC_VER=${DRV_SRC_VER}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DDRV_ENCODING=${ENCODING}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DDRV_NAME=${DRV_NAME}")

#set(LIBCURL_PATH_LIB ${LIBCURL_PATH_LIB}\\libcurl.dll)
# ...including the build type indicator
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /DDRV_BUILD_TYPE=d")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /DDRV_BUILD_TYPE=r")
set(CMAKE_C_FLAGS_RELWITHDEBINFO
"${CMAKE_C_FLAGS_RELWITHDEBINFO} /DDRV_BUILD_TYPE=i")
set(CMAKE_C_FLAGS_MINSIZEREL
"${CMAKE_C_FLAGS_MINSIZEREL} /DDRV_BUILD_TYPE=s")

# unless building for stripping Release, export the testing functions
# (this will allow RelWithDebInfo buliding and still be able to test it)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /DTEST_API=")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_RELEASE} /DTEST_API=")
else (${WIN32})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")

#set(LIBCURL_PATH_LIB ${LIBCURL_PATH_LIB}/libcurl.so)
endif (${WIN32})
message("C flags: ${CMAKE_C_FLAGS} .")

set(DRV_SRC_DIR driver)
set(DRV_LIB_DIR lib)
set(DRV_BUILD_DIR builds)
message("Directories: source: '${DRV_SRC_DIR}', output: '${DRV_LIB_DIR}'.")

aux_source_directory(${DRV_SRC_DIR} DRV_SRC)

# generate Module definition file (symbols to export)
execute_process(COMMAND
execute_process(COMMAND
${CMAKE_SOURCE_DIR}/${DRV_SRC_DIR}/build_def.bat ${DRV_NAME}
${CMAKE_SOURCE_DIR}/${DRV_BUILD_DIR}/${DRV_NAME}.def
${CMAKE_BINARY_DIR}/${DRV_NAME}.def
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/${DRV_SRC_DIR}"
RESULT_VARIABLE CMD_RETURN
OUTPUT_VARIABLE CMD_OUTPUT
ERROR_VARIABLE CMD_OUTERR
)
# WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/${DRV_SRC_DIR}"
if (${CMD_RETURN})
message("Generating module .def file failed:")
message(WARNING "Generating module .def file failed:")
message("\tret: ${CMD_RETURN}")
message("\tout: ${CMD_OUTPUT}")
message("\terr: ${CMD_OUTERR}")
Expand All @@ -103,106 +147,101 @@ endif (${CMD_RETURN})
#
# add ODBC-Specification to the project
#
if (IS_DIRECTORY $ENV{ODBC_PATH_SRC})
set(ODBC_PATH_SRC $ENV{ODBC_PATH_SRC})
else (IS_DIRECTORY $ENV{ODBC_PATH_SRC})
if (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/ODBC-Specification)
set(ODBC_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/ODBC-Specification)
else (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/ODBC-Specification)
message(FATAL_ERROR "No ODBC-Specification directory found: set "
"environment var ODBC_PATH_SRC or place an "
"'ODBC-Specification' export into local 'lib' dir.")
endif (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/ODBC-Specification)
endif (IS_DIRECTORY $ENV{ODBC_PATH_SRC})
# TODO: add this as a git subtree and/or as ExternalProject
set(ODBC_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/ODBC-Specification CACHE PATH
"ODBC-Specification source path")
if (NOT IS_DIRECTORY ${ODBC_PATH_SRC})
message(FATAL_ERROR "No ODBC-Specification directory found: use "
"ODBC_PATH_SRC cmake option or place an 'ODBC-Specification' "
"clone into local 'lib' dir.")
endif (NOT IS_DIRECTORY ${ODBC_PATH_SRC})
message("ODBC-Specification source path: ${ODBC_PATH_SRC} .")
set(ODBC_INC ${ODBC_PATH_SRC}/Windows/inc )
set(ODBC_INC ${ODBC_PATH_SRC}/Windows/inc)


#
# add ujson4c to the project
#
if (IS_DIRECTORY $ENV{UJSON4C_PATH_SRC})
set(UJSON4C_PATH_SRC $ENV{UJSON4C_PATH_SRC})
else (IS_DIRECTORY $ENV{UJSON4C_PATH_SRC})
if (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/ujson4c)
set(UJSON4C_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/ujson4c)
else (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/ujson4c)
message(FATAL_ERROR "No ujson4c directory found: set environment var "
"UJSON4C_PATH_SRC or place an 'ujson4c' export into local "
"'libs' dir.")
endif (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/ujson4c)
endif (IS_DIRECTORY $ENV{UJSON4C_PATH_SRC})
# TODO: add this as a git subtree and/or as ExternalProject (with patching)
set(UJSON4C_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/ujson4c CACHE PATH
"Lib ujson4c source path")
if (NOT IS_DIRECTORY ${UJSON4C_PATH_SRC})
message(FATAL_ERROR "No ujson4c directory found: use UJSON4C_PATH_SRC "
"cmake option or place an 'ujson4c' clone into local 'libs' dir.")
endif (NOT IS_DIRECTORY ${UJSON4C_PATH_SRC})
message("Lib ujson4c source path: ${UJSON4C_PATH_SRC} .")
aux_source_directory(${UJSON4C_PATH_SRC}/src DRV_SRC)
aux_source_directory(${UJSON4C_PATH_SRC}/3rdparty DRV_SRC)
set(UJSON4C_INC ${UJSON4C_PATH_SRC}/src ${UJSON4C_PATH_SRC}/3rdparty )

#
# add c-timestamp to the project
#
# TODO: add this as a git subtree and/or as ExternalProject
set(CTIMESTAMP_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/c-timestamp CACHE PATH
"Lib c-timestamp source path")
if (NOT IS_DIRECTORY ${CTIMESTAMP_PATH_SRC})
message(FATAL_ERROR "No c-timestamp directory found: use "
"CTIMESTAMP_PATH_SRC cmake option or place a 'c-timestamp' clone "
"in local 'lib' dir.")
endif (NOT IS_DIRECTORY ${CTIMESTAMP_PATH_SRC})
message("Lib c-timestamp source path: ${CTIMESTAMP_PATH_SRC} .")
aux_source_directory(${CTIMESTAMP_PATH_SRC}/ DRV_SRC)

#
# add libcurl to the project
#
# read libcurl's build paths from the environment (assume local dir otherwise)
if (IS_DIRECTORY $ENV{LIBCURL_PATH_BUILD})
set(LIBCURL_PATH_BUILD $ENV{LIBCURL_PATH_BUILD})
else (IS_DIRECTORY $ENV{LIBCURL_PATH_BUILD})
if (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/libcurl)
set(LIBCURL_PATH_BUILD ${CMAKE_SOURCE_DIR}/libs/libcurl)
else (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/libcurl)
message(FATAL_ERROR "No libcurl directory found: set environment var "
"LIBCURL_PATH_BUILD or place a 'libcurl' dir in local source"
"tree, with 'bin' and 'include' subdirs.")
endif (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/libcurl)
endif (IS_DIRECTORY $ENV{LIBCURL_PATH_BUILD})
message("Lib libcurl build path: ${LIBCURL_PATH_BUILD} .")
# TODO: add this as a git subtree and/or as ExternalProject
set(LIBCURL_LD_PATH
# curl "installs" the .dll and .lib in different directories -> use the
# build dir to find both files in same directory instead of installing
${CMAKE_SOURCE_DIR}/libs/curl/builds/libcurl-vc-${TARCH}-release-dll-ipv6-sspi-winssl-obj-lib/
CACHE PATH "Lib curl load library path")
set(LIBCURL_INC_PATH ${CMAKE_SOURCE_DIR}/libs/curl/include CACHE PATH
"Lib curl include path")
if (NOT IS_DIRECTORY ${LIBCURL_LD_PATH}
OR NOT IS_DIRECTORY ${LIBCURL_INC_PATH})
message(FATAL_ERROR "Missing libcurl lib and/or inc directories: use "
"LIBCURL_LD_PATH and LIBCURL_INC_PATH cmake options or place a built "
"'curl' clone in local 'libs' dir.")
endif()
message("Curl paths load lib: ${LIBCURL_LD_PATH}, inc: ${LIBCURL_INC_PATH} .")
# add libcurl as dependency
add_library(libcurl SHARED IMPORTED)
set(LIBCURL_INC ${LIBCURL_PATH_BUILD}/include)
if (${WIN32})
set_property(TARGET libcurl PROPERTY IMPORTED_LOCATION
${LIBCURL_PATH_BUILD}/bin/libcurl.dll)
set_property(TARGET libcurl PROPERTY IMPORTED_LOCATION
${LIBCURL_LD_PATH}/libcurl${CMAKE_SHARED_LIBRARY_SUFFIX})
set_property(TARGET libcurl PROPERTY IMPORTED_IMPLIB
${LIBCURL_PATH_BUILD}/lib/libcurl.lib)
${LIBCURL_LD_PATH}/libcurl${CMAKE_STATIC_LIBRARY_SUFFIX})
else (${WIN32})
set_property(TARGET libcurl PROPERTY IMPORTED_LOCATION
${LIBCURL_PATH_BUILD}/lib/libcurl.so)
set_property(TARGET libcurl PROPERTY IMPORTED_LOCATION
${LIBCURL_LD_PATH}/libcurl${CMAKE_SHARED_LIBRARY_SUFFIX})
endif (${WIN32})

#
# add c-timestamp to the project
#
if (IS_DIRECTORY $ENV{CTIMESTAMP_PATH_SRC})
set(CTIMESTAMP_PATH_SRC $ENV{CTIMESTAMP_PATH_SRC})
else (IS_DIRECTORY $ENV{CTIMESTAMP_PATH_SRC})
if (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/c-timestamp)
set(CTIMESTAMP_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/c-timestamp)
else (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/c-timestamp)
message(FATAL_ERROR "No c-timestamp directory found: set environment"
" var CTIMESTAMP_PATH_SRC or place an export into "
"'c-timestamp' dir in local source tree.")
endif (IS_DIRECTORY ${CMAKE_SOURCE_DIR}/libs/c-timestamp)
endif (IS_DIRECTORY $ENV{CTIMESTAMP_PATH_SRC})
message("Lib c-timestamp source path: ${CTIMESTAMP_PATH_SRC} .")
aux_source_directory(${CTIMESTAMP_PATH_SRC}/ DRV_SRC)
set(CTIMESTAMP_INC ${CTIMESTAMP_PATH_SRC}/ )


message("Driver source files: ${DRV_SRC} .")
message("Driver include paths: " ${ODBC_INC} ${DRV_SRC_DIR} ${LIBCURL_INC}
${UJSON4C_INC} ${CTIMESTAMP_INC})
message("Driver include paths: " ${ODBC_INC} ${DRV_SRC_DIR}
${LIBCURL_INC_PATH} ${UJSON4C_INC} ${CTIMESTAMP_PATH_SRC})

#
# finally, set destination library
#
add_library(${DRV_NAME} SHARED ${DRV_SRC} ${DRV_BUILD_DIR}/${DRV_NAME}.def)
add_library(${DRV_NAME} SHARED ${DRV_SRC} ${CMAKE_BINARY_DIR}/${DRV_NAME}.def)
#generate_export_header(${DRV_NAME})
target_compile_definitions(${DRV_NAME} PRIVATE "DRIVER_BUILD")

#include_directories(${DRV_SRC_DIR} ${DRV_BUILD_DIR})
include_directories(${ODBC_INC} ${DRV_SRC_DIR} ${LIBCURL_INC} ${UJSON4C_INC}
${CTIMESTAMP_INC})

include_directories(${ODBC_INC} ${DRV_SRC_DIR} ${LIBCURL_INC_PATH}
${UJSON4C_INC} ${CTIMESTAMP_PATH_SRC})

target_link_libraries(${DRV_NAME} libcurl)

# add testing project/target
enable_testing()
# ... and testing directory to build
add_subdirectory(test)

# add instalation project/target
install(TARGETS ${DRV_NAME} DESTINATION ${DRV_LIB_DIR})


install(TARGETS ${DRV_NAME}
DESTINATION ${DRV_LIB_DIR}
)
# vim: set noet fenc=utf-8 ff=dos sts=0 sw=4 ts=4 :
Loading

0 comments on commit 0c68261

Please sign in to comment.