summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-06-26 09:38:35 -0400
committerBrad King <brad.king@kitware.com>2015-06-26 10:07:08 -0400
commit806609c7024dbf07a639a9d77074d4bc82ae1b8a (patch)
tree9722ec7e2129e407ff10794fb5c5035c0a6a9e2f
parentdcc2a7ccd4f8d9612b224d7106a4c3cfcd48e6fc (diff)
downloadcmake-806609c7024dbf07a639a9d77074d4bc82ae1b8a.tar.gz
VS: Add /machine: flag to Librarian tool (#11240)
If a Windows resource (.rc) source file is included in a STATIC library, the VS "link" tool will process the compiled ".res" file and needs to know the target architecture. Without it, we may get a LNK4068 warning and possibly a LNK1112 error. Add /machine: to the default static library flags to give the link tool the information it needs.
-rw-r--r--Modules/Platform/Windows-MSVC.cmake1
-rw-r--r--Tests/VSResource/CMakeLists.txt3
-rw-r--r--Tests/VSResource/lib.cpp1
-rw-r--r--Tests/VSResource/lib.rc4
-rw-r--r--Tests/VSResource/main.cpp4
5 files changed, 12 insertions, 1 deletions
diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake
index 13fe8bc9c4..2537e3921c 100644
--- a/Modules/Platform/Windows-MSVC.cmake
+++ b/Modules/Platform/Windows-MSVC.cmake
@@ -230,6 +230,7 @@ elseif(MSVC_Fortran_ARCHITECTURE_ID)
set(_MACHINE_ARCH_FLAG "/machine:${MSVC_Fortran_ARCHITECTURE_ID}")
endif()
set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} ${_MACHINE_ARCH_FLAG}")
+set(CMAKE_STATIC_LINKER_FLAGS_INIT "${CMAKE_STATIC_LINKER_FLAGS_INIT} ${_MACHINE_ARCH_FLAG}")
unset(_MACHINE_ARCH_FLAG)
# add /debug and /INCREMENTAL:YES to DEBUG and RELWITHDEBINFO also add pdbtype
diff --git a/Tests/VSResource/CMakeLists.txt b/Tests/VSResource/CMakeLists.txt
index 17eb04136d..3b9cfc396f 100644
--- a/Tests/VSResource/CMakeLists.txt
+++ b/Tests/VSResource/CMakeLists.txt
@@ -46,7 +46,10 @@ else()
include_directories(${CMAKE_CURRENT_BINARY_DIR})
endif()
+add_library(ResourceLib STATIC lib.cpp lib.rc)
+
add_executable(VSResource main.cpp test.rc)
+target_link_libraries(VSResource ResourceLib)
set_property(TARGET VSResource
PROPERTY VS_GLOBAL_CMakeTestVsGlobalVariable "test val")
diff --git a/Tests/VSResource/lib.cpp b/Tests/VSResource/lib.cpp
new file mode 100644
index 0000000000..006e3e48ac
--- /dev/null
+++ b/Tests/VSResource/lib.cpp
@@ -0,0 +1 @@
+int lib() { return 0; }
diff --git a/Tests/VSResource/lib.rc b/Tests/VSResource/lib.rc
new file mode 100644
index 0000000000..1ffade6ca8
--- /dev/null
+++ b/Tests/VSResource/lib.rc
@@ -0,0 +1,4 @@
+STRINGTABLE
+BEGIN
+ 1234 "5"
+END
diff --git a/Tests/VSResource/main.cpp b/Tests/VSResource/main.cpp
index 7ee0c74fa3..ccf700c42d 100644
--- a/Tests/VSResource/main.cpp
+++ b/Tests/VSResource/main.cpp
@@ -1,6 +1,8 @@
#include <windows.h>
#include <stdio.h>
+extern int lib();
+
struct x
{
const char *txt;
@@ -76,5 +78,5 @@ int main(int argc, char** argv)
}
}
- return ret;
+ return ret + lib();
}