Skip to content

Commit e54a274

Browse files
AlexeySachkovAlexeySotkin
authored andcommitted
Fix build issue on Windows
add_llvm_library cmake function automatically adds resource file to the list of sources: two reource files cause errors during linking. Fixed by re-using resource file from LLVM source tree with manually configured fields.
1 parent 5e62f1f commit e54a274

File tree

3 files changed

+125
-62
lines changed

3 files changed

+125
-62
lines changed

CMakeLists.txt

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,6 @@ set( PRODUCT_VER_MINOR 0 )
140140
set (LLVM_VER_MAJOR ${LLVM_VERSION_MAJOR} )
141141
set (LLVM_VER_MINOR ${LLVM_VERSION_MINOR} )
142142

143-
if (WIN32)
144-
configure_file(
145-
${CMAKE_CURRENT_SOURCE_DIR}/common_clang.rc.in
146-
${CMAKE_CURRENT_BINARY_DIR}/common_clang.rc
147-
@ONLY)
148-
list (APPEND TARGET_SOURCE_FILES ${CMAKE_CURRENT_BINARY_DIR}/common_clang.rc)
149-
endif (WIN32)
150-
151143
add_definitions( -D__STDC_LIMIT_MACROS )
152144
add_definitions( -D__STDC_CONSTANT_MACROS )
153145
add_definitions( -DCOMMON_CLANG_EXPORTS )
@@ -256,6 +248,40 @@ add_llvm_library(${TARGET_NAME} SHARED
256248
clangStaticAnalyzerFrontend
257249
${CMAKE_DL_LIBS})
258250

251+
# Configure resource file on Windows
252+
if (WIN32)
253+
# windows_resource_file should be defined by llvm_add_library and should
254+
# contain full patch to a .rc file
255+
# It also might not be defined if this library is built out-of-tree:
256+
# let's use our copy of .rc file from LLVM source tree in that case
257+
if (NOT DEFINED windows_resource_file)
258+
set(windows_resource_file windows_resource_file.rc)
259+
endif(NOT DEFINED windows_resource_file)
260+
261+
set(RC_CHAR_TM "\\231")
262+
set(RC_CHAR_C "\\251")
263+
set(RC_CHAR_R "\\256")
264+
265+
set(RC_FILE_VERSION "${PRODUCT_VER_MAJOR}.${PRODUCT_VER_MINOR}.${LLVM_VER_MAJOR}.${LLVM_VER_MINOR}")
266+
set(RC_PRODUCT_NAME "Intel${RC_CHAR_R} Front-end Library for OpenCL${RC_CHAR_TM} software")
267+
268+
# Adjust content of the resource file by specifying compile definitions
269+
set_property(SOURCE ${windows_resource_file}
270+
PROPERTY COMPILE_DEFINITIONS
271+
"RC_VERSION_FIELD_1=${PRODUCT_VER_MAJOR}"
272+
"RC_VERSION_FIELD_2=${PRODUCT_VER_MINOR}"
273+
"RC_VERSION_FIELD_3=${LLVM_VER_MAJOR}"
274+
"RC_VERSION_FIELD_4=${LLVM_VER_MINOR}"
275+
"RC_COMPANY_NAME=\"Intel Corporation\""
276+
"RC_FILE_DESCRIPTION=\"${RC_PRODUCT_NAME}\""
277+
"RC_FILE_VERSION=\"${RC_FILE_VERSION}\""
278+
"RC_INTERNAL_NAME=\"${TARGET_NAME}\""
279+
"RC_ORIGINAL_FILENAME=\"${TARGET_NAME}.dll\""
280+
"RC_PRODUCT_NAME=\"${RC_PRODUCT_NAME}\""
281+
"RC_PRODUCT_VERSION=\"${RC_FILE_VERSION}\""
282+
"RC_COPYRIGHT=\"Copyright ${RC_CHAR_C} 2018 Intel Corporation. All rights reserved.\"")
283+
endif(WIN32)
284+
259285
install(FILES common_clang.h
260286
DESTINATION include/cclang
261287
COMPONENT ${TARGET_NAME})

