cmake_minimum_required(VERSION 3.23)

###############################################################################
### define funcitons ###

## function: visual studio source group
macro(ADD_SOURCE_GROUP srcpath)
	file(GLOB src_h ${PROJECT_SOURCE_DIR}/${srcpath}/*.h)
	file(GLOB src_cpp ${PROJECT_SOURCE_DIR}/${srcpath}/*.cpp)
	set(src_tmp ${src_h} ${src_cpp})
	if (${srcpath} STREQUAL "./" OR ${srcpath} STREQUAL "." OR ${srcpath} STREQUAL "")
		set(groupName src)
	else()
		set(groupName src/${srcpath})
	endif()
	source_group(${groupName} FILES ${src_tmp})
	list(APPEND SOURCE_FILE ${src_tmp})
endmacro(ADD_SOURCE_GROUP)
###############################################################################

set(PROJECT_NAME ESS)
project(${PROJECT_NAME})

set(CMAKE_CXX_STANDARD 20)

# 【注意】visual studio编译时的字符编码问题，配置属性 --> C/C++ --> 命令行 --> 其它选项: /utf-8 或添加如下指令
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")

# 设置 Release 模式启用调试信息
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
# 设置 Release 模式的优化级别和其他选项
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Od /Ob2")
# 设置 Release 模式下链接器的调试信息
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG")

add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)

# Qt_PATH 为 Qt 的安装地址
#set(QT_PATH "D:/Programs/Qt5/5.15.2/msvc2019_64")
set(QT_PATH "D:/Programs/Qt6/6.10.0/msvc2022_64")
set(CMAKE_PREFIX_PATH ${QT_PATH}/lib/cmake)

# 开启自动编译
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt6 COMPONENTS
	Core
	Gui
	Widgets 
	Network 
	Charts 
	WebEngineWidgets 
REQUIRED)


set(ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
set(THIRDPARTY_PATH ${ROOT_PATH}/../thirdparty)
#set(PVLIBS_PATH ${ROOT_PATH}/../libs/pvb)

include_directories(
	${ROOT_PATH}
	${ROOT_PATH}/app
	${ROOT_PATH}/common
	${ROOT_PATH}/widgets
	${THIRDPARTY_PATH}
	${THIRDPARTY_PATH}/mysql/include
	${THIRDPARTY_PATH}/nlohmann_json-3.11.2
	${THIRDPARTY_PATH}/cpp-httplib-0.25.0
	${THIRDPARTY_PATH}/paho_mqtt/include
	${THIRDPARTY_PATH}/spdlog-1.13.0/include
	${THIRDPARTY_PATH}/OpenXLSX/include
	${THIRDPARTY_PATH}/GmSSL-3.1.1/include
	${THIRDPARTY_PATH}/OpenSSL-3.5.3/include
	#${PVLIBS_PATH}/include/pvserver
	#${PVLIBS_PATH}/include/rllib
)

# 设置编译源文件
ADD_SOURCE_GROUP(.)
ADD_SOURCE_GROUP(common)
ADD_SOURCE_GROUP(app)
ADD_SOURCE_GROUP(database)
ADD_SOURCE_GROUP(protocol)
#ADD_SOURCE_GROUP(widgets)
#ADD_SOURCE_GROUP(widgets/pages)
#ADD_SOURCE_GROUP(pv)
#ADD_SOURCE_GROUP(pv/pages)
ADD_SOURCE_GROUP(qt)
ADD_SOURCE_GROUP(qt/widgets)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../bin)
add_executable(${PROJECT_NAME} ${SOURCE_FILE} "resource.rc")

#set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")

target_link_libraries(${PROJECT_NAME} 
	Qt6::Core
	Qt6::Gui
	Qt6::Widgets
	Qt6::Network
	Qt6::Charts
	Qt6::WebEngineWidgets
)

target_link_libraries(${PROJECT_NAME} 
	ws2_32 iphlpapi
	${THIRDPARTY_PATH}/mysql/lib/x64/libmysql.lib
	${THIRDPARTY_PATH}/paho_mqtt/lib/paho-mqtt3a.lib
	${THIRDPARTY_PATH}/paho_mqtt/lib/paho-mqtt3c.lib
	${THIRDPARTY_PATH}/OpenXLSX/lib/OpenXLSX.lib
	${THIRDPARTY_PATH}/GmSSL-3.1.1/lib/gmssl.lib
	${THIRDPARTY_PATH}/OpenSSL-3.5.3/lib/VC/x64/MD/libcrypto.lib
	#${PVLIBS_PATH}/x64/serverlib.lib
	#${PVLIBS_PATH}/x64/rllib.lib
)