Skip to content

Commit ea5e5e5

Browse files
committed
cmake: Compile windows executables using MinGW
windows-libc is more trouble than it's worth and MinGW covers a lot of the ground that's missing from native windows C library. What's still missing is covered by compat/. Switch cmake presets to use MinGW for native windows compilation as well as cross-compilation from linux. Remove windows-libc dependency, all attendant cmake hacks etc. Signed-off-by: Alexander Shishkin <[email protected]>
1 parent eb64785 commit ea5e5e5

File tree

4 files changed

+66
-79
lines changed

4 files changed

+66
-79
lines changed

CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ endif ()
3434

3535
include(scripts/bootstrap.cmake)
3636
bootstrap_deps("bootstrap.json")
37-
if (WIN32)
38-
bootstrap_deps("bootstrap-win32.json")
39-
endif ()
4037

4138
add_subdirectory(${CMAKE_SOURCE_DIR}/compat)
4239

@@ -81,8 +78,6 @@ set(MESHOPT_BUILD_SHARED_LIBS OFF CACHE BOOL "")
8178
add_subdirectory(deps/src/meshoptimizer EXCLUDE_FROM_ALL)
8279
set_property(TARGET meshoptimizer PROPERTY FOLDER "ThirdPartyLibraries")
8380

84-
wlibc_setup(deps/src/windows-libc)
85-
8681
set(ODE_ROOT "${CMAKE_CURRENT_BINARY_DIR}/ode")
8782

8883
if (WIN32)

CMakeUserPresets.json

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -75,51 +75,81 @@
7575
}
7676
},
7777
{
78-
"name": "w32debug",
79-
"displayName": "win32 debug",
80-
"binaryDir": "build/debug",
81-
"generator": "Ninja",
78+
"name": "w32debug-cross",
79+
"displayName": "win32 debug with (mingw, cross)",
80+
"binaryDir": "build/w32debug",
81+
"generator": "Unix Makefiles",
8282
"toolchainFile": "$env{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake",
8383
"cacheVariables": {
84-
"CMAKE_PROGRAM_PATH": "C:/Program Files/LLVM/bin",
8584
"CMAKE_BUILD_TYPE":"Debug",
8685
"CMAKE_SYSTEM_PROCESSOR": "AMD64",
87-
"CMAKE_C_COMPILER_FRONTEND_VARIANT": "MSVC",
88-
"CMAKE_CXX_COMPILER_FRONTEND_VARIANT": "MSVC",
89-
"CMAKE_C_COMPILER": "clang-cl.exe",
90-
"CMAKE_CXX_COMPILER": "clang-cl.exe",
91-
"CMAKE_AR": "llvm-lib.exe",
92-
"CMAKE_PREFIX_PATH": "$env{VCPKG_INSTALLATION_ROOT}/installed/x64-windows-static/",
86+
"CMAKE_SYSTEM_NAME": "Windows",
87+
"CMAKE_C_COMPILER_FRONTEND_VARIANT": "GNU",
88+
"CMAKE_CXX_COMPILER_FRONTEND_VARIANT": "GNU",
89+
"CMAKE_C_COMPILER": "x86_64-w64-mingw32-gcc",
90+
"CMAKE_CXX_COMPILER": "x86_64-w64-mingw32-g++",
91+
"CMAKE_AR": "x86_64-w64-mingw32-ar",
92+
"CMAKE_RANLIB": "x86_64-w64-mingw32-ranlib",
93+
"CMAKE_NM": "x86_64-w64-mingw32-nm",
94+
"CMAKE_STRIP": "x86_64-w64-mingw32-strip",
9395
"VCPKG_LOAD_VCVARS_ENV": true,
94-
"VCPKG_TARGET_TRIPLET": "x64-windows-static",
96+
"VCPKG_TARGET_TRIPLET": "x64-mingw",
9597
"VCPKG_APPLOCAL_DEPS": false,
9698
"CLAP_BUILD_NETWORKING": false,
99+
"LDJAM56_BUILD_IN_ASSETS":true,
100+
"LDJAM57_BUILD_IN_ASSETS":true
101+
}
102+
},
103+
{
104+
"name": "w32test-cross",
105+
"displayName": "win32 test/release-with-debug-info (mingw, cross)",
106+
"inherits": "w32debug-cross",
107+
"cacheVariables": {
108+
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
109+
},
110+
"binaryDir": "build/w32test"
111+
},
112+
{
113+
"name": "w32rel-cross",
114+
"displayName": "win32 release (mingw, cross)",
115+
"inherits": "w32debug-cross",
116+
"cacheVariables": {
117+
"CMAKE_BUILD_TYPE": "Release"
118+
},
119+
"binaryDir": "build/w32rel"
120+
},
121+
{
122+
"name": "w32debug",
123+
"displayName": "win32 debug (mingw, native)",
124+
"binaryDir": "build/debug",
125+
"inherits": "w32debug-cross",
126+
"generator": "Ninja",
127+
"cacheVariables": {
128+
"CMAKE_C_COMPILER": "gcc.exe",
129+
"CMAKE_CXX_COMPILER": "g++.exe",
130+
"CMAKE_AR": "ar.exe",
131+
"CMAKE_STRIP": "strip.exe",
132+
"CMAKE_RANLIB": "ranlib.exe",
97133
"GLSLC_HINT": "$env{VCPKG_INSTALLATION_ROOT}/installed/x64-windows/tools/shaderc",
98134
"SPIRV_CROSS_HINT": "$env{VCPKG_INSTALLATION_ROOT}/installed/x64-windows/tools/spirv-cross"
99135
}
100136
},
101137
{
102138
"name": "w32test",
103-
"displayName": "win32 test",
139+
"displayName": "win32 test/release-with-debug-info (mingw, native)",
104140
"binaryDir": "build/test",
105-
"generator": "Ninja",
106-
"toolchainFile": "$env{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake",
141+
"inherits": "w32debug",
107142
"cacheVariables": {
108-
"CMAKE_PROGRAM_PATH": "C:/Program Files/LLVM/bin",
109-
"CMAKE_BUILD_TYPE":"Release",
110-
"CMAKE_SYSTEM_PROCESSOR": "AMD64",
111-
"CMAKE_C_COMPILER_FRONTEND_VARIANT": "MSVC",
112-
"CMAKE_CXX_COMPILER_FRONTEND_VARIANT": "MSVC",
113-
"CMAKE_C_COMPILER": "clang-cl.exe",
114-
"CMAKE_CXX_COMPILER": "clang-cl.exe",
115-
"CMAKE_AR": "llvm-lib.exe",
116-
"CMAKE_PREFIX_PATH": "$env{VCPKG_INSTALLATION_ROOT}/installed/x64-windows-static/",
117-
"VCPKG_LOAD_VCVARS_ENV": true,
118-
"VCPKG_TARGET_TRIPLET": "x64-windows-static",
119-
"VCPKG_APPLOCAL_DEPS": false,
120-
"CLAP_BUILD_NETWORKING": false,
121-
"GLSLC_HINT": "$env{VCPKG_INSTALLATION_ROOT}/installed/x64-windows/tools/shaderc",
122-
"SPIRV_CROSS_HINT": "$env{VCPKG_INSTALLATION_ROOT}/installed/x64-windows/tools/spirv-cross"
143+
"CMAKE_BUILD_TYPE":"RelWithDebInfo"
144+
}
145+
},
146+
{
147+
"name": "w32rel",
148+
"displayName": "win32 release (mingw, native)",
149+
"binaryDir": "build/rel",
150+
"inherits": "w32debug",
151+
"cacheVariables": {
152+
"CMAKE_BUILD_TYPE":"Release"
123153
}
124154
}
125155
],

