242 lines
7.2 KiB
CMake
242 lines
7.2 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)
|
|
|
|
|
|
|
|
|
|
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 ${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
|
|
)
|
|
endif()
|
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
target_link_libraries(Core_Static PUBLIC
|
|
rt
|
|
dl
|
|
pthread
|
|
)
|
|
endif()
|
|
|
|
|
|
if(1)
|
|
if (NOT GTest_FOUND)
|
|
find_package(GTest)
|
|
endif()
|
|
if (NOT GTest_FOUND)
|
|
add_subdirectory(${CMAKE_SOURCE_DIR}/3rdParty/GTest)
|
|
endif()
|
|
target_compile_definitions(Core_Interface INTERFACE _USE_GTEST)
|
|
target_link_libraries(Core_Static PUBLIC GTest::gtest GTest::gmock)
|
|
endif()
|
|
|
|
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_library(Core_lib STATIC )
|
|
#target_link_libraries(Core_lib PRIVATE Core_Static)
|
|
#
|
|
#add_library(Core_dll SHARED)
|
|
#target_link_libraries(Core_dll PRIVATE Core_Static)
|
|
#
|
|
add_executable(Core_exe ${CMAKE_CURRENT_LIST_DIR}/main.cpp)
|
|
target_link_libraries(Core_exe PRIVATE Core_Static)
|
|
|
|
|
|
|
|
|
|
#add_subdirectory(${core_3rd}/ucoro/ucoro ${CMAKE_BINARY_DIR}/ucoro)
|
|
#include(${CMAKE_CURRENT_LIST_DIR}/learn_coro_code/main.cmake)
|
|
|
|
|
|
|
|
#set(empty_file "${CMAKE_BINARY_DIR}/temp/empty.cpp")
|
|
#get_filename_component(_dir "${empty_file}" DIRECTORY)
|
|
#file(MAKE_DIRECTORY "${_dir}")
|
|
#file(TOUCH "${empty_file}")
|
|
|
|
|
|
#include("${CMAKE_SOURCE_DIR}/0_cmake_library/ninja_build_analyze/test_ninja_build_analyze.cmake")
|
|
#message("11111111111111")
|
|
#register_ninja_build_analyze_target(
|
|
# NINJA_ANALYZE_RUN_TARGET
|
|
# NINJA_ANALYZE_CLEAR_TARGET
|
|
# ninja_build_analyze_ctx
|
|
# "${CMAKE_SOURCE_DIR}"
|
|
# "${CMAKE_BINARY_DIR}"
|
|
# "Core_exe"
|
|
# "26"
|
|
# "${CMAKE_BINARY_DIR}/build_analysis"
|
|
# "ON"
|
|
# "30"
|
|
#)
|
|
#message("2222222222222") |