1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

[conan] add MSVC support

also removes all mentions of vcpkg and cross-building from Linux
This commit is contained in:
Andrey Filipenkov
2025-03-07 11:36:08 +03:00
parent 951be24f5e
commit a3f08c2217
11 changed files with 53 additions and 123 deletions

View File

@@ -19,10 +19,6 @@ else()
set(fuzzylite_FOUND FALSE) set(fuzzylite_FOUND FALSE)
endif() endif()
if(TARGET fuzzylite::fuzzylite AND MSVC)
install_vcpkg_imported_tgt(fuzzylite::fuzzylite)
endif()
if(NOT fuzzylite_FOUND) if(NOT fuzzylite_FOUND)
set(FL_BUILD_BINARY OFF CACHE BOOL "") set(FL_BUILD_BINARY OFF CACHE BOOL "")
set(FL_BUILD_SHARED OFF CACHE BOOL "") set(FL_BUILD_SHARED OFF CACHE BOOL "")

21
CI/conan/base/msvc Normal file
View File

@@ -0,0 +1,21 @@
include(common)
[settings]
compiler=msvc
compiler.cppstd=17
compiler.runtime=dynamic
compiler.version=194
os=Windows
[conf]
# https://walbourn.github.io/a-brief-history-of-windows-sdks/
# https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt
# https://learn.microsoft.com/en-us/windows/win32/WinProg/using-the-windows-headers
{% set _WIN32_WINNT_WIN7 = '0x0601' %}
{% set NTDDI_WIN7 = '0x06010000' %}
{% set win7_defines = [
'_WIN32_WINNT={}'.format(_WIN32_WINNT_WIN7),
'WINVER={}'.format(_WIN32_WINNT_WIN7),
'NTDDI_VERSION={}'.format(NTDDI_WIN7),
] %}
tools.build:defines={{ win7_defines }}

4
CI/conan/msvc-x64 Normal file
View File

@@ -0,0 +1,4 @@
include(base/msvc)
[settings]
arch=x86_64

4
CI/conan/msvc-x86 Normal file
View File

@@ -0,0 +1,4 @@
include(base/msvc)
[settings]
arch=x86

View File

@@ -310,7 +310,7 @@ endif()
if(MINGW OR MSVC) if(MINGW OR MSVC)
# Windows Vista or newer for FuzzyLite 6 to compile # Windows Vista or newer for FuzzyLite 6 to compile
# Except for conan which already has this definition in its preset # Except for conan which already has this definition in its profile
if(NOT USING_CONAN) if(NOT USING_CONAN)
add_definitions(-D_WIN32_WINNT=0x0600) add_definitions(-D_WIN32_WINNT=0x0600)
endif() endif()
@@ -373,14 +373,9 @@ if(MINGW OR MSVC)
# Reported to Microsoft here: # Reported to Microsoft here:
# https://developercommunity.visualstudio.com/content/problem/224597/linker-failing-because-of-multiple-definitions-of.html # https://developercommunity.visualstudio.com/content/problem/224597/linker-failing-because-of-multiple-definitions-of.html
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /FORCE:MULTIPLE") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /FORCE:MULTIPLE")
# Required at least for compatibility with Boost 1.68 on Vcpkg
# psapi required for ARM64 builds
set(SYSTEM_LIBS ${SYSTEM_LIBS} bcrypt psapi)
endif(MSVC) endif(MSVC)
if(MINGW) if(MINGW)
# Temporary (?) workaround for failing builds on MinGW CI due to bug in TBB # Temporary (?) workaround for failing builds on MinGW CI due to bug in TBB
set(CMAKE_CXX_EXTENSIONS ON) set(CMAKE_CXX_EXTENSIONS ON)
@@ -779,59 +774,6 @@ if(NOT WIN32 AND NOT APPLE_IOS AND NOT ANDROID)
WORLD_READ WORLD_EXECUTE) WORLD_READ WORLD_EXECUTE)
endif() endif()
if(WIN32)
if(TBB_FOUND AND MSVC)
install_vcpkg_imported_tgt(TBB::tbb)
endif()
if(USING_CONAN)
#Conan imports enabled
vcmi_install_conan_deps("\${CMAKE_INSTALL_PREFIX}")
file(GLOB dep_files
${dep_files}
"${CMAKE_SYSROOT}/bin/*.dll"
"${CMAKE_SYSROOT}/lib/*.dll"
"${CONAN_SYSTEM_LIBRARY_LOCATION}/libgcc_s_dw2-1.dll" # for 32-bit only?
"${CONAN_SYSTEM_LIBRARY_LOCATION}/libgcc_s_seh-1.dll" # for 64-bit only?
"${CONAN_SYSTEM_LIBRARY_LOCATION}/libstdc++-6.dll")
else()
file(GLOB dep_files
${dep_files}
"${CMAKE_FIND_ROOT_PATH}/bin/*.dll")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# Copy debug versions of libraries if build type is debug
set(debug_postfix d)
endif()
if(ENABLE_LAUNCHER OR ENABLE_EDITOR)
get_target_property(QtCore_location Qt${QT_VERSION_MAJOR}::Core LOCATION)
get_filename_component(Qtbin_folder ${QtCore_location} PATH)
file(GLOB dep_files
${dep_files}
${Qtbin_folder}/Qt5Core${debug_postfix}.dll
${Qtbin_folder}/Qt5Gui${debug_postfix}.dll
${Qtbin_folder}/Qt5Widgets${debug_postfix}.dll
${Qtbin_folder}/Qt5Network${debug_postfix}.dll
${Qtbin_folder}/icu*.dll)
get_target_property(integration_type Qt${QT_VERSION_MAJOR}::QWindowsIntegrationPlugin TYPE)
if(NOT(integration_type STREQUAL "INTERFACE_LIBRARY"))
get_target_property(integration_loc Qt${QT_VERSION_MAJOR}::QWindowsIntegrationPlugin LOCATION)
install(
FILES ${integration_loc}
DESTINATION ${BIN_DIR}/platforms
)
install(
FILES "$<TARGET_FILE:Qt${QT_VERSION_MAJOR}::QWindowsVistaStylePlugin>"
DESTINATION ${BIN_DIR}/styles)
endif()
endif()
install(FILES ${dep_files} DESTINATION ${BIN_DIR})
endif(WIN32)
####################################### #######################################
# Packaging section # # Packaging section #
####################################### #######################################

