From 1d58bda82dc7364114f1a3bc8c9147c780c0bf8f Mon Sep 17 00:00:00 2001 From: "Marco Antonio J. Costa" Date: Fri, 13 Dec 2024 19:07:39 -0300 Subject: [PATCH] cross-compilation scaffolding WIP requires clang/lld or mingw, obviously just make sure the MSVC_DIRECTORY env variable points to valid Visual Studio Build Tools directory and do: `cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=clang_or_mingw_toolchain_file` --- cmake/clang-toolchain.cmake | 39 +++++++++++++++++++++++++++++++++++++ cmake/mingw-toolchain.cmake | 11 +++++++++++ 2 files changed, 50 insertions(+) create mode 100644 cmake/clang-toolchain.cmake create mode 100644 cmake/mingw-toolchain.cmake diff --git a/cmake/clang-toolchain.cmake b/cmake/clang-toolchain.cmake new file mode 100644 index 000000000..e70a13752 --- /dev/null +++ b/cmake/clang-toolchain.cmake @@ -0,0 +1,39 @@ +set(CMAKE_SYSTEM_NAME Windows) + +set(CMAKE_C_COMPILER clang) +set(CMAKE_CXX_COMPILER clang++) +set(CMAKE_RC_COMPILER llvm-rc) + +set(triple i386-pc-win32-msvc) +set(CMAKE_C_COMPILER_TARGET ${triple}) +set(CMAKE_CXX_COMPILER_TARGET ${triple}) +set(CMAKE_RC_COMPILER_TARGET ${triple}) + +set(msvc_dir "$ENV{MSVC_DIRECTORY}") +if(msvc_dir STREQUAL "") + message(FATAL_ERROR "Please set a valid MSVC_DIRECTORY environment variable") +endif() + +# Don't remember which version of Visual Studio Build Tools this is. +# When updating this, make sure to pin the version so people can get it. +set(msvc_include + "${msvc_dir}/14.34.31933/include" + "${msvc_dir}/14.34.31933/ATLMFC/include" + "${msvc_dir}/include/10.0.22000.0/ucrt" + "${msvc_dir}/include/10.0.22000.0/um" + "${msvc_dir}/include/10.0.22000.0/shared" + "${msvc_dir}/include/10.0.22000.0/winrt" + "${msvc_dir}/include/10.0.22000.0/cppwinrt" +) +set(msvc_libraries + "${msvc_dir}/14.34.31933/ATLMFC/lib/x86" + "${msvc_dir}/14.34.31933/lib/x86" + "${msvc_dir}/lib/10.0.22000.0/ucrt/x86" + "${msvc_dir}/lib/10.0.22000.0/um/x86" +) + +foreach(LANG C CXX) + set(CMAKE_${LANG}_STANDARD_INCLUDE_DIRECTORIES ${msvc_include}) +endforeach() + +link_directories(${msvc_libraries}) diff --git a/cmake/mingw-toolchain.cmake b/cmake/mingw-toolchain.cmake new file mode 100644 index 000000000..f8742cfb9 --- /dev/null +++ b/cmake/mingw-toolchain.cmake @@ -0,0 +1,11 @@ +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_SYSTEM_PROCESSOR i686) + +set(triple ${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32) + +set(CMAKE_C_COMPILER ${triple}-gcc) +set(CMAKE_CXX_COMPILER ${triple}-g++) +set(CMAKE_RC_COMPILER ${triple}-windres) + +set(CMAKE_C_COMPILER_TARGET ${triple}) +set(CMAKE_CXX_COMPILER_TARGET ${triple})