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

Commit

Permalink
back to cmake version 2.8.7
Browse files Browse the repository at this point in the history
  • Loading branch information
disog committed Jun 7, 2016
1 parent 57b7d5c commit d78234f
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 70 deletions.
134 changes: 96 additions & 38 deletions CMakeLists.txt
@@ -1,11 +1,9 @@
cmake_minimum_required(VERSION 2.8.7)
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 entirely (may help resolve issues in VS2015 builds)" OFF)
option(NANODBC_STATIC "build static instead of shared library" 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,7 @@ 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()
set(IODBC 1)
endif()
endif()

Expand All @@ -131,17 +127,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 @@ -191,38 +176,111 @@ elseif(MINGW)
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 ${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 ${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 ${Boost_LIBRARIES} ${ODBC_LIBRARIES})
set_target_properties(nanodbcu_static PROPERTIES COMPILE_DEFINITIONS NANODBC_USE_UNICODE)

if(MSVC OR MINGW)
# Enables "Use Unicode Character Set" in Visual Studio or MinGW
set_target_properties(nanodbcu_static PROPERTIES COMPILE_DEFINITIONS UNICODE)
set_target_properties(nanodbcu_static PROPERTIES COMPILE_DEFINITIONS _UNICODE)
endif()

if(IODBC)
set_target_properties(nanodbcu_static PROPERTIES COMPILE_DEFINITIONS NANODBC_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 ${Boost_LIBRARIES} ${ODBC_LIBRARIES})
set_target_properties(nanodbcu_shared PROPERTIES COMPILE_DEFINITIONS NANODBC_USE_UNICODE)

if(MSVC OR MINGW)
# Enables "Use Unicode Character Set" in Visual Studio or MinGW
set_target_properties(nanodbcu_shared PROPERTIES COMPILE_DEFINITIONS UNICODE)
set_target_properties(nanodbcu_shared PROPERTIES COMPILE_DEFINITIONS _UNICODE)
endif()

if(IODBC)
set_target_properties(nanodbcu_shared PROPERTIES COMPILE_DEFINITIONS NANODBC_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
LIBRARY DESTINATION lib)
else()
install(TARGETS nanodbc
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif()
message(STATUS "Target install: Turned on")
else()
message(STATUS "Target install: Turned off")
install(FILES cmake/nanodbc-config.cmake DESTINATION lib/cmake/nanodbc)
endif()

########################################
Expand Down
35 changes: 19 additions & 16 deletions examples/CMakeLists.txt
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)
34 changes: 18 additions & 16 deletions test/CMakeLists.txt
Expand Up @@ -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()

0 comments on commit d78234f

Please sign in to comment.