View File

@@ -30,6 +30,7 @@ if(ANDROID)
) )
else() else()
add_executable(vcmiclient ${clientapp_SRCS} ${clientapp_HEADERS}) add_executable(vcmiclient ${clientapp_SRCS} ${clientapp_HEADERS})
vcmi_create_exe_shim(vcmiclient)
endif() endif()
target_link_libraries(vcmiclient PRIVATE vcmiclientcommon) target_link_libraries(vcmiclient PRIVATE vcmiclientcommon)
@@ -55,15 +56,6 @@ if(WIN32)
target_link_libraries(vcmiclient SDL2::SDL2main) target_link_libraries(vcmiclient SDL2::SDL2main)
endif() endif()
target_compile_definitions(vcmiclient PRIVATE WINDOWS_IGNORE_PACKING_MISMATCH) target_compile_definitions(vcmiclient PRIVATE WINDOWS_IGNORE_PACKING_MISMATCH)
# TODO: very hacky, find proper solution to copy AI dlls into bin dir
if(MSVC)
add_custom_command(TARGET vcmiclient POST_BUILD
WORKING_DIRECTORY "$<TARGET_FILE_DIR:vcmiclient>"
COMMAND ${CMAKE_COMMAND} -E copy AI/fuzzylite.dll fuzzylite.dll
COMMAND ${CMAKE_COMMAND} -E copy AI/tbb12.dll tbb12.dll
)
endif()
elseif(APPLE_IOS) elseif(APPLE_IOS)
set_target_properties(vcmiclient PROPERTIES set_target_properties(vcmiclient PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/ios/Info.plist" MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_LIST_DIR}/ios/Info.plist"

View File

@@ -118,16 +118,6 @@ function(vcmi_print_git_commit_hash)
endfunction() endfunction()
#install imported target on windows
function(install_vcpkg_imported_tgt tgt)
get_target_property(TGT_LIB_LOCATION ${tgt} LOCATION)
get_filename_component(TGT_LIB_FOLDER ${TGT_LIB_LOCATION} PATH)
get_filename_component(tgt_name ${TGT_LIB_LOCATION} NAME_WE)
get_filename_component(TGT_DLL ${TGT_LIB_FOLDER}/../bin/${tgt_name}.dll ABSOLUTE)
message("${tgt_name}: ${TGT_DLL}")
install(FILES ${TGT_DLL} DESTINATION ${BIN_DIR})
endfunction(install_vcpkg_imported_tgt)
# install dependencies from Conan, CONAN_RUNTIME_LIBS_FILE is set in conanfile.py # install dependencies from Conan, CONAN_RUNTIME_LIBS_FILE is set in conanfile.py
function(vcmi_install_conan_deps) function(vcmi_install_conan_deps)
if(NOT USING_CONAN) if(NOT USING_CONAN)
@@ -149,3 +139,14 @@ function(vcmi_deploy_qt deployQtToolName deployQtOptions)
message(WARNING "${deployQtToolName} not found, running cpack would result in broken package") message(WARNING "${deployQtToolName} not found, running cpack would result in broken package")
endif() endif()
endfunction() endfunction()
# generate .bat for .exe with proper PATH
function(vcmi_create_exe_shim tgt)
if(NOT CONAN_RUNENV_SCRIPT)
return()
endif()
file(GENERATE OUTPUT "$<TARGET_FILE_DIR:${tgt}>/$<TARGET_FILE_BASE_NAME:${tgt}>.bat" CONTENT
"call ${CONAN_RUNENV_SCRIPT}
@start $<TARGET_FILE_NAME:${tgt}>"
)
endfunction()

View File

@@ -155,6 +155,7 @@ if(ENABLE_SINGLE_APP_BUILD OR ANDROID)
add_library(vcmilauncher OBJECT ${launcher_QM}) add_library(vcmilauncher OBJECT ${launcher_QM})
else() else()
add_executable(vcmilauncher WIN32 ${launcher_QM} ${launcher_ICON}) add_executable(vcmilauncher WIN32 ${launcher_QM} ${launcher_ICON})
vcmi_create_exe_shim(vcmilauncher)
endif() endif()
if(ENABLE_TRANSLATIONS) if(ENABLE_TRANSLATIONS)

View File

@@ -258,6 +258,7 @@ if(ENABLE_SINGLE_APP_BUILD OR ANDROID)
add_library(vcmieditor OBJECT ${editor_QM}) add_library(vcmieditor OBJECT ${editor_QM})
else() else()
add_executable(vcmieditor WIN32 ${editor_QM} ${editor_SRCS} ${editor_HEADERS} ${editor_UI_HEADERS} ${editor_ICON}) add_executable(vcmieditor WIN32 ${editor_QM} ${editor_SRCS} ${editor_HEADERS} ${editor_UI_HEADERS} ${editor_ICON})
vcmi_create_exe_shim(vcmieditor)
endif() endif()
if(ENABLE_TRANSLATIONS) if(ENABLE_TRANSLATIONS)

View File

@@ -9,6 +9,7 @@ set(serverapp_HEADERS
assign_source_group(${serverapp_SRCS} ${serverapp_HEADERS}) assign_source_group(${serverapp_SRCS} ${serverapp_HEADERS})
add_executable(vcmiserver ${serverapp_SRCS} ${serverapp_HEADERS}) add_executable(vcmiserver ${serverapp_SRCS} ${serverapp_HEADERS})
vcmi_create_exe_shim(vcmiserver)
set(serverapp_LIBS vcmi) set(serverapp_LIBS vcmi)
if(CMAKE_SYSTEM_NAME MATCHES FreeBSD OR HAIKU) if(CMAKE_SYSTEM_NAME MATCHES FreeBSD OR HAIKU)

View File

@@ -1,43 +1,10 @@
# We need to keep this code into separate directory so CMake will execute it after all other subdirectories install code # We need to keep this code into separate directory so CMake will execute it after all other subdirectories install code
# Otherwise we can't fix win bundle dependencies since binaries wouldn't be there when this code executed if(WIN32 AND (ENABLE_LAUNCHER OR ENABLE_EDITOR))
# This will likely only work for Vcpkg if(TARGET vcmilauncher)
if(WIN32) set(deployTarget vcmilauncher)
#there are some weird issues with variables used in path not evaluated properly when trying to remove code duplication from below lines elseif(TARGET vcmieditor)
set(deployTarget vcmieditor)
if(ENABLE_LAUNCHER)
install(CODE "
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/qt.conf\"
\"[Paths]\nPlugins = .\"
)
")
endif() endif()
set(targetBinary "\"\${CMAKE_INSTALL_PREFIX}/${BIN_DIR}/$<TARGET_FILE_NAME:${deployTarget}>\"")
vcmi_deploy_qt(windeployqt "--no-compiler-runtime ${targetBinary}")
#TODO: check if some equivalent of block below can be used for above block (easy qt dependencies copy) endif()
#LuaJIT will not be copied automatically by not meeting criteria for this block of code
if(ENABLE_LUA)
install_vcpkg_imported_tgt(luajit::luajit)
endif()
if(MSVC)
set(gp_tool "dumpbin")
endif()
install(CODE "
set(dirs \"${CMAKE_PREFIX_PATH}\")
if(\"\${CMAKE_INSTALL_CONFIG_NAME}\" STREQUAL \"Debug\")
list(TRANSFORM dirs APPEND \"/debug/bin\")
else()
list(TRANSFORM dirs APPEND \"/bin\")
list(FILTER dirs EXCLUDE REGEX \".*debug.*\")
endif()
set(BU_CHMOD_BUNDLE_ITEMS ON)
set(gp_tool \"${gp_tool}\")
include(BundleUtilities)
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/VCMI_Client.exe\" \"\" \"\${dirs}\")
" COMPONENT Runtime)
endif(WIN32)