rework handling of libraries installed via vcpkg and fix linker issues

This commit is contained in:
ohyzha
2024-07-31 12:50:17 +03:00
parent 656d6f1371
commit 0373039386

View File

@@ -18,7 +18,7 @@ if(NOT DEFINED VCPKG_REPO)
set(VCPKG_REPO https://github.com/microsoft/vcpkg.git) set(VCPKG_REPO https://github.com/microsoft/vcpkg.git)
endif() endif()
set(VCPKG_SRC_DIR "${CMAKE_BINARY_DIR}/_deps/vcpkg-src") set(VCPKG_SRC_DIR "${CMAKE_BINARY_DIR}/_deps/vcpkg-src" CACHE INTERNAL "vcpkg source dir")
if (NOT EXISTS ${VCPKG_SRC_DIR} OR VCPKG_EXECUTABLE STREQUAL "" OR NOT DEFINED VCPKG_EXECUTABLE) if (NOT EXISTS ${VCPKG_SRC_DIR} OR VCPKG_EXECUTABLE STREQUAL "" OR NOT DEFINED VCPKG_EXECUTABLE)
message("Cloning vcpkg...") message("Cloning vcpkg...")
FetchContent_Declare( FetchContent_Declare(
@@ -38,37 +38,28 @@ if (NOT EXISTS ${VCPKG_SRC_DIR} OR VCPKG_EXECUTABLE STREQUAL "" OR NOT DEFINED V
endif() endif()
endif() endif()
# custom triplets (looks like doesn't work)
#if (WIN32)
# set(VCPKG_TARGET_TRIPLET "${CMAKE_SOURCE_DIR}/cmake/x64-windows-static-triplet" CACHE STRING "VCPKG Target Triplet to use")
#elseif(UNIX)
# set(VCPKG_TARGET_TRIPLET "${CMAKE_SOURCE_DIR}/cmake/x64-linux-triplet" CACHE STRING "VCPKG Target Triplet to use")
#endif()
if (WIN32) if (WIN32)
# static win build breaks find_library call. need to specify FREETYPE_LIBRARY and FREETYPE_INCLUDE_DIRS manually. set(TRIPLET x64-windows-static-md-release CACHE INTERNAL "triplet")
# plain x64-windows will link freetype as dll instead of lib .......
set(TRIPLET x64-windows-static)
elseif(UNIX) elseif(UNIX)
set(TRIPLET x64-linux) set(TRIPLET x64-linux CACHE INTERNAL "triplet")
elseif(APPLE) elseif(APPLE)
set(TRIPLET x64-osx) set(TRIPLET x64-osx CACHE INTERNAL "triplet")
else() else()
message(FATAL_ERROR "Unknown OS, can't build msdfgen") message(FATAL_ERROR "Unknown OS, can't build msdfgen")
endif() endif()
execute_process(COMMAND ${VCPKG_EXECUTABLE} install freetype:${TRIPLET}) execute_process(COMMAND ${VCPKG_EXECUTABLE} install freetype:${TRIPLET} libpng:${TRIPLET})
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_BINARY_DIR}/_deps/vcpkg-src/scripts/buildsystems/vcpkg.cmake" CACHE STRING "cmake toolchain") set(CMAKE_TOOLCHAIN_FILE "${CMAKE_BINARY_DIR}/_deps/vcpkg-src/scripts/buildsystems/vcpkg.cmake" CACHE STRING "cmake toolchain")
include("${VCPKG_SRC_DIR}/scripts/buildsystems/vcpkg.cmake") include("${VCPKG_SRC_DIR}/scripts/buildsystems/vcpkg.cmake")
list(APPEND CMAKE_PREFIX_PATH "${VCPKG_SRC_DIR}/installed/${TRIPLET}/lib")
if(WIN32) list(APPEND CMAKE_PREFIX_PATH "${VCPKG_SRC_DIR}/installed/${TRIPLET}/include")
set(FREETYPE_LIBRARY "${VCPKG_SRC_DIR}/buildtrees/freetype/${TRIPLET}-rel/freetype.lib" CACHE STRING "freetype lib path on win")
set(FREETYPE_INCLUDE_DIRS "${VCPKG_SRC_DIR}/packages/freetype_${TRIPLET}/include" CACHE STRING "freetype include path on win")
endif()
set(MSDFGEN_DISABLE_SVG TRUE CACHE INTERNAL "disable msdfgen svg") set(MSDFGEN_DISABLE_SVG TRUE CACHE INTERNAL "disable msdfgen svg")
set(MSDFGEN_DISABLE_PNG TRUE CACHE INTERNAL "disable msdfgen png")
set(MSDFGEN_USE_SKIA OFF CACHE BOOL "use skia" FORCE) set(MSDFGEN_USE_SKIA OFF CACHE BOOL "use skia" FORCE)
set(MSDF_ATLAS_USE_SKIA OFF CACHE BOOL "use skia" FORCE)
set(MSDF_ATLAS_MSDFGEN_EXTERNAL ON CACHE BOOL "do not build msdfgen submodule" FORCE)
set(MSDFGEN_DYNAMIC_RUNTIME ON CACHE BOOL "msvc dynamic runtime" FORCE)
set(MSDF_ATLAS_DYNAMIC_RUNTIME ON CACHE BOOL "msvc dynamic runtime" FORCE)
FetchContent_Declare( FetchContent_Declare(
msdfgen msdfgen
@@ -79,11 +70,6 @@ FetchContent_Declare(
) )
FetchContent_MakeAvailable(msdfgen) FetchContent_MakeAvailable(msdfgen)
set(MSDFGEN_DISABLE_SVG TRUE CACHE INTERNAL "disable msdfgen svg")
set(MSDFGEN_DISABLE_PNG TRUE CACHE INTERNAL "disable msdfgen png")
set(MSDF_ATLAS_USE_SKIA OFF CACHE BOOL "use skia" FORCE)
set(MSDF_ATLAS_MSDFGEN_EXTERNAL ON CACHE BOOL "do not build msdfgen submodule" FORCE)
FetchContent_Declare( FetchContent_Declare(
msdfgen_atlas msdfgen_atlas
EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL
@@ -92,3 +78,16 @@ FetchContent_Declare(
GIT_SHALLOW TRUE GIT_SHALLOW TRUE
) )
FetchContent_MakeAvailable(msdfgen_atlas) FetchContent_MakeAvailable(msdfgen_atlas)
function(LinkMsdf TARGET)
if(WIN32)
set(STATIC_LIB_EXT "lib")
else()
set(STATIC_LIB_EXT "a")
endif()
file(GLOB installed_libs "${VCPKG_SRC_DIR}/installed/${TRIPLET}/lib/*.${STATIC_LIB_EXT}")
foreach(lib ${installed_libs})
target_link_libraries(${TARGET} PUBLIC ${lib})
endforeach()
endfunction()