Skip to content

Commit

Permalink
cross-compilation scaffolding WIP
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
majcosta committed Dec 13, 2024
1 parent 87f51f0 commit 1d58bda
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
39 changes: 39 additions & 0 deletions cmake/clang-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -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})
11 changes: 11 additions & 0 deletions cmake/mingw-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -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})

0 comments on commit 1d58bda

Please sign in to comment.