deps/bootstrap-win32.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

scripts/win32-helpers.cmake

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,17 @@ elseif (WIN32)
55
set(WIN32_HOST OFF)
66
endif ()
77

8-
function(wlibc_setup wlibc_dir)
9-
if (WIN32)
10-
set(BUILD_TESTING OFF)
11-
set(ENABLE_DLFCN OFF CACHE BOOL "")
12-
set(ENABLE_LANGINFO OFF CACHE BOOL "")
13-
set(ENABLE_EXTENDED_ATTRIBUTES OFF CACHE BOOL "")
14-
set(ENABLE_ACCOUNTS OFF CACHE BOOL "")
15-
set(ENABLE_TERMIOS OFF CACHE BOOL "")
16-
set(ENABLE_WCHAR_EXT OFF CACHE BOOL "")
17-
add_subdirectory(${wlibc_dir} EXCLUDE_FROM_ALL)
18-
set_property(TARGET wlibc PROPERTY FOLDER "ThirdPartyLibraries")
19-
set(WLIBC_LIBRARY "${CMAKE_BINARY_DIR}/wlibc${W32LIBSUFFIX}.lib" CACHE INTERNAL "WLIBC_LIBRARY")
20-
set(WLIBC_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/${wlibc_dir}/include" CACHE INTERNAL "WLIBC_INCLUDE_DIR")
21-
set(WLIBC_DEFINES "__forceinline=static\ inline\ __attribute__((always_inline))" CACHE INTERNAL "WLIBC_DEFINES")
22-
endif ()
23-
endfunction ()
24-
258
function(win32_library target includes)
26-
if (WIN32)
27-
target_compile_definitions(${target} PUBLIC ${WLIBC_DEFINES})
28-
if (includes)
29-
target_include_directories(${target} PUBLIC ${WLIBC_INCLUDE_DIR})
30-
endif ()
31-
target_link_libraries(${target} PRIVATE ${WLIBC_LIBRARY})
32-
else ()
33-
target_link_libraries(${target} PRIVATE clap_compat)
34-
endif ()
9+
target_link_libraries(${target} PRIVATE clap_compat)
3510
endfunction ()
3611

3712
function(win32_executable target)
3813
target_link_libraries(${target} PRIVATE clap_compat)
3914
if (WIN32)
40-
win32_library(${target} TRUE)
41-
target_link_libraries(${target} PRIVATE ntdll Netapi32)
42-
target_link_options(${target} PRIVATE /ENTRY:wmainCRTStartup /SUBSYSTEM:CONSOLE)
15+
target_link_options(${target} PRIVATE
16+
-static-libgcc
17+
-static-libstdc++
18+
-Wl,-Bstatic -lwinpthread -Wl,-Bdynamic
19+
)
4320
endif ()
4421
endfunction ()

0 commit comments

Comments
 (0)