PellesC: Add support for Windows Resources

The PellesC toolchain provides a `porc` tool to compile them.

Note that `polib` fails to archive resource files (`.res`):

    POLIB: fatal error: An internal error occurred

Turn off the static library part of the VSResource test.

Issue: #21536
Inspired-by: Serguei E. Leontiev <leo@sai.msu.ru>
This commit is contained in:
Brad King
2026-04-20 11:58:39 -04:00
parent f0d5a282da
commit fec53c68cd
5 changed files with 21 additions and 6 deletions
+5
View File
@@ -21,4 +21,9 @@ macro(__windows_compiler_pellesc lang)
set(CMAKE_${lang}_CREATE_WIN32_EXE "-subsystem:windows")
set(CMAKE_${lang}_CREATE_CONSOLE_EXE "-subsystem:console")
if(NOT CMAKE_RC_COMPILER_INIT)
set(CMAKE_RC_COMPILER_INIT porc)
endif()
enable_language(RC)
endmacro()
+1
View File
@@ -0,0 +1 @@
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -Fo<OBJECT> <SOURCE>")
+1
View File
@@ -444,6 +444,7 @@ if(BUILD_TESTING)
if(CMake_TEST_RESOURCES)
ADD_TEST_MACRO(VSResource VSResource)
set_property(TEST VSResource APPEND PROPERTY LABELS "PellesC")
if(CMAKE_GENERATOR MATCHES "Ninja")
add_test_macro(VSResourceNinjaForceRSP VSResourceNinjaForceRSP)
endif()
+7 -5
View File
@@ -13,9 +13,8 @@ message(STATUS "CMAKE_RC_COMPILER='${CMAKE_RC_COMPILER}'")
# add_definitions is fine for simple definitions (with no spaces and no
# quoting), but requires avoidance or work-arounds beyond that...
if(CMAKE_RC_COMPILER MATCHES windres)
if(CMAKE_RC_COMPILER MATCHES "(windres|porc)")
# windres rc compiler does not properly define quoted /D values as strings
message(STATUS "CMAKE_RC_COMPILER MATCHES windres")
add_definitions(/DCMAKE_RCDEFINE=test.txt)
add_definitions(/DCMAKE_RCDEFINE_NO_QUOTED_STRINGS)
if(CMAKE_CURRENT_BINARY_DIR MATCHES " ")
@@ -45,10 +44,13 @@ else()
include_directories(${CMAKE_CURRENT_BINARY_DIR})
endif()
add_library(ResourceLib STATIC lib.c lib.rc)
add_executable(VSResource main.c test.rc)
target_link_libraries(VSResource ResourceLib)
if(NOT CMAKE_AR MATCHES "polib")
add_library(ResourceLib STATIC lib.c lib.rc)
target_link_libraries(VSResource PRIVATE ResourceLib)
target_compile_definitions(VSResource PRIVATE HAVE_RESOURCE_LIB)
endif()
if(MSVC AND NOT MSVC_VERSION VERSION_LESS 1600)
set_property(SOURCE test.rc PROPERTY COMPILE_FLAGS /nologo)
+7 -1
View File
@@ -2,7 +2,9 @@
#include <stdio.h>
#ifdef HAVE_RESOURCE_LIB
extern int lib(void);
#endif
struct x
{
@@ -76,5 +78,9 @@ int main(int argc, char** argv)
}
}
return ret + lib();
return ret
#ifdef HAVE_RESOURCE_LIB
+ lib()
#endif
;
}