Skip to content
This repository has been archived by the owner on Aug 25, 2018. It is now read-only.

ANSI/Unicode and static/shared (recreated) #180

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
131 changes: 96 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
cmake_minimum_required(VERSION 2.8.7)
cmake_minimum_required(VERSION 3.0.2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot accept this change, since Travis CI is based on Ubuntu 12.04 with CMake 2.8.7.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. That's a pity.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsogari are your other changes not compatible with CMake version 2.8.7? Your PR could be updated to revert this particular change if so.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right @lexicalunit. I just realized there is a COMPILE_DEFINITIONS property for targets in version 2.8.7, which could be used instead of target_compile_definitions (from 3.0.2). I'update the PR to reflect this change and some other fixes. Thanks!

Copy link
Author

@ghost ghost Jun 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I create a new PR, then? Or is it possible to reopen a closed one?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsogari I believe it is possible to re-open a PR after a force push updates the branch for it. I think the original PR's author has to reopen it. The reopen button is grayed out for me.

Copy link
Author

@ghost ghost Jun 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's grayed out for me too. The tooltip says "The ... branch was force-pushed or recreated". I'll have to create a new one.

project(nanodbc)

option(NANODBC_USE_UNICODE "build with unicode support turned on" OFF)
option(NANODBC_USE_BOOST_CONVERT "build using Boost.Locale for string convert" OFF)
option(NANODBC_HANDLE_NODATA_BUG "enable special handling for SQL_NO_DATA (required for vertica)" OFF)
option(NANODBC_DISABLE_ASYNC "disable async features entierly (may help resolve issues in VS2015 builds)" OFF)
option(NANODBC_STATIC "build static instead of shared library" OFF)
option(NANODBC_DISABLE_ASYNC "disable async features entirely (may help resolve issues in VS2015 builds)" OFF)
option(NANODBC_EXAMPLES "build examples" ON)
option(NANODBC_TEST "build tests" ON)
option(NANODBC_INSTALL "generate install target" ON)
Expand Down Expand Up @@ -107,9 +105,6 @@ if(UNIX)
set(CMAKE_FLAGS "${CMAKE_FLAGS} ${ODBC_CFLAGS}")
execute_process(COMMAND ${ODBC_CONFIG} --libs
OUTPUT_VARIABLE ODBC_LINK_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NANODBC_USE_UNICODE)
add_definitions(-DNANODBC_USE_IODBC_WIDE_STRINGS)
endif()
endif()
endif()

Expand All @@ -131,17 +126,6 @@ else()
add_definitions(-DNANODBC_ODBC_VERSION=${NANODBC_ODBC_VERSION})
endif()

if(NANODBC_USE_UNICODE)
message(STATUS "Unicode support: Turned on")
add_definitions(-DNANODBC_USE_UNICODE)
if(MSVC)
# Sets "Use Unicode Character Set" property in Visual Studio projects
add_definitions(-DUNICODE -D_UNICODE)
endif()
else()
message(STATUS "Unicode support: Turned off")
endif()

if(NANODBC_USE_BOOST_CONVERT)
message(STATUS "Boost string convert: Turned on")
add_definitions(-DNANODBC_USE_BOOST_CONVERT)
Expand Down Expand Up @@ -186,36 +170,113 @@ if(UNIX)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ODBC_LINK_FLAGS}")
elseif(MSVC)
set(ODBC_LIBRARIES odbc32.lib odbccp32.lib Ws2_32.lib)
elseif(MINGW)
set(ODBC_LIBRARIES odbc32 odbccp32)
endif()

########################################
## nanodbc library target
## nanodbc static library target - ANSI
########################################
if(NANODBC_STATIC)
add_library(nanodbc STATIC src/nanodbc.cpp src/nanodbc.h)
message(STATUS "Build target: STATIC")
else()
add_library(nanodbc SHARED src/nanodbc.cpp src/nanodbc.h)
target_link_libraries(nanodbc ${Boost_LIBRARIES} ${ODBC_LIBRARIES})
message(STATUS "Build target: SHARED")
add_library(nanodbca_static STATIC src/nanodbc.cpp src/nanodbc.h)
set_target_properties(nanodbca_static PROPERTIES OUTPUT_NAME nanodbca)
target_link_libraries(nanodbca_static PUBLIC ${Boost_LIBRARIES} ${ODBC_LIBRARIES})

if(UNIX)
set_target_properties(nanodbca_static PROPERTIES
COMPILE_FLAGS "${ODBC_CFLAGS}"
LIBRARY_OUTPUT_DIRECTORY "lib")
endif()