common_clang.rc.in

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

windows_resource_file.rc

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// This file was copied from LLVM_SOURCE_DIR/resources/windows_version_resource.rc
2+
3+
// Microsoft Visual C++ resource script for embedding version information.
4+
// The format is described at:
5+
// http://msdn.microsoft.com/en-gb/library/windows/desktop/aa380599(v=vs.85).aspx
6+
// The VERSIONINFO resource is described at:
7+
// https://msdn.microsoft.com/en-gb/library/windows/desktop/aa381058(v=vs.85).aspx
8+
9+
10+
// Default values for required fields.
11+
12+
#ifndef RC_VERSION_FIELD_1
13+
#define RC_VERSION_FIELD_1 0
14+
#endif
15+
16+
#ifndef RC_VERSION_FIELD_2
17+
#define RC_VERSION_FIELD_2 0
18+
#endif
19+
20+
#ifndef RC_VERSION_FIELD_3
21+
#define RC_VERSION_FIELD_3 0
22+
#endif
23+
24+
#ifndef RC_VERSION_FIELD_4
25+
#define RC_VERSION_FIELD_4 0
26+
#endif
27+
28+
#ifndef RC_COMPANY_NAME
29+
#define RC_COMPANY_NAME ""
30+
#endif
31+
32+
#ifndef RC_FILE_DESCRIPTION
33+
#define RC_FILE_DESCRIPTION ""
34+
#endif
35+
36+
#ifndef RC_FILE_VERSION
37+
#define RC_FILE_VERSION ""
38+
#endif
39+
40+
#ifndef RC_INTERNAL_NAME
41+
#define RC_INTERNAL_NAME ""
42+
#endif
43+
44+
#ifndef RC_ORIGINAL_FILENAME
45+
#define RC_ORIGINAL_FILENAME ""
46+
#endif
47+
48+
#ifndef RC_PRODUCT_NAME
49+
#define RC_PRODUCT_NAME ""
50+
#endif
51+
52+
#ifndef RC_PRODUCT_VERSION
53+
#define RC_PRODUCT_VERSION ""
54+
#endif
55+
56+
57+
1 VERSIONINFO
58+
FILEVERSION RC_VERSION_FIELD_1,RC_VERSION_FIELD_2,RC_VERSION_FIELD_3,RC_VERSION_FIELD_4
59+
BEGIN
60+
BLOCK "StringFileInfo"
61+
BEGIN
62+
BLOCK "040904B0"
63+
BEGIN
64+
// Required strings
65+
VALUE "CompanyName", RC_COMPANY_NAME
66+
VALUE "FileDescription", RC_FILE_DESCRIPTION
67+
VALUE "FileVersion", RC_FILE_VERSION
68+
VALUE "InternalName", RC_INTERNAL_NAME
69+
VALUE "OriginalFilename", RC_ORIGINAL_FILENAME
70+
VALUE "ProductName", RC_PRODUCT_NAME
71+
VALUE "ProductVersion", RC_PRODUCT_VERSION
72+
73+
// Optional strings
74+
#ifdef RC_COMMENTS
75+
VALUE "Comments", RC_COMMENTS
76+
#endif
77+
78+
#ifdef RC_COPYRIGHT
79+
VALUE "LegalCopyright", RC_COPYRIGHT
80+
#endif
81+
END
82+
END
83+
84+
BLOCK "VarFileInfo"
85+
BEGIN
86+
// The translation must correspond to the above BLOCK inside StringFileInfo
87+
// langID 0x0409 U.S. English
88+
// charsetID 0x04B0 Unicode
89+
VALUE "Translation", 0x0409, 0x04B0
90+
END
91+
END

0 commit comments

Comments
 (0)