diff --git a/CMakeLists.txt b/CMakeLists.txt index bd1f81009..78f783b2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,9 @@ -cmake_minimum_required(VERSION 2.8.7) +cmake_minimum_required(VERSION 3.0.2) 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) @@ -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() @@ -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) @@ -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() ######################################## diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e02af7f9f..4f6ae8f3b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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) diff --git a/examples/table_schema.cpp b/examples/table_schema.cpp index 92f079e34..d411d6481 100644 --- a/examples/table_schema.cpp +++ b/examples/table_schema.cpp @@ -11,7 +11,9 @@ #include #ifdef _WIN32 +#ifndef __MINGW32__ #define NOMINMAX +#endif #include // SQLLEN, SQLULEN, SQLHWND #endif #include diff --git a/src/nanodbc.cpp b/src/nanodbc.cpp index 741fe1f58..7dae11c5e 100755 --- a/src/nanodbc.cpp +++ b/src/nanodbc.cpp @@ -44,7 +44,9 @@ #ifdef _WIN32 // needs to be included above sql.h for windows - #define NOMINMAX + #ifndef __MINGW32__ + #define NOMINMAX + #endif #include #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 276ff966e..8671be6d1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) @@ -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() diff --git a/test/base_test_fixture.h b/test/base_test_fixture.h index 743dff2fe..b111bc3bc 100644 --- a/test/base_test_fixture.h +++ b/test/base_test_fixture.h @@ -25,7 +25,9 @@ #ifdef _WIN32 // needs to be included above sql.h for windows -#define NOMINMAX +#ifndef __MINGW32__ + #define NOMINMAX +#endif #include #endif #include diff --git a/test/mssql_test.cpp b/test/mssql_test.cpp index a9d4abe12..8fdd3add7 100644 --- a/test/mssql_test.cpp +++ b/test/mssql_test.cpp @@ -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); @@ -236,4 +236,4 @@ TEST_CASE_METHOD(mssql_fixture, "async_test", "[mssql][async]") REQUIRE(row.get(0) >= 0); } -#endif //WIN32 +#endif //defined(WIN32) && !defined(NANODBC_DISABLE_ASYNC)