From 49ca52ba03d4666fe358606aa9a2c9b97d8f7b83 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Sun, 15 Dec 2019 19:34:18 +0000 Subject: [PATCH] cmake: Visual Studio misc followup on cf9a88df. Fix the vcpkg root setting, which was trying to use CMAKE_PROJECT_DIR before a project is defined by switching back to CMAKE_SOURCE_DIR. Also check if the user has \vcpkg or c:\vcpkg and use those if found. Use \vcpkg if ENV{CI} is set, e.g. on Appveyor. Enable nasm for visual studio builds by using the nuget nasm2 package. In Architecture.cmake check that the vcpkg arch matches the compiler arch, and throw a fatal error otherwise. When using GLOB to find the nuget package directory, use the package name as the prefix, this is quite necessary when using multiple nuget packages. Signed-off-by: Rafael Kitover --- CMakeLists.txt | 16 ++++++++++++++++ cmake/Architecture.cmake | 12 +++++++++--- cmake/Set-Toolchain-vcpkg.cmake | 13 ++++++++++++- src/wx/CMakeLists.txt | 2 +- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1520e311..04a9efc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -275,7 +275,23 @@ if(AMD64 AND (ENABLE_ASM_CORE OR ENABLE_ASM_SCALERS OR ENABLE_MMX)) endif() if(ENABLE_ASM_CORE OR ENABLE_ASM_SCALERS) + if(MSVC) + if(NOT EXISTS ${CMAKE_BINARY_DIR}/nuget.exe) + file(DOWNLOAD "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" ${CMAKE_BINARY_DIR}/nuget.exe) + endif() + + execute_process( + COMMAND nuget.exe install nasm2 -OutputDirectory ${CMAKE_BINARY_DIR}/nuget + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + + file(GLOB pkg ${CMAKE_BINARY_DIR}/nuget/nasm2*) + + list(APPEND CMAKE_PROGRAM_PATH ${pkg}/tools) + endif() + enable_language(ASM_NASM) + set(ASM_ENABLED ON) endif() diff --git a/cmake/Architecture.cmake b/cmake/Architecture.cmake index ca4613f4..3368cac5 100644 --- a/cmake/Architecture.cmake +++ b/cmake/Architecture.cmake @@ -14,13 +14,19 @@ endif() # and set WINARCH for windows stuff if(CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86|i[3-9]86|[aA][mM][dD]64") if(CMAKE_C_SIZEOF_DATA_PTR EQUAL 4) # 32 bit - if(NOT (MSVC AND CMAKE_TOOLCHAIN_FILE MATCHES vcpkg)) - set(ASM_DEFAULT ON) - endif() + set(ASM_DEFAULT ON) set(X86_32 ON) set(WINARCH x86) + + if(DEFINED VCPKG_TARGET_TRIPLET AND (NOT VCPKG_TARGET_TRIPLET MATCHES "^x86-")) + message(FATAL_ERROR "ERROR: Wrong build environment architecture for VCPKG_TARGET_TRIPLET") + endif() else() set(AMD64 ON) set(WINARCH x64) + + if(DEFINED VCPKG_TARGET_TRIPLET AND (NOT VCPKG_TARGET_TRIPLET MATCHES "^x64-")) + message(FATAL_ERROR "ERROR: Wrong build environment architecture for VCPKG_TARGET_TRIPLET") + endif() endif() endif() diff --git a/cmake/Set-Toolchain-vcpkg.cmake b/cmake/Set-Toolchain-vcpkg.cmake index c62d3bd0..858d8b6d 100644 --- a/cmake/Set-Toolchain-vcpkg.cmake +++ b/cmake/Set-Toolchain-vcpkg.cmake @@ -6,7 +6,18 @@ endmacro() if(VCPKG_TARGET_TRIPLET) if(NOT DEFINED ENV{VCPKG_ROOT}) - get_filename_component(VCPKG_ROOT ${CMAKE_PROJECT_DIR}/../vcpkg ABSOLUTE) + if(WIN32) + if(DEFINED ENV{CI} OR EXISTS /vcpkg) + set(VCPKG_ROOT /vcpkg) + elseif(EXISTS c:/vcpkg) + set(VCPKG_ROOT c:/vcpkg) + endif() + endif() + + if(NOT DEFINED VCPKG_ROOT) + get_filename_component(VCPKG_ROOT ${CMAKE_SOURCE_DIR}/../vcpkg ABSOLUTE) + endif() + set(ENV{VCPKG_ROOT} ${VCPKG_ROOT}) else() set(VCPKG_ROOT $ENV{VCPKG_ROOT}) diff --git a/src/wx/CMakeLists.txt b/src/wx/CMakeLists.txt index a3c9ff9f..72e1d092 100644 --- a/src/wx/CMakeLists.txt +++ b/src/wx/CMakeLists.txt @@ -544,7 +544,7 @@ if(CMAKE_TOOLCHAIN_FILE MATCHES vcpkg) ) # find the path to the binaries in the package and add them to find path - file(GLOB pkg ${CMAKE_BINARY_DIR}/nuget/*) + file(GLOB pkg ${CMAKE_BINARY_DIR}/nuget/Gettext.Tools*) list(APPEND CMAKE_PROGRAM_PATH ${pkg}/tools/bin)