From ecda78666d14e5d791567b9b8cb5a588f77bccd7 Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Sat, 17 Dec 2022 17:22:03 -0800 Subject: [PATCH 1/9] Allow ARM64 on Windows --- CMakeLists.txt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bde16bb813..57b65775e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,9 +43,9 @@ option(BuildSPEngine "Whether to create projects for the SP engine (openjk_sp.ex option(BuildSPGame "Whether to create projects for the SP gamecode (jagamex86.dll)" ON) option(BuildSPRdVanilla "Whether to create projects for the SP default renderer (rdsp-vanilla_x86.dll)" ON) -option(BuildJK2SPEngine "Whether to create projects for the jk2 SP engine (openjo_sp.exe)" OFF) -option(BuildJK2SPGame "Whether to create projects for the jk2 sp gamecode mod (jk2gamex86.dll)" OFF) -option(BuildJK2SPRdVanilla "Whether to create projects for the jk2 sp renderer (rdjosp-vanilla_x86.dll)" OFF) +option(BuildJK2SPEngine "Whether to create projects for the jk2 SP engine (openjo_sp.exe)" ON) +option(BuildJK2SPGame "Whether to create projects for the jk2 sp gamecode mod (jk2gamex86.dll)" ON) +option(BuildJK2SPRdVanilla "Whether to create projects for the jk2 sp renderer (rdjosp-vanilla_x86.dll)" ON) option(BuildTests "Whether to build automatic unit tests (requires Boost)" OFF) @@ -103,11 +103,17 @@ list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake/Modules") # and is used in DLL names (jagamex86.dll, jagamex86.dylib, jagamei386.so). if(WIN32) set(X86 ON) - if(CMAKE_SIZEOF_VOID_P MATCHES "8") + if(DEFINED CMAKE_GENERATOR_PLATFORM) + set(Architecture "${CMAKE_GENERATOR_PLATFORM}") + elseif(CMAKE_SIZEOF_VOID_P MATCHES "8") set(Architecture "x86_64") - set(WIN64 TRUE) else() set(Architecture "x86") + endif() + + if(Architecture EQUAL "x86_64") + set(WIN64 TRUE) + elseif(Architecture EQUAL "x86") set(WIN64 FALSE) endif() else() From 9a12a10bcfae98c50376eaeae6b10355a610d8c6 Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Sun, 18 Dec 2022 01:05:21 -0800 Subject: [PATCH 2/9] Make Architecture CACHE INTERNAL --- CMakeLists.txt | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57b65775e6..7c6741cf13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,11 +104,11 @@ list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake/Modules") if(WIN32) set(X86 ON) if(DEFINED CMAKE_GENERATOR_PLATFORM) - set(Architecture "${CMAKE_GENERATOR_PLATFORM}") + set(Architecture "${CMAKE_GENERATOR_PLATFORM}" CACHE INTERNAL "") elseif(CMAKE_SIZEOF_VOID_P MATCHES "8") - set(Architecture "x86_64") + set(Architecture "x86_64" CACHE INTERNAL "") else() - set(Architecture "x86") + set(Architecture "x86" CACHE INTERNAL "") endif() if(Architecture EQUAL "x86_64") @@ -119,24 +119,24 @@ if(WIN32) else() set(X86 OFF) if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") - set(Architecture "arm") + set(Architecture "arm" CACHE INTERNAL "") elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$") set(X86 ON) if(APPLE) - set(Architecture "x86") + set(Architecture "x86" CACHE INTERNAL "") else() # e.g. Linux - set(Architecture "i386") + set(Architecture "i386" CACHE INTERNAL "") endif() elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^x86.64$") set(X86 ON) - set(Architecture "x86_64") + set(Architecture "x86_64" CACHE INTERNAL "") elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "powerpc") - set(Architecture "ppc") + set(Architecture "ppc" CACHE INTERNAL "") elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "powerpc64") - set(Architecture "ppc64") + set(Architecture "ppc64" CACHE INTERNAL "") else() - set(Architecture "${CMAKE_SYSTEM_PROCESSOR}") + set(Architecture "${CMAKE_SYSTEM_PROCESSOR}" CACHE INTERNAL "") endif() endif() From ebf88c08578d277d427878b4475a7d64ab1d11bf Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Sun, 18 Dec 2022 01:28:04 -0800 Subject: [PATCH 3/9] Make Architecture lower case --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c6741cf13..a50e80d05c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,6 +105,7 @@ if(WIN32) set(X86 ON) if(DEFINED CMAKE_GENERATOR_PLATFORM) set(Architecture "${CMAKE_GENERATOR_PLATFORM}" CACHE INTERNAL "") + string(TOLOWER "${Architecture}" Architecture) elseif(CMAKE_SIZEOF_VOID_P MATCHES "8") set(Architecture "x86_64" CACHE INTERNAL "") else() @@ -137,6 +138,7 @@ else() set(Architecture "ppc64" CACHE INTERNAL "") else() set(Architecture "${CMAKE_SYSTEM_PROCESSOR}" CACHE INTERNAL "") + string(TOLOWER "${Architecture}" Architecture) endif() endif() From 1d81ac388277fbecff4b4036b7f504d9abc58391 Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Sun, 18 Dec 2022 02:10:08 -0800 Subject: [PATCH 4/9] Obtain SDL2 from VCPKG --- CMakeLists.txt | 7 +++++-- code/CMakeLists.txt | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a50e80d05c..32eedd0c64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,9 @@ list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake/Modules") # and is used in DLL names (jagamex86.dll, jagamex86.dylib, jagamei386.so). if(WIN32) set(X86 ON) + get_filename_component(ParentDir ${CMAKE_CURRENT_LIST_DIR} DIRECTORY) + # VCPKG default dir is this repository's sibling directory 'vcpkg'. + set(VcpkgDir "${ParentDir}/vcpkg" CACHE INTERNAL "") if(DEFINED CMAKE_GENERATOR_PLATFORM) set(Architecture "${CMAKE_GENERATOR_PLATFORM}" CACHE INTERNAL "") string(TOLOWER "${Architecture}" Architecture) @@ -112,9 +115,9 @@ if(WIN32) set(Architecture "x86" CACHE INTERNAL "") endif() - if(Architecture EQUAL "x86_64") + if(Architecture STREQUAL "x86_64") set(WIN64 TRUE) - elseif(Architecture EQUAL "x86") + elseif(Architecture STREQUAL "x86") set(WIN64 FALSE) endif() else() diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 2c9e7f509f..551d9800f9 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -71,18 +71,24 @@ if(BuildSPEngine OR BuildJK2SPEngine) endif() if(UseInternalSDL2) - if(CMAKE_SIZEOF_VOID_P EQUAL 4) + if(Architecture STREQUAL "x86") set(SPEngineLibraries ${SPEngineLibraries} ${OpenJKLibDir}/SDL2/lib/x86/SDL2main.lib ${OpenJKLibDir}/SDL2/lib/x86/SDL2.lib ) - else() + elseif(Architecture STREQUAL "x86_64") set(SPEngineLibraries ${SPEngineLibraries} ${OpenJKLibDir}/SDL2/lib/x64/SDL2main.lib ${OpenJKLibDir}/SDL2/lib/x64/SDL2.lib ) + elseif(Architecture STREQUAL "arm64") + set(SPEngineLibraries + ${SPEngineLibraries} + ${VcpkgDir}/installed/arm64-windows/lib/manual-link/SDL2main.lib + ${VcpkgDir}/installed/arm64-windows/lib/SDL2.lib + ) endif() set(SPEngineIncludeDirectories @@ -387,14 +393,19 @@ if(BuildSPEngine OR BuildJK2SPEngine) if(WIN32) add_executable(${ProjectName} WIN32 ${SPEngineFiles}) if(UseInternalSDL2) - if(CMAKE_SIZEOF_VOID_P EQUAL 4) + if(Architecture STREQUAL "x86") set(SPEngineExtraInstallFiles ${OpenJKLibDir}/SDL2/bin/x86/SDL2.dll ) - else() + elseif(Architecture STREQUAL "x86_64") set(SPEngineExtraInstallFiles ${OpenJKLibDir}/SDL2/bin/x64/SDL2.dll ) + elseif(Architecture STREQUAL "arm64") + set(SPEngineLibraries + ${SPEngineLibraries} + ${VcpkgDir}/installed/arm64-windows/bin/SDL2.dll + ) endif() endif() else(WIN32) From 6e561639f18a4f675c82266539359fb5bcd5e98d Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Sun, 18 Dec 2022 15:31:16 -0800 Subject: [PATCH 5/9] Don't use __rdtsc on ARM64 --- code/qcommon/timing.h | 5 +++-- codemp/qcommon/timing.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/code/qcommon/timing.h b/code/qcommon/timing.h index f608c2722a..8e472d74f0 100644 --- a/code/qcommon/timing.h +++ b/code/qcommon/timing.h @@ -38,7 +38,8 @@ class timing_c void Start() { -#ifdef _WIN32 + +#if defined(_WIN32) && !defined(_M_ARM64) start = __rdtsc(); #else start = 0; @@ -49,7 +50,7 @@ class timing_c { int time; -#ifdef _WIN32 +#if defined(_WIN32) && !defined(_M_ARM64) end = __rdtsc(); #else end = 0; diff --git a/codemp/qcommon/timing.h b/codemp/qcommon/timing.h index 28ef999e94..eab22d94dd 100644 --- a/codemp/qcommon/timing.h +++ b/codemp/qcommon/timing.h @@ -39,7 +39,7 @@ class timing_c void Start() { -#ifdef _WIN32 +#if defined(_WIN32) && !defined(_M_ARM64) start = __rdtsc(); #else start = 0; @@ -50,7 +50,7 @@ class timing_c { int64_t time; -#ifdef _WIN32 +#if defined(_WIN32) && !defined(_M_ARM64) end = __rdtsc(); #else end = 0; From 391222c3881363a84c4e70f75465c2430c0b63b7 Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Sun, 18 Dec 2022 16:32:35 -0800 Subject: [PATCH 6/9] Fix SDL2 DLL reference --- CMakeLists.txt | 2 +- code/CMakeLists.txt | 3 +-- codemp/CMakeLists.txt | 22 ++++++++++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32eedd0c64..9963fa4151 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,7 +115,7 @@ if(WIN32) set(Architecture "x86" CACHE INTERNAL "") endif() - if(Architecture STREQUAL "x86_64") + if(Architecture STREQUAL "x86_64" OR Architecture STREQUAL "arm64") set(WIN64 TRUE) elseif(Architecture STREQUAL "x86") set(WIN64 FALSE) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 551d9800f9..9e24d45e20 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -402,8 +402,7 @@ if(BuildSPEngine OR BuildJK2SPEngine) ${OpenJKLibDir}/SDL2/bin/x64/SDL2.dll ) elseif(Architecture STREQUAL "arm64") - set(SPEngineLibraries - ${SPEngineLibraries} + set(SPEngineExtraInstallFiles ${VcpkgDir}/installed/arm64-windows/bin/SDL2.dll ) endif() diff --git a/codemp/CMakeLists.txt b/codemp/CMakeLists.txt index c10cabf7ab..f4426605ce 100644 --- a/codemp/CMakeLists.txt +++ b/codemp/CMakeLists.txt @@ -377,18 +377,24 @@ if(BuildMPEngine) endif() if(UseInternalSDL2) - if(CMAKE_SIZEOF_VOID_P EQUAL 4) + if(Architecture STREQUAL "x86") set(MPEngineLibraries ${MPEngineLibraries} ${OpenJKLibDir}/SDL2/lib/x86/SDL2main.lib ${OpenJKLibDir}/SDL2/lib/x86/SDL2.lib ) - else() + elseif(Architecture STREQUAL "x86_64") set(MPEngineLibraries ${MPEngineLibraries} ${OpenJKLibDir}/SDL2/lib/x64/SDL2main.lib ${OpenJKLibDir}/SDL2/lib/x64/SDL2.lib ) + elseif(Architecture STREQUAL "arm64") + set(SPEngineLibraries + ${SPEngineLibraries} + ${VcpkgDir}/installed/arm64-windows/lib/manual-link/SDL2main.lib + ${VcpkgDir}/installed/arm64-windows/lib/SDL2.lib + ) endif() set(MPEngineIncludeDirectories @@ -564,14 +570,18 @@ if(BuildMPEngine) if(WIN32) add_executable(${MPEngine} WIN32 ${MPEngineFiles}) if(UseInternalSDL2) - if(CMAKE_SIZEOF_VOID_P EQUAL 4) - set(MPEngineExtraInstallFiles + if(Architecture STREQUAL "x86") + set(SPEngineExtraInstallFiles ${OpenJKLibDir}/SDL2/bin/x86/SDL2.dll ) - else() - set(MPEngineExtraInstallFiles + elseif(Architecture STREQUAL "x86_64") + set(SPEngineExtraInstallFiles ${OpenJKLibDir}/SDL2/bin/x64/SDL2.dll ) + elseif(Architecture STREQUAL "arm64") + set(SPEngineExtraInstallFiles + ${VcpkgDir}/installed/arm64-windows/bin/SDL2.dll + ) endif() endif() else(WIN32) From 0dc74aa964b2de68325d43768e2ea118c5ddb06b Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Sun, 18 Dec 2022 16:37:34 -0800 Subject: [PATCH 7/9] Use MPEngineExtraInstallFiles in MP CmakeLists --- codemp/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/codemp/CMakeLists.txt b/codemp/CMakeLists.txt index f4426605ce..c69e3f3c27 100644 --- a/codemp/CMakeLists.txt +++ b/codemp/CMakeLists.txt @@ -390,8 +390,8 @@ if(BuildMPEngine) ${OpenJKLibDir}/SDL2/lib/x64/SDL2.lib ) elseif(Architecture STREQUAL "arm64") - set(SPEngineLibraries - ${SPEngineLibraries} + set(MPEngineLibraries + ${MPEngineLibraries} ${VcpkgDir}/installed/arm64-windows/lib/manual-link/SDL2main.lib ${VcpkgDir}/installed/arm64-windows/lib/SDL2.lib ) @@ -571,15 +571,15 @@ if(BuildMPEngine) add_executable(${MPEngine} WIN32 ${MPEngineFiles}) if(UseInternalSDL2) if(Architecture STREQUAL "x86") - set(SPEngineExtraInstallFiles + set(MPEngineExtraInstallFiles ${OpenJKLibDir}/SDL2/bin/x86/SDL2.dll ) elseif(Architecture STREQUAL "x86_64") - set(SPEngineExtraInstallFiles + set(MPEngineExtraInstallFiles ${OpenJKLibDir}/SDL2/bin/x64/SDL2.dll ) elseif(Architecture STREQUAL "arm64") - set(SPEngineExtraInstallFiles + set(MPEngineExtraInstallFiles ${VcpkgDir}/installed/arm64-windows/bin/SDL2.dll ) endif() From 2fcacbcf1f03301bf4dcc140b7f1762fbb299c30 Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Sun, 18 Dec 2022 16:59:37 -0800 Subject: [PATCH 8/9] Diable JO building by default --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9963fa4151..65cd2afceb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,9 +43,9 @@ option(BuildSPEngine "Whether to create projects for the SP engine (openjk_sp.ex option(BuildSPGame "Whether to create projects for the SP gamecode (jagamex86.dll)" ON) option(BuildSPRdVanilla "Whether to create projects for the SP default renderer (rdsp-vanilla_x86.dll)" ON) -option(BuildJK2SPEngine "Whether to create projects for the jk2 SP engine (openjo_sp.exe)" ON) -option(BuildJK2SPGame "Whether to create projects for the jk2 sp gamecode mod (jk2gamex86.dll)" ON) -option(BuildJK2SPRdVanilla "Whether to create projects for the jk2 sp renderer (rdjosp-vanilla_x86.dll)" ON) +option(BuildJK2SPEngine "Whether to create projects for the jk2 SP engine (openjo_sp.exe)" OFF) +option(BuildJK2SPGame "Whether to create projects for the jk2 sp gamecode mod (jk2gamex86.dll)" OFF) +option(BuildJK2SPRdVanilla "Whether to create projects for the jk2 sp renderer (rdjosp-vanilla_x86.dll)" OFF) option(BuildTests "Whether to build automatic unit tests (requires Boost)" OFF) From eb3e4c0c5ad60109a96e70ed2ac93cf7309df1aa Mon Sep 17 00:00:00 2001 From: "Julio C. Rocha" Date: Thu, 9 Feb 2023 21:34:20 -0800 Subject: [PATCH 9/9] Skip CMAKE_GENERATOR_PLATFORM if empty --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65cd2afceb..f29c3bdf20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,7 +106,7 @@ if(WIN32) get_filename_component(ParentDir ${CMAKE_CURRENT_LIST_DIR} DIRECTORY) # VCPKG default dir is this repository's sibling directory 'vcpkg'. set(VcpkgDir "${ParentDir}/vcpkg" CACHE INTERNAL "") - if(DEFINED CMAKE_GENERATOR_PLATFORM) + if(DEFINED CMAKE_GENERATOR_PLATFORM AND NOT CMAKE_GENERATOR_PLATFORM STREQUAL "") set(Architecture "${CMAKE_GENERATOR_PLATFORM}" CACHE INTERNAL "") string(TOLOWER "${Architecture}" Architecture) elseif(CMAKE_SIZEOF_VOID_P MATCHES "8")