210 lines
6.9 KiB
CMake
210 lines
6.9 KiB
CMake
if (WIN32)
|
|
if (MSVC)
|
|
set(EXPORT_ATTR "__declspec(dllexport)")
|
|
set(IMPORT_ATTR "__declspec(dllimport)")
|
|
set(LOCAL_ATTR "")
|
|
set(COMPILER_NAME "MSVC")
|
|
elseif (MINGW)
|
|
set(EXPORT_ATTR "__attribute__((dllexport))")
|
|
set(IMPORT_ATTR "__attribute__((dllimport))")
|
|
set(LOCAL_ATTR "")
|
|
set(COMPILER_NAME "MinGW")
|
|
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
set(EXPORT_ATTR "__attribute__((dllexport))")
|
|
set(IMPORT_ATTR "__attribute__((dllimport))")
|
|
set(LOCAL_ATTR "")
|
|
set(COMPILER_NAME "Clang on Windows")
|
|
else ()
|
|
set(EXPORT_ATTR "__declspec(dllexport)")
|
|
set(IMPORT_ATTR "__declspec(dllimport)")
|
|
set(LOCAL_ATTR "")
|
|
set(COMPILER_NAME "${CMAKE_CXX_COMPILER_ID} on Windows")
|
|
endif ()
|
|
else ()
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
|
|
set(EXPORT_ATTR "__attribute__((visibility(\"default\")))")
|
|
set(IMPORT_ATTR "__attribute__((visibility(\"default\")))")
|
|
set(LOCAL_ATTR "__attribute__((visibility(\"hidden\")))")
|
|
set(COMPILER_NAME "${CMAKE_CXX_COMPILER_ID}")
|
|
else ()
|
|
set(EXPORT_ATTR "")
|
|
set(IMPORT_ATTR "")
|
|
set(LOCAL_ATTR "")
|
|
set(COMPILER_NAME "${CMAKE_CXX_COMPILER_ID}")
|
|
endif ()
|
|
endif ()
|
|
|
|
|
|
set(global_include_dir ${CMAKE_CURRENT_LIST_DIR}/psc_global_include)
|
|
set(base_dir ${CMAKE_CURRENT_LIST_DIR}/Core/Base)
|
|
file(GLOB_RECURSE hs ${global_include_dir}/*.h ${global_include_dir}/*.hpp)
|
|
file(GLOB_RECURSE ss ${global_include_dir}/*.cpp)
|
|
string(APPEND global_include_h "${base_dir}/global_include.h")
|
|
string(APPEND global_include_cpp "${base_dir}/global_include.cpp")
|
|
string(APPEND global_include_h_content "#pragma once\n")
|
|
string(APPEND global_include_cpp_content "#pragma once\n")
|
|
set(rel_global_include "../../psc_global_include")
|
|
foreach (h IN LISTS hs)
|
|
file(RELATIVE_PATH rel_h ${global_include_dir} ${h})
|
|
string(APPEND global_include_h_content "#include \"${rel_global_include}/${rel_h}\"\n")
|
|
endforeach ()
|
|
foreach (s IN LISTS ss)
|
|
file(RELATIVE_PATH rel_s ${global_include_dir} ${s})
|
|
string(APPEND global_include_cpp_content "#include \"${rel_global_include}/${rel_s}\"\n")
|
|
endforeach ()
|
|
file(WRITE ${global_include_h} ${global_include_h_content})
|
|
file(WRITE ${global_include_cpp} ${global_include_cpp_content})
|
|
|
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/3rd/asio/main.cmake)
|
|
|
|
|
|
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/3rd/pfr ${CMAKE_CURRENT_BINARY_DIR}/pfr)
|
|
|
|
|
|
set(3rd_dir ${CMAKE_CURRENT_LIST_DIR}/3rd)
|
|
set(src_dir ${CMAKE_CURRENT_LIST_DIR}/Core)
|
|
|
|
find_package(spdlog CONFIG QUIET)
|
|
add_library(Core_Interface INTERFACE)
|
|
|
|
|
|
file(GLOB_RECURSE srcs
|
|
${src_dir}/*.c
|
|
${src_dir}/*.cpp
|
|
${src_dir}/*.hpp
|
|
${src_dir}/*.h
|
|
)
|
|
add_library(Core_Static STATIC ${srcs})
|
|
|
|
|
|
target_precompile_headers(Core_Static PRIVATE
|
|
"$<$<COMPILE_LANGUAGE:CXX>:${base_dir}/global_include.h>"
|
|
)
|
|
|
|
|
|
if (NOT spdlog_FOUND)
|
|
set(SPDLOG_BUILD_PIC ON)
|
|
set(spdlog_name spdlog-1.17.0)
|
|
set(spdlog_root_dir "${3rd_dir}/spdlog/${spdlog_name}")
|
|
message(STATUS "spdlog not found, use bundled: ${spdlog_src_dir}")
|
|
set(SPDLOG_BUILD_EXAMPLE OFF CACHE BOOL "" FORCE)
|
|
set(SPDLOG_BUILD_EXAMPLE_HO OFF CACHE BOOL "" FORCE)
|
|
set(SPDLOG_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
|
set(SPDLOG_BUILD_TESTS_HO OFF CACHE BOOL "" FORCE)
|
|
set(SPDLOG_BUILD_BENCH OFF CACHE BOOL "" FORCE)
|
|
set(SPDLOG_INSTALL ON CACHE BOOL "" FORCE)
|
|
target_include_directories(Core_Interface INTERFACE ${spdlog_root_dir}/include)
|
|
add_subdirectory(${spdlog_root_dir} ${CMAKE_CURRENT_BINARY_DIR}/Core_spdlog)
|
|
else ()
|
|
message(STATUS "Found spdlog: ${spdlog_VERSION}")
|
|
endif ()
|
|
target_include_directories(Core_Interface INTERFACE "${CMAKE_CURRENT_LIST_DIR}")
|
|
target_include_directories(Core_Interface INTERFACE "${CMAKE_CURRENT_LIST_DIR}/3rd/ucoro/include")
|
|
target_include_directories(Core_Interface INTERFACE ${3rd_dir}/magic_enum/magic_enum/include)
|
|
target_compile_definitions(Core_Interface INTERFACE SPDLOG_COMPILED_LIB)
|
|
target_compile_definitions(Core_Interface INTERFACE INCL_EXTRA_HTON_FUNCTIONS)
|
|
set_target_properties(Core_Interface PROPERTIES FOLDER "Core")
|
|
|
|
# ============================================================
|
|
# Core compile definitions
|
|
# ============================================================
|
|
|
|
target_compile_definitions(Core_Interface INTERFACE
|
|
NOMINMAX
|
|
WIN32_LEAN_AND_MEAN
|
|
_USE_MATH_DEFINES
|
|
)
|
|
|
|
# 如果你的旧代码里还大量使用 #ifdef WIN32,可以临时打开这一行。
|
|
# 新代码建议统一改成 _WIN32,不建议手动定义 WIN32。
|
|
# target_compile_definitions(Core_Interface INTERFACE WIN32)
|
|
|
|
|
|
# ============================================================
|
|
# Compiler options
|
|
# ============================================================
|
|
|
|
if (MSVC)
|
|
target_compile_options(Core_Interface INTERFACE
|
|
/wd4819
|
|
/utf-8
|
|
/Zc:preprocessor
|
|
/EHsc
|
|
/bigobj
|
|
)
|
|
else ()
|
|
target_compile_options(Core_Interface INTERFACE
|
|
-fvisibility=hidden
|
|
-fvisibility-inlines-hidden
|
|
-Wall
|
|
-Wextra
|
|
-Wpedantic
|
|
-Wshadow
|
|
-Wconversion
|
|
-Wsign-conversion
|
|
)
|
|
endif ()
|
|
|
|
|
|
# ============================================================
|
|
# Platform link libraries
|
|
# ============================================================
|
|
|
|
if (WIN32)
|
|
target_link_libraries(Core_Static PRIVATE
|
|
ole32
|
|
oleaut32
|
|
wbemuuid
|
|
psapi
|
|
shell32
|
|
dbghelp
|
|
iphlpapi
|
|
)
|
|
|
|
endif ()
|
|
|
|
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
target_link_libraries(Core_Static PUBLIC
|
|
rt
|
|
dl
|
|
pthread
|
|
)
|
|
endif ()
|
|
|
|
#include("${CMAKE_CURRENT_LIST_DIR}/3rd/ucoro/main.cmake")
|
|
#if (1)
|
|
# set(ucoro_dir "${CMAKE_CURRENT_LIST_DIR}/3rd/ucoro")
|
|
# file(GLOB_RECURSE ucoro_srcs ${ucoro_dir}/*.h ${ucoro_dir}/*.hpp ${ucoro_dir}/*.cpp)
|
|
# target_compile_definitions(Core_Interface INTERFACE _USE_GTEST)
|
|
# target_link_libraries(Core_Static PUBLIC GTest::gtest GTest::gmock)
|
|
# target_sources(Core_Static PUBLIC ${ucoro_srcs})
|
|
#
|
|
#endif ()
|
|
|
|
target_link_libraries(Core_Static PUBLIC boost_pfr)
|
|
|
|
|
|
target_link_libraries(Core_Static PUBLIC Core_Interface)
|
|
target_link_libraries(Core_Static PUBLIC spdlog::spdlog)
|
|
target_link_libraries(Core_Static PUBLIC asio_object)
|
|
|
|
|
|
set_target_properties(Core_Static PROPERTIES
|
|
AUTOMOC OFF
|
|
AUTOUIC OFF
|
|
AUTORCC OFF
|
|
)
|
|
|
|
set_property(TARGET Core_Static PROPERTY POSITION_INDEPENDENT_CODE ON)
|
|
|
|
|
|
add_executable(Core_exe ${CMAKE_CURRENT_LIST_DIR}/main.cpp)
|
|
target_link_libraries(Core_exe PRIVATE Core_Static)
|
|
|
|
|
|
get_target_property(_c_launcher Core_Static C_COMPILER_LAUNCHER)
|
|
get_target_property(_cxx_launcher Core_Static CXX_COMPILER_LAUNCHER)
|
|
message("Core_Static C_COMPILER_LAUNCHER=${_c_launcher}")
|
|
message("Core_Static CXX_COMPILER_LAUNCHER=${_cxx_launcher}")
|