Skip to content

Commit

Permalink
internal: optimize CMake calls to find_package (#1952)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove authored May 8, 2024
1 parent 4869870 commit ecdffa6
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 106 deletions.
64 changes: 0 additions & 64 deletions cmake/link_vcpkg_dependencies.cmake

This file was deleted.

Empty file removed cmake/modules/dummy.txt
Empty file.
6 changes: 4 additions & 2 deletions libespm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
project(libespm)
include(${CMAKE_SOURCE_DIR}/cmake/apply_default_settings.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/link_vcpkg_dependencies.cmake)

file(GLOB ESPM_SRC "include/*.h" "src/*.cpp" "src/*.h")
add_library(espm STATIC ${ESPM_SRC})
target_include_directories(espm PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
target_include_directories(espm PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src)

apply_default_settings(TARGETS espm)
link_vcpkg_dependencies(TARGETS espm)

add_library(libespm ALIAS espm)

find_path(SPARSEPP_INCLUDE_DIR NAMES spp.h PATH_SUFFIXES sparsepp)
get_filename_component(SPARSEPP_INCLUDE_DIR ${SPARSEPP_INCLUDE_DIR} DIRECTORY)
target_include_directories(espm PUBLIC ${SPARSEPP_INCLUDE_DIR})
6 changes: 3 additions & 3 deletions papyrus-vm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
project(papyrus-vm VERSION 1.0.0)
include(${CMAKE_SOURCE_DIR}/cmake/apply_default_settings.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/link_vcpkg_dependencies.cmake)

file(GLOB src "${CMAKE_CURRENT_SOURCE_DIR}/src/papyrus-vm-lib/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/src/papyrus-vm-lib/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
list(APPEND src "${CMAKE_SOURCE_DIR}/.clang-format")
Expand All @@ -10,11 +9,12 @@ target_include_directories(papyrus-vm-lib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/in
target_include_directories(papyrus-vm-lib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")

target_link_libraries(papyrus-vm-lib PUBLIC viet)
link_vcpkg_dependencies(TARGETS papyrus-vm-lib)

find_package(spdlog CONFIG REQUIRED)
target_link_libraries(papyrus-vm-lib PUBLIC spdlog::spdlog)

file(GLOB src "${CMAKE_CURRENT_SOURCE_DIR}/src/papyrus-vm/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/src/papyrus-vm/*.cpp")
add_executable(papyrus-vm ${src})
target_link_libraries(papyrus-vm PUBLIC papyrus-vm-lib)
apply_default_settings(TARGETS papyrus-vm)
link_vcpkg_dependencies(TARGETS papyrus-vm)
add_custom_command(TARGET papyrus-vm POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:papyrus-vm> "${CMAKE_BINARY_DIR}/dist/papyrus-vm/$<TARGET_FILE_NAME:papyrus-vm>")
5 changes: 3 additions & 2 deletions savefile/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
project(savefile)
include(${CMAKE_SOURCE_DIR}/cmake/apply_default_settings.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/link_vcpkg_dependencies.cmake)

file(GLOB_RECURSE savefile_src "${CMAKE_CURRENT_LIST_DIR}/src/*.cpp" "${CMAKE_CURRENT_LIST_DIR}/src/*.h" "${CMAKE_CURRENT_LIST_DIR}/include/*.h")

Expand All @@ -10,4 +9,6 @@ add_library(savefile STATIC ${savefile_src})
target_include_directories(savefile PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src)
target_include_directories(savefile PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
apply_default_settings(TARGETS savefile)
link_vcpkg_dependencies(TARGETS savefile)

find_package(ZLIB REQUIRED)
target_link_libraries(savefile PUBLIC ZLIB::ZLIB)
5 changes: 3 additions & 2 deletions skymp5-downloader/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
project(skymp5-downloader)

if(WIN32)
include(${CMAKE_SOURCE_DIR}/cmake/link_vcpkg_dependencies.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/apply_default_settings.cmake)

# Define source files
Expand All @@ -14,10 +13,12 @@ if(WIN32)
add_executable(${PROJECT_NAME} WIN32 ${sources})
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\"")

link_vcpkg_dependencies(TARGETS ${PROJECT_NAME})
apply_default_settings(TARGETS ${PROJECT_NAME})

target_link_libraries(${PROJECT_NAME} PRIVATE ComCtl32)

find_path(HTTPLIB_INCLUDE_DIR NAMES httplib.h PATH_SUFFIXES include)
target_include_directories(${PROJECT_NAME} PUBLIC ${HTTPLIB_INCLUDE_DIR})
else()
add_custom_target(${PROJECT_NAME} ALL SOURCES ${sources}
COMMAND ${CMAKE_COMMAND} -E echo "Building ${PROJECT_NAME} is disabled on non-Windows setups."
Expand Down
45 changes: 24 additions & 21 deletions skymp5-server/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,38 +87,41 @@ target_include_directories(localization-provider PUBLIC "${CMAKE_CURRENT_SOURCE_
# Link vcpkg deps
#

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
find_path(CATCH_INCLUDE_DIR NAMES catch.hpp PATH_SUFFIXES catch2)
get_filename_component(CATCH_INCLUDE_DIR ${CATCH_INCLUDE_DIR} DIRECTORY)

find_path(SPARSEPP_INCLUDE_DIR NAMES spp.h PATH_SUFFIXES sparsepp)
get_filename_component(SPARSEPP_INCLUDE_DIR ${SPARSEPP_INCLUDE_DIR} DIRECTORY)

find_path(JSON_INCLUDE_DIR NAMES json.hpp PATH_SUFFIXES nlohmann)
get_filename_component(JSON_INCLUDE_DIR ${JSON_INCLUDE_DIR} DIRECTORY)

find_package(spdlog CONFIG REQUIRED)

find_package(simdjson CONFIG REQUIRED)

find_package(slikenet CONFIG REQUIRED)

find_package(ZLIB REQUIRED)

find_package(mongocxx REQUIRED)
find_package(mongoc-1.0 CONFIG REQUIRED)

find_package(OpenSSL REQUIRED)

find_package(bsa CONFIG REQUIRED)

foreach(target ${VCPKG_DEPENDENT})
find_path(CATCH_INCLUDE_DIR NAMES catch.hpp PATH_SUFFIXES catch2)
get_filename_component(CATCH_INCLUDE_DIR ${CATCH_INCLUDE_DIR} DIRECTORY)
target_include_directories(${target} PUBLIC ${CATCH_INCLUDE_DIR})

find_path(SPARSEPP_INCLUDE_DIR NAMES spp.h PATH_SUFFIXES sparsepp)
get_filename_component(SPARSEPP_INCLUDE_DIR ${SPARSEPP_INCLUDE_DIR} DIRECTORY)
target_include_directories(${target} PUBLIC ${SPARSEPP_INCLUDE_DIR})

find_path(JSON_INCLUDE_DIR NAMES json.hpp PATH_SUFFIXES nlohmann)
get_filename_component(JSON_INCLUDE_DIR ${JSON_INCLUDE_DIR} DIRECTORY)
target_include_directories(${target} PUBLIC ${JSON_INCLUDE_DIR})

find_package(spdlog CONFIG REQUIRED)
target_link_libraries(${target} PUBLIC spdlog::spdlog)

find_package(simdjson CONFIG REQUIRED)
target_link_libraries(${target} PUBLIC simdjson::simdjson)

find_package(slikenet CONFIG REQUIRED)
target_link_libraries(${target} PUBLIC SLikeNet)

find_package(ZLIB REQUIRED)
target_link_libraries(${target} PUBLIC ZLIB::ZLIB)

find_package(mongocxx REQUIRED)
find_package(mongoc-1.0 CONFIG REQUIRED)
target_link_libraries(${target} PUBLIC mongo::mongocxx_static mongo::bsoncxx_static mongo::mongoc_static mongo::bson_static)
find_package(OpenSSL REQUIRED)
target_link_libraries(${target} PUBLIC OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(${target} PUBLIC bsa::bsa)

if(UNIX)
target_link_libraries(${target} PUBLIC pthread resolv rt m)
Expand Down
2 changes: 0 additions & 2 deletions skyrim-platform/src/platform_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
if(MSVC)
include(${CMAKE_SOURCE_DIR}/cmake/apply_default_settings.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/link_vcpkg_dependencies.cmake)

file(GLOB_RECURSE sources "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
add_library(platform_lib STATIC ${sources})
Expand All @@ -9,5 +8,4 @@ if(MSVC)
target_include_directories(platform_lib PUBLIC "${CMAKE_SOURCE_DIR}/1js")
target_include_directories(platform_lib PUBLIC "${SKYRIM_PLATFORM_SOURCE_DIR}/src/third_party")
apply_default_settings(TARGETS platform_lib)
link_vcpkg_dependencies(TARGETS platform_lib)
endif()
71 changes: 63 additions & 8 deletions skyrim-platform/src/platform_se/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Version.h.in ${CMAKE_CURRENT_BI
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)

include(${CMAKE_SOURCE_DIR}/cmake/apply_default_settings.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/link_vcpkg_dependencies.cmake)

if(MSVC)
include(${CMAKE_SOURCE_DIR}/cmake/add_papyrus_library_ck.cmake)
Expand All @@ -25,19 +24,16 @@ if(MSVC)
file(GLOB_RECURSE core_library_src "${tilted}/core_library/*")
add_library(core_library STATIC ${core_library_src})
target_include_directories(core_library PUBLIC "${tilted}/core_library")
list(APPEND VCPKG_DEPENDENT core_library)

file(GLOB_RECURSE reverse_src "${tilted}/reverse/*")
add_library(reverse STATIC ${reverse_src})
target_include_directories(reverse PUBLIC "${tilted}/reverse")
target_link_libraries(reverse PUBLIC core_library)
list(APPEND VCPKG_DEPENDENT reverse)

file(GLOB_RECURSE hooks_src "${tilted}/hooks/*")
add_library(hooks STATIC ${hooks_src})
target_include_directories(hooks PUBLIC "${tilted}/hooks")
target_link_libraries(hooks PUBLIC core_library reverse)
list(APPEND VCPKG_DEPENDENT hooks)

file(GLOB_RECURSE ui_src "${tilted}/ui/*")
add_library(ui STATIC ${ui_src})
Expand All @@ -46,7 +42,6 @@ if(MSVC)
target_link_libraries(ui PUBLIC "d3d11.lib" "dxguid.lib")
target_link_libraries(ui PUBLIC skyrim_plugin_resources)
target_link_libraries(ui PUBLIC cef)
list(APPEND VCPKG_DEPENDENT ui)

file(GLOB_RECURSE ui_process_src "${tilted}/ui_process/*")
add_executable(SkyrimPlatformCEF ${ui_process_src})
Expand Down Expand Up @@ -103,7 +98,6 @@ if(NOT "${SKIP_SKYRIM_PLATFORM_BUILDING}")
target_link_options(skyrim_platform PRIVATE "LINKER:-ignore:4099")
target_precompile_headers(skyrim_platform PRIVATE skyrim_platform/PCH.h)
apply_default_settings(TARGETS skyrim_platform)
list(APPEND VCPKG_DEPENDENT skyrim_platform)

file(GLOB_RECURSE platform_entry_src "skyrim_platform_entry/*")
list(APPEND platform_entry_src "${CMAKE_SOURCE_DIR}/.clang-format")
Expand Down Expand Up @@ -154,7 +148,6 @@ if(NOT "${SKIP_SKYRIM_PLATFORM_BUILDING}")
add_executable(TSConverter ${CMAKE_CURRENT_LIST_DIR}/codegen/TSConverter.cpp)
apply_default_settings(TARGETS TSConverter)
set_target_properties(TSConverter PROPERTIES CXX_STANDARD 20)
list(APPEND VCPKG_DEPENDENT TSConverter)

set(CONVERT_FILES_DIR ${CMAKE_CURRENT_LIST_DIR}/codegen/convert-files/)
list(APPEND CODEGEN_ARGS
Expand Down Expand Up @@ -182,4 +175,66 @@ if(MSVC)
)
endif()

link_vcpkg_dependencies(TARGETS ${VCPKG_DEPENDENT})
# TSConverter vcpkg deps

find_path(JSON_INCLUDE_DIR NAMES json.hpp PATH_SUFFIXES nlohmann)
get_filename_component(JSON_INCLUDE_DIR ${JSON_INCLUDE_DIR} DIRECTORY)
target_include_directories(TSConverter PUBLIC ${JSON_INCLUDE_DIR})

if(MSVC)

# interface targets

find_library(MHOOH_LIBRARY_DEBUG mhook)
string(REPLACE "/debug/lib/" "/lib/" MHOOH_LIBRARY_RELEASE ${MHOOH_LIBRARY_DEBUG})
find_path(MHOOK_INCLUDE_DIR NAMES mhook.h PATH_SUFFIXES mhook-lib REQUIRED)
get_filename_component(MHOOK_INCLUDE_DIR ${MHOOK_INCLUDE_DIR} DIRECTORY)
add_library(mhook INTERFACE)
target_link_libraries(mhook INTERFACE "$<IF:$<CONFIG:Debug>,${MHOOH_LIBRARY_DEBUG},${MHOOH_LIBRARY_RELEASE}>")
target_include_directories(mhook INTERFACE ${MHOOK_INCLUDE_DIR})

# ui vcpkg deps

find_package(spdlog CONFIG REQUIRED)
target_link_libraries(ui PUBLIC spdlog::spdlog)

# reverse vcpkg deps

target_link_libraries(core_library PUBLIC mhook)
target_link_libraries(reverse PUBLIC mhook)

# ui vcpkg deps
find_package(directxtk CONFIG REQUIRED)
find_package(directxmath CONFIG REQUIRED)
target_link_libraries(ui PUBLIC Microsoft::DirectXTK)

# skyrim_platform vcpkg deps

find_package(unofficial-chakracore CONFIG REQUIRED)
target_link_libraries(skyrim_platform PUBLIC unofficial::chakracore::chakracore)

target_link_libraries(skyrim_platform PUBLIC mhook)

if(SKYRIM_SE)
find_package(commonlibse REQUIRED CONFIGS CommonLibSSEConfig.cmake)
else()
find_package(commonlibae REQUIRED CONFIGS CommonLibSSEConfig.cmake)
endif()

find_package(robin_hood REQUIRED)

find_path(SIMPLEINI_INCLUDE_DIRS "ConvertUTF.c")
target_include_directories(skyrim_platform PRIVATE ${SIMPLEINI_INCLUDE_DIRS})

target_link_libraries(skyrim_platform PRIVATE CommonLibSSE::CommonLibSSE robin_hood::robin_hood)

find_package(directxtk CONFIG REQUIRED)
find_package(directxmath CONFIG REQUIRED)
target_link_libraries(skyrim_platform PUBLIC Microsoft::DirectXTK)

find_package(spdlog CONFIG REQUIRED)
target_link_libraries(skyrim_platform PUBLIC spdlog::spdlog)

find_package(OpenSSL REQUIRED)
target_link_libraries(skyrim_platform PUBLIC OpenSSL::SSL OpenSSL::Crypto)
endif()
8 changes: 6 additions & 2 deletions viet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
include(${CMAKE_SOURCE_DIR}/cmake/apply_default_settings.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/link_vcpkg_dependencies.cmake)

file(GLOB_RECURSE viet_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/*" "${CMAKE_CURRENT_SOURCE_DIR}/include/*")
add_library(viet STATIC ${viet_sources})
target_include_directories(viet PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_include_directories(viet PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
apply_default_settings(TARGETS viet)
link_vcpkg_dependencies(TARGETS viet)

find_path(MAKEID_INCLUDE_DIR NAMES MakeID.h)
target_include_directories(viet PUBLIC ${MAKEID_INCLUDE_DIR})

find_package(spdlog CONFIG REQUIRED)
target_link_libraries(viet PUBLIC spdlog::spdlog)

0 comments on commit ecdffa6

Please sign in to comment.