mirror of
https://github.com/Kitware/CMake.git
synced 2026-11-06 05:16:58 +00:00
Tests/VSResource: Port from C++ to C
This will make the test usable without a C++ compiler. The test's code was basically C compiled as C++ anyway.
This commit is contained in:
1 parent
63a3a1c1a3
commit
f037bd6950
6 files changed
+31
-27
No files matched your search
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(VSResource)
|
||||
project(VSResource LANGUAGES C)
|
||||
|
||||
string(REPLACE "/INCREMENTAL:YES" ""
|
||||
CMAKE_EXE_LINKER_FLAGS_DEBUG
|
||||
@@ -45,9 +45,9 @@ else()
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
add_library(ResourceLib STATIC lib.cpp lib.rc)
|
||||
add_library(ResourceLib STATIC lib.c lib.rc)
|
||||
|
||||
add_executable(VSResource main.cpp test.rc)
|
||||
add_executable(VSResource main.c test.rc)
|
||||
target_link_libraries(VSResource ResourceLib)
|
||||
|
||||
if(MSVC AND NOT MSVC_VERSION VERSION_LESS 1600)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
int lib()
|
||||
int lib(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern int lib();
|
||||
extern int lib(void);
|
||||
|
||||
struct x
|
||||
{
|
||||
@@ -12,6 +12,7 @@ struct x
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int ret = 1;
|
||||
HRSRC hello = FindResource(NULL, MAKEINTRESOURCE(1025), "TEXTFILE");
|
||||
|
||||
fprintf(stdout, "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)\n");
|
||||
|
||||
@@ -20,30 +21,31 @@ int main(int argc, char** argv)
|
||||
#endif
|
||||
|
||||
#ifdef CMAKE_RCDEFINE_NO_QUOTED_STRINGS
|
||||
// Expect CMAKE_RCDEFINE to preprocess to exactly test.txt
|
||||
x test;
|
||||
test.txt = "*exactly* test.txt";
|
||||
fprintf(stdout, "CMAKE_RCDEFINE_NO_QUOTED_STRINGS defined\n");
|
||||
fprintf(stdout, "CMAKE_RCDEFINE is %s, and is *not* a string constant\n",
|
||||
CMAKE_RCDEFINE);
|
||||
{
|
||||
// Expect CMAKE_RCDEFINE to preprocess to exactly test.txt
|
||||
struct x test;
|
||||
test.txt = "*exactly* test.txt";
|
||||
fprintf(stdout, "CMAKE_RCDEFINE_NO_QUOTED_STRINGS defined\n");
|
||||
fprintf(stdout, "CMAKE_RCDEFINE is %s, and is *not* a string constant\n",
|
||||
CMAKE_RCDEFINE);
|
||||
}
|
||||
#else
|
||||
// Expect CMAKE_RCDEFINE to be a string:
|
||||
fprintf(stdout, "CMAKE_RCDEFINE='%s', and is a string constant\n",
|
||||
CMAKE_RCDEFINE);
|
||||
#endif
|
||||
|
||||
HRSRC hello = ::FindResource(NULL, MAKEINTRESOURCE(1025), "TEXTFILE");
|
||||
if (hello) {
|
||||
HGLOBAL hgbl = LoadResource(NULL, hello);
|
||||
int datasize = (int)SizeofResource(NULL, hello);
|
||||
fprintf(stdout, "FindResource worked\n");
|
||||
HGLOBAL hgbl = ::LoadResource(NULL, hello);
|
||||
int datasize = (int)::SizeofResource(NULL, hello);
|
||||
if (hgbl && datasize > 0) {
|
||||
void* data = LockResource(hgbl);
|
||||
fprintf(stdout, "LoadResource worked\n");
|
||||
fprintf(stdout, "SizeofResource returned datasize='%d'\n", datasize);
|
||||
void* data = ::LockResource(hgbl);
|
||||
if (data) {
|
||||
fprintf(stdout, "LockResource worked\n");
|
||||
char* str = (char*)malloc(datasize + 4);
|
||||
fprintf(stdout, "LockResource worked\n");
|
||||
if (str) {
|
||||
memcpy(str, data, datasize);
|
||||
str[datasize] = 'E';
|
||||
@@ -58,13 +60,15 @@ int main(int argc, char** argv)
|
||||
#ifdef CMAKE_RCDEFINE_NO_QUOTED_STRINGS
|
||||
fprintf(stdout, "LoadString skipped\n");
|
||||
#else
|
||||
char buf[256];
|
||||
if (::LoadString(NULL, 1026, buf, sizeof(buf)) > 0) {
|
||||
fprintf(stdout, "LoadString worked\n");
|
||||
fprintf(stdout, "buf='%s'\n", buf);
|
||||
} else {
|
||||
fprintf(stdout, "LoadString failed\n");
|
||||
ret = 1;
|
||||
{
|
||||
char buf[256];
|
||||
if (LoadString(NULL, 1026, buf, sizeof(buf)) > 0) {
|
||||
fprintf(stdout, "LoadString worked\n");
|
||||
fprintf(stdout, "buf='%s'\n", buf);
|
||||
} else {
|
||||
fprintf(stdout, "LoadString failed\n");
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(VSResourceNinjaForceRSP)
|
||||
project(VSResourceNinjaForceRSP LANGUAGES C)
|
||||
|
||||
set(CMAKE_NINJA_FORCE_RESPONSE_FILE TRUE)
|
||||
|
||||
add_library(ResourceLib lib.cpp test.rc)
|
||||
add_executable(VSResourceNinjaForceRSP main.cpp test.rc)
|
||||
add_library(ResourceLib lib.c test.rc)
|
||||
add_executable(VSResourceNinjaForceRSP main.c test.rc)
|
||||
@@ -1,4 +1,4 @@
|
||||
int lib()
|
||||
int lib(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
File renamed without changes.
Reference in new issue
Block a user