Skip to content

Commit

Permalink
chore: update CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
horror-proton committed May 21, 2024
1 parent 8904bc1 commit 561b601
Showing 1 changed file with 61 additions and 28 deletions.
89 changes: 61 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ option(BUILD_UNIVERSAL "build both arm64 and x86_64 on macOS" OFF)
option(INSTALL_PYTHON "install python ffi" OFF)
option(INSTALL_RESOURCE "install resource" OFF)
option(INSTALL_DEVEL "install development files" OFF)
option(INSTALL_FLATTEN "do not use bin lib include directory" ON)
option(INSTALL_THIRD_LIBS "install third party libraries" ON)
option(USE_MAADEPS "use third-party libraries built by MaaDeps" ON)
option(WITH_EMULATOR_EXTRAS "build with emulator extras" ON)
option(WITH_THRIFT "build with thrift" OFF)

include(${PROJECT_SOURCE_DIR}/cmake/utils.cmake)
Expand All @@ -24,29 +26,28 @@ if(USE_MAADEPS)
include(${PROJECT_SOURCE_DIR}/MaaDeps/maadeps.cmake)
endif()

add_library(header_only_libraries INTERFACE)
target_include_directories(header_only_libraries INTERFACE 3rdparty/include 3rdparty/EmulatorExtras)

file(GLOB_RECURSE maa_src src/MaaCore/*.cpp)

add_library(MaaCore SHARED ${maa_src})

if (MSVC)
add_compile_options("/utf-8")
add_compile_options("/MP")
add_compile_options("/W4;/WX")
add_compile_options("/wd4127") # conditional expression is constant
add_compile_options("/Wv:19.35.32217") # disable warning introduced after this version
target_compile_options(MaaCore PRIVATE "/utf-8")
target_compile_options(MaaCore PRIVATE "/MP")
target_compile_options(MaaCore PRIVATE "/W4;/WX")
target_compile_options(MaaCore PRIVATE "/wd4127") # conditional expression is constant
target_compile_options(MaaCore PRIVATE "/Wv:19.35.32217") # disable warning introduced after this version

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
else ()
add_compile_options("-Wall;-Werror;-Wextra;-Wpedantic;-Wno-missing-field-initializers")
target_compile_options(MaaCore PRIVATE "-Wall;-Werror;-Wextra;-Wpedantic;-Wno-missing-field-initializers")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13)
add_compile_options("-Wno-restrict")
target_compile_options(MaaCore PRIVATE "-Wno-restrict")
endif()
endif ()


add_library(header_only_libraries INTERFACE)
target_include_directories(header_only_libraries INTERFACE 3rdparty/include 3rdparty/EmulatorExtras)

file(GLOB_RECURSE maa_src src/MaaCore/*.cpp)

add_library(MaaCore SHARED ${maa_src})

if (WIN32)
#注意:相比VS版本缺少了 -D_CONSOLE -D_WINDLL 两项
target_compile_definitions(MaaCore PRIVATE ASST_DLL_EXPORTS _UNICODE UNICODE)
Expand Down Expand Up @@ -77,17 +78,50 @@ endif (BUILD_TEST)

find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs videoio)
find_package(ZLIB REQUIRED)
find_package(MaaDerpLearning REQUIRED)
find_package(asio REQUIRED)
find_package(ONNXRuntime)
find_package(cpr CONFIG REQUIRED)
if(WITH_THRIFT)
find_package(Thrift CONFIG REQUIRED)
endif(WITH_THRIFT)

target_link_libraries(MaaCore ${OpenCV_LIBS} MaaDerpLearning asio::asio ZLIB::ZLIB ONNXRuntime::ONNXRuntime cpr::cpr header_only_libraries)
if (USE_MAADEPS)
find_package(MaaDerpLearning REQUIRED)
elseif(DEFINED MaaDerpLearning_SOURCE_DIR) # TODO: FetchContent
if (NOT DEFINED MaaDerpLearning_BINARY_DIR)
set(MaaDerpLearning_BINARY_DIR ${CMAKE_BINARY_DIR}/MaaDerpLearning)
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_subdirectory(${MaaDerpLearning_SOURCE_DIR} ${MaaDerpLearning_BINARY_DIR} EXCLUDE_FROM_ALL SYSTEM)
if (NOT DEFINED MaaDerpLearning_INCLUDE_DIRS)
set(MaaDerpLearning_INCLUDE_DIRS ${MaaDerpLearning_SOURCE_DIR})
endif()
get_target_property(MaaDerpLearning_type MaaDerpLearning TYPE)
if (MaaDerpLearning_type STREQUAL "SHARED_LIBRARY")
install(TARGETS MaaDerpLearning)
endif()
else()
find_package(MaaDerpLearning REQUIRED)
# TODO: INSTALL_THIRD_LIBS
endif()

list(APPEND maa_libs ${OpenCV_LIBS} MaaDerpLearning ZLIB::ZLIB cpr::cpr header_only_libraries)

if (USE_MAADEPS)
find_package(ONNXRuntime REQUIRED)
find_package(asio REQUIRED)
list(APPEND maa_libs ONNXRuntime::ONNXRuntime asio::asio)
else()
find_package(onnxruntime REQUIRED) # provided by onnxruntime>=1.16
list(APPEND maa_libs onnxruntime::onnxruntime)
target_include_directories(MaaCore SYSTEM PRIVATE ${MaaDerpLearning_INCLUDE_DIRS})
endif()

target_link_libraries(MaaCore ${maa_libs})

if(WITH_EMULATOR_EXTRAS AND NOT EXISTS ${PROJECT_SOURCE_DIR}/3rdparty/EmulatorExtras/Mumu)
message(WARNING "EmulatorExtras not found, please run `git submodule update --init 3rdparty/EmulatorExtras`")
set(WITH_EMULATOR_EXTRAS OFF)
endif()
target_compile_definitions(MaaCore PRIVATE ASST_WITH_EMULATOR_EXTRAS=$<BOOL:${WITH_EMULATOR_EXTRAS}>)

if(WITH_THRIFT)
find_package(Thrift CONFIG REQUIRED)
add_subdirectory(src/MaaThriftController)
target_link_libraries(MaaCore MaaThriftController)
endif(WITH_THRIFT)
Expand All @@ -105,12 +139,11 @@ if(INSTALL_DEVEL)
set(MaaCore_install_extra_args PUBLIC_HEADER DESTINATION devel/include ARCHIVE DESTINATION devel/lib)
endif()

install(TARGETS MaaCore
RUNTIME DESTINATION .
LIBRARY DESTINATION .
PUBLIC_HEADER DESTINATION .
${MaaCore_install_extra_args}
)
if(INSTALL_FLATTEN)
set(MaaCore_install_flatten_args RUNTIME DESTINATION . LIBRARY DESTINATION . PUBLIC_HEADER DESTINATION .)
endif()

install(TARGETS MaaCore ${MaaCore_install_flatten_args} ${MaaCore_install_extra_args})

if(INSTALL_THIRD_LIBS AND USE_MAADEPS)
maadeps_install()
Expand Down

0 comments on commit 561b601

Please sign in to comment.