if(NANODBC_INSTALL)
install(TARGETS nanodbca_static
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif()

########################################
## nanodbc shared library target - ANSI
########################################
add_library(nanodbca_shared SHARED src/nanodbc.cpp src/nanodbc.h)
set_target_properties(nanodbca_shared PROPERTIES OUTPUT_NAME nanodbca)
target_link_libraries(nanodbca_shared PUBLIC ${Boost_LIBRARIES} ${ODBC_LIBRARIES})

if(UNIX)
set_target_properties(nanodbc PROPERTIES
set_target_properties(nanodbca_shared PROPERTIES
COMPILE_FLAGS "${ODBC_CFLAGS}"
LIBRARY_OUTPUT_DIRECTORY "lib")
endif()

if(NANODBC_INSTALL)
install(TARGETS nanodbca_shared
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif()

########################################
## nanodbc static library target - Unicode
########################################
add_library(nanodbcu_static STATIC src/nanodbc.cpp src/nanodbc.h)
set_target_properties(nanodbcu_static PROPERTIES OUTPUT_NAME nanodbcu)
target_link_libraries(nanodbcu_static PUBLIC ${Boost_LIBRARIES} ${ODBC_LIBRARIES})
target_compile_definitions(nanodbcu_static PUBLIC -DNANODBC_USE_UNICODE)

if(MSVC OR MINGW)
# Enables "Use Unicode Character Set" in Visual Studio or MinGW
target_compile_definitions(nanodbcu_static PUBLIC -DUNICODE -D_UNICODE)
endif()

if(ODBC_CONFIG)
target_compile_definitions(nanodbcu_static PUBLIC -DNANODBC_USE_IODBC_WIDE_STRINGS)
endif()

if(UNIX)
set_target_properties(nanodbcu_static PROPERTIES
COMPILE_FLAGS "${ODBC_CFLAGS}"
LIBRARY_OUTPUT_DIRECTORY "lib")
endif()

if(NANODBC_INSTALL)
install(TARGETS nanodbcu_static
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif()

########################################
## nanodbc shared library target - Unicode
########################################
add_library(nanodbcu_shared SHARED src/nanodbc.cpp src/nanodbc.h)
set_target_properties(nanodbcu_shared PROPERTIES OUTPUT_NAME nanodbcu)
target_link_libraries(nanodbcu_shared PUBLIC ${Boost_LIBRARIES} ${ODBC_LIBRARIES})
target_compile_definitions(nanodbcu_shared PUBLIC -DNANODBC_USE_UNICODE)

if(MSVC OR MINGW)
# Enables "Use Unicode Character Set" in Visual Studio or MinGW
target_compile_definitions(nanodbcu_shared PUBLIC -DUNICODE -D_UNICODE)
endif()

if(ODBC_CONFIG)
target_compile_definitions(nanodbcu_shared PUBLIC -DNANODBC_USE_IODBC_WIDE_STRINGS)
endif()

if(UNIX)
set_target_properties(nanodbcu_shared PROPERTIES
COMPILE_FLAGS "${ODBC_CFLAGS}"
LIBRARY_OUTPUT_DIRECTORY "lib")
endif()

if(NANODBC_INSTALL)
install(TARGETS nanodbcu_shared
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif()

########################################
## headers
########################################
if(NANODBC_INSTALL)
install(FILES src/nanodbc.h DESTINATION include)
if(NANODBC_STATIC)
install(TARGETS nanodbc ARCHIVE DESTINATION lib)
else()
install(TARGETS nanodbc LIBRARY DESTINATION lib)
endif()
message(STATUS "Target install: Turned on")
else()
message(STATUS "Target install: Turned off")
endif()

########################################
Expand Down
35 changes: 19 additions & 16 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@ set(examples northwind usage rowset_iteration table_schema)
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src ${ODBC_INCLUDE_DIR})
link_directories(${CMAKE_BINARY_DIR}/lib)

foreach(example ${examples})
add_executable(example_${example} ${example}.cpp example_unicode_utils.h)
if (NANODBC_STATIC)
target_link_libraries(example_${example} nanodbc ${ODBC_LIBRARIES})
else()
target_link_libraries(example_${example} nanodbc "${ODBC_LINK_FLAGS}")
endif()
add_dependencies(examples example_${example})
foreach(config "ansi" "unicode")
foreach(example ${examples})
add_executable(example_${example}_${config} ${example}.cpp example_unicode_utils.h)
if (${config} STREQUAL "ansi")
target_link_libraries(example_${example}_${config} nanodbca_shared)
else()
target_link_libraries(example_${example}_${config} nanodbcu_shared)
endif()
add_dependencies(examples example_${example}_${config})
endforeach()
endforeach()

set(example_empty ${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp)
if(NOT EXISTS ${example_empty}) # Behavior is well-defined only for full paths.
configure_file(${example_empty}.in ${example_empty} COPYONLY)
configure_file(${example_empty}.in ${example_empty} COPYONLY)
endif()
add_executable(example_empty ${example_empty} example_unicode_utils.h)
if (NANODBC_STATIC)
target_link_libraries(example_empty nanodbc ${ODBC_LIBRARIES})
else()
target_link_libraries(example_empty nanodbc "${ODBC_LINK_FLAGS}")
endif()
add_dependencies(examples example_empty)

add_executable(example_empty_ansi ${example_empty} example_unicode_utils.h)
target_link_libraries(example_empty_ansi nanodbca_shared)
add_dependencies(examples example_empty_ansi)

add_executable(example_empty_unicode ${example_empty} example_unicode_utils.h)
target_link_libraries(example_empty_unicode nanodbcu_shared)
add_dependencies(examples example_empty_unicode)
2 changes: 2 additions & 0 deletions examples/table_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include <string>

#ifdef _WIN32
#ifndef __MINGW32__
#define NOMINMAX
#endif
#include <windows.h> // SQLLEN, SQLULEN, SQLHWND
#endif
#include <sql.h>
Expand Down
4 changes: 3 additions & 1 deletion src/nanodbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@

#ifdef _WIN32
// needs to be included above sql.h for windows
#define NOMINMAX
#ifndef __MINGW32__
#define NOMINMAX
#endif
#include <windows.h>
#endif

Expand Down
36 changes: 19 additions & 17 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.7)
cmake_minimum_required(VERSION 3.0.2)
include(ExternalProject)

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
Expand All @@ -25,20 +25,22 @@ link_directories(${CMAKE_BINARY_DIR}/lib)
file(GLOB headers *.h *.hpp)
add_custom_target(tests DEPENDS tests catch)
set(test_list mssql mysql odbc postgresql sqlite)
foreach(test_item ${test_list})
set(test_name ${test_item}_tests)
add_executable(${test_name} main.cpp ${test_item}_test.cpp ${headers})
add_dependencies(${test_name} catch)
if (NANODBC_STATIC)
target_link_libraries(${test_name} nanodbc ${ODBC_LIBRARIES})
else()
target_link_libraries(${test_name} nanodbc "${ODBC_LINK_FLAGS}")
endif()
add_test(NAME ${test_name} COMMAND ${test_name})
add_custom_target(${test_item}_test
COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure -R ${test_name})
add_custom_target(${test_item}_check
COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure -R ${test_name}
DEPENDS ${test_name})
add_dependencies(tests ${test_name})
foreach(config "ansi" "unicode")
foreach(test_item ${test_list})
set(test_name ${test_item}_${config}_tests)
add_executable(${test_name} main.cpp ${test_item}_test.cpp ${headers})
add_dependencies(${test_name} catch)
if (${config} STREQUAL "ansi")
target_link_libraries(${test_name} nanodbca_shared)
else()
target_link_libraries(${test_name} nanodbcu_shared)
endif()
add_test(NAME ${test_name} COMMAND ${test_name})
add_custom_target(${test_item}_${config}_test
COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure -R ${test_name})
add_custom_target(${test_item}_${config}_check
COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure -R ${test_name}
DEPENDS ${test_name})
add_dependencies(tests ${test_name})
endforeach()
endforeach()
4 changes: 3 additions & 1 deletion test/base_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

#ifdef _WIN32
// needs to be included above sql.h for windows
#define NOMINMAX
#ifndef __MINGW32__
#define NOMINMAX
#endif
#include <windows.h>
#endif
#include <sql.h>
Expand Down
4 changes: 2 additions & 2 deletions test/mssql_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ TEST_CASE_METHOD(mssql_fixture, "while_next_iteration_test", "[mssql][looping]")
while_next_iteration_test();
}

#ifdef WIN32
#if defined(WIN32) && !defined(NANODBC_DISABLE_ASYNC)
TEST_CASE_METHOD(mssql_fixture, "async_test", "[mssql][async]")
{
HANDLE event_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
Expand All @@ -236,4 +236,4 @@ TEST_CASE_METHOD(mssql_fixture, "async_test", "[mssql][async]")

REQUIRE(row.get<int>(0) >= 0);
}
#endif //WIN32
#endif //defined(WIN32) && !defined(NANODBC_DISABLE_ASYNC)