You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.5 KiB

cmake_minimum_required(VERSION 3.26)
project(csci)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${CMAKE_CURRENT_BINARY_DIR}")
if(WIN32)
set(CMAKE_PREFIX_PATH $ENV{QT_5_MINGW64})
set(BOOST_INCLUDES third_party/boost-1_83/include)
set(BOOST_LIBRARIES third_party/boost-1_83/lib)
endif ()
if(APPLE)
set(BOOST_ROOT "/usr/local/Cellar/boost/1.83.0")
find_package(Boost 1.83.0 COMPONENTS system)
set(BOOST_INCLUDES ${Boost_INCLUDE_DIRS})
set(BOOST_LIBRARIES ${Boost_LIBRARIES})
endif ()
add_executable(${PROJECT_NAME} main.cpp)
add_subdirectory(third_party/QxOrm)
add_dependencies(${PROJECT_NAME} QxOrm)
find_package(Qt5 COMPONENTS
Core
Concurrent
Sql
REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC
Qt5::Core
Qt5::Concurrent
Qt5::Sql
)
# 添加源码目录
aux_source_directory(config CONFIG_DIR)
aux_source_directory(controller CONTROLLER_DIR)
aux_source_directory(service SERVICE_DIR)
aux_source_directory(entity ENTITY_DIR)
aux_source_directory(handler HANDLER_DIR)
aux_source_directory(compute COMPUTE_DIR)
aux_source_directory(kafka KAFKA_DIR)
target_include_directories(${PROJECT_NAME} PRIVATE
include/code
include/kafka
include/controller
${BOOST_INCLUDES}
)
target_sources(${PROJECT_NAME} PRIVATE
${CONFIG_DIR}
${CONTROLLER_DIR}
${SERVICE_DIR}
${ENTITY_DIR}
${HANDLER_DIR}
${COMPUTE_DIR}
${KAFKA_DIR}
)
target_link_libraries(${PROJECT_NAME} PUBLIC
rdkafka
rdkafka++
QxOrm
${BOOST_LIBRARIES}
)
include(third_party/QxOrm/QxOrm.cmake)
add_subdirectory(third_party/librdkafka)
# 拷贝依赖库
file(COPY application.ini DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) # 拷贝QxOrm
#file(COPY lib/kafka/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) # 拷贝kafka
#file(GLOB LIB "lib/*.dll")
#file(COPY ${LIB} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) # 拷贝mysql
#file(COPY lib/sqldrivers DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) # 拷贝QT mysql驱动
file(COPY third_party/QxOrm/lib/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) # 拷贝QxOrm
if (WIN32 AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(DEBUG_SUFFIX)
if (MSVC AND CMAKE_BUILD_TYPE MATCHES "Debug")
set(DEBUG_SUFFIX "d")
endif ()
set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}")
if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
endif ()
endif ()
if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
endif ()
foreach (QT_LIB Core Concurrent Sql)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${QT_INSTALL_PATH}/bin/Qt5${QT_LIB}${DEBUG_SUFFIX}.dll"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>")
endforeach (QT_LIB)
endif ()