1 Star 0 Fork 1

zhoutk/zorm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
CMakeLists.txt 5.53 KB
一键复制 编辑 原始数据 按行查看 历史
cmake_minimum_required(VERSION 3.8)
file(READ "version" ver)
string(REGEX MATCH "VERSION_MAJOR ([0-9]*)" _ ${ver})
set(ver_major ${CMAKE_MATCH_1})
string(REGEX MATCH "VERSION_MINOR ([0-9]*)" _ ${ver})
set(ver_minor ${CMAKE_MATCH_1})
string(REGEX MATCH "VERSION_PATCH ([0-9]*)" _ ${ver})
set(ver_patch ${CMAKE_MATCH_1})
message("version: ${ver_major}.${ver_minor}.${ver_patch}")
project(zorm VERSION ${ver_major}.${ver_minor}.${ver_patch})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# set(CMAKE_BUILD_TYPE Debug) # Use `cmake -DCMAKE_BUILD_TYPE=Debug` more better
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
if(MSVC)
add_definitions(-D__MSVC__)
string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus")
add_compile_options(/wd26451 /wd26812 /wd4267)
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
elseif(UNIX AND NOT APPLE)
add_definitions(-D__LINUX__)
find_package(Threads REQUIRED)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
endif()
add_definitions(-DZORM_LIB)
add_definitions(-DSQLITE_OMIT_TEMPDB)
add_definitions(-DDM64)
option(CMAKE_QJSON_ENABLE "Whether to use QJSON (default use ZJSON)" ON)
if (CMAKE_QJSON_ENABLE)
add_definitions(-D__QJSON)
set(CMAKE_PREFIX_PATH $ENV{QTDIR})
message("QTDIR --- " $ENV{QTDIR})
message("Looking for Qt...")
find_package(Qt5 REQUIRED Core)
if (${Qt5_FOUND})
message("Found Qt " ${Qt5_VERSION})
else()
message("Couldn't find Qt")
endif()
find_package(Qt5Core)
set(CMAKE_AUTOMOC ON)
set(QTLIBS Qt5::Core)
include_directories($ENV{QTDIR}/include)
include_directories($ENV{QTDIR}/include/QtCore)
endif()
include_directories(./thirds/sqlit3)
link_directories(./thirds/sqlit3/lib)
include_directories(./src/include)
include_directories(./thirds/zjson)
include_directories(./thirds/qjson)
include_directories(./thirds/MySQL-C-Api-6.1/include)
if(MSVC)
link_directories(./thirds/MySQL-C-Api-6.1/lib)
include_directories(./thirds/pgsql/include)
link_directories(./thirds/pgsql/lib)
include_directories(./thirds/dm8/dpi/include)
link_directories(./thirds/dm8/dpi)
set(MysqlDll libmysql.dll)
set(pqName libpq.dll)
set(sqliteName sqlite3.dll)
set(dm8Name dmdpi.dll)
elseif(APPLE)
link_directories(./thirds/MySQL-C-Api-6.1/lib)
include_directories(./thirds/pgsql/macos/include)
link_directories(./thirds/pgsql/macos/lib)
set(MysqlDll libmysqlclient.a)
set(pqName libpq.a)
elseif(UNIX)
include_directories(/usr/include/postgresql)
include_directories(/opt/dm8/dpi/include)
link_directories(/opt/dm8/dpi)
set(MysqlDll mysqlclient)
set(pthread pthread)
set(pqName pq)
set(sqliteName libsqlite3.so)
set(dm8Name libdmdpi.so)
endif()
FILE(GLOB_RECURSE SRC_FILES "./src/*.cc")
FILE(GLOB_RECURSE HEAD_FILES "./src/*.h")
add_executable(${PROJECT_NAME} ${SRC_FILES} ${HEAD_FILES})
if(MSVC)
target_link_libraries(${PROJECT_NAME} ${pthread} ${MysqlDll} ${pqName} ${sqliteName} ${dm8Name} ${QTLIBS})
elseif(UNIX)
target_link_libraries(${PROJECT_NAME} ${pthread} ${MysqlDll} ${pqName} ${sqliteName} ${dm8Name} dl)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
##--------------------- Build unit tests -----------------------------------##
option(CMAKE_ZJSON_ENABLE_TEST "Whether to enable unit tests" ON)
if (CMAKE_ZJSON_ENABLE_TEST)
message(STATUS "Unit tests enabled")
enable_testing()
set(CMAKE_PREFIX_PATH $ENV{QTDIR})
find_package(Qt5 REQUIRED Core)
if (${Qt5_FOUND})
message("Found Qt " ${Qt5_VERSION})
else()
message("Couldn't find Qt")
endif()
find_package(Qt5Core)
find_package(Qt5Test)
set(CMAKE_AUTOMOC ON)
include_directories($ENV{QTDIR}/include/QtTest)
add_executable(test_sqlite3 tests/test_sqlite3.cpp "./thirds/sqlit3/sqlite3.h")
add_executable(test_mysql tests/test_mysql.cpp "./thirds/sqlit3/sqlite3.h")
add_executable(test_postgres tests/test_postgres.cpp "./thirds/sqlit3/sqlite3.h")
add_executable(test_dm8 tests/test_dm8.cpp "./thirds/sqlit3/sqlite3.h")
add_test(NAME test_sqlite3 COMMAND test_sqlite3)
add_test(NAME test_mysql COMMAND test_mysql)
add_test(NAME test_postgres COMMAND test_postgres)
add_test(NAME test_dm8 COMMAND test_dm8)
if(MSVC)
target_link_libraries(test_sqlite3 ${pthread} ${MysqlDll} ${pqName} ${sqliteName} ${dm8Name} Qt5::Core Qt5::Test)
target_link_libraries(test_mysql ${pthread} ${MysqlDll} ${pqName} ${sqliteName} ${dm8Name} Qt5::Core Qt5::Test)
target_link_libraries(test_postgres ${pthread} ${MysqlDll} ${pqName} ${sqliteName} ${dm8Name} Qt5::Core Qt5::Test)
target_link_libraries(test_dm8 ${pthread} ${MysqlDll} ${pqName} ${sqliteName} ${dm8Name} Qt5::Core Qt5::Test)
elseif(UNIX)
target_link_libraries(test_sqlite3 ${pthread} ${MysqlDll} ${pqName} ${sqliteName} ${dm8Name} Qt5::Core Qt5::Test dl)
target_link_libraries(test_mysql ${pthread} ${MysqlDll} ${pqName} ${sqliteName} ${dm8Name} Qt5::Core Qt5::Test dl)
target_link_libraries(test_postgres ${pthread} ${MysqlDll} ${pqName} ${sqliteName} ${dm8Name} Qt5::Core Qt5::Test dl)
target_link_libraries(test_dm8 ${pthread} ${MysqlDll} ${pqName} ${sqliteName} ${dm8Name} Qt5::Core Qt5::Test dl)
endif()
endif()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/zhoutk/zorm.git
git@gitee.com:zhoutk/zorm.git
zhoutk
zorm
zorm
master

搜索帮助