]> granicus.if.org Git - llvm/commitdiff
[libFuzzer] Fix test with shared libraries on Windows.
authorMarcos Pividori <mpividori@google.com>
Sun, 22 Jan 2017 02:28:08 +0000 (02:28 +0000)
committerMarcos Pividori <mpividori@google.com>
Sun, 22 Jan 2017 02:28:08 +0000 (02:28 +0000)
We need to set BINARY_DIR to: ${CMAKE_BINARY_DIR}/lib/Fuzzer/test , so the dll
is placed in the same directory than the test LLVMFuzzer-DSOTest, and is found
when executing that test.
As we are using CMAKE_CXX_CREATE_SHARED_LIBRARY to link the dll, we can't modify
the output directory for the import library. It will be created in the same
directory than the dll (in BINARY_DIR), no matter which value we set to
LIBRARY_DIR. So, if we set LIBRARY_DIR to a different directory than BINARY_DIR,
when linking LLVMFuzzer-DSOTest, cmake will look for the import library
LLVMFuzzer-DSO1.lib in LIBRARY_DIR, and won't find it, since it was created in
BINARY_DIR. So, for Windows, we need that LIBRARY_DIR and BINARY_DIR are the
same directory.

Differential Revision: https://reviews.llvm.org/D27870

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292748 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/test/CMakeLists.txt
lib/Fuzzer/test/DSO1.cpp
lib/Fuzzer/test/DSO2.cpp

index 2d1f178629317961f8863a9cf016f58626e7e4bd..f2dfcf21482cb31c44b92c22a5b357d9dd08cfbd 100644 (file)
@@ -195,10 +195,20 @@ target_link_libraries(LLVMFuzzer-DSOTest
 
 set_target_properties(LLVMFuzzer-DSOTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY
   "${CMAKE_BINARY_DIR}/lib/Fuzzer/test")
-set_target_properties(LLVMFuzzer-DSO1 PROPERTIES LIBRARY_OUTPUT_DIRECTORY
-  "${CMAKE_BINARY_DIR}/lib/Fuzzer/lib")
-set_target_properties(LLVMFuzzer-DSO2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY
-  "${CMAKE_BINARY_DIR}/lib/Fuzzer/lib")
+
+if(MSVC)
+  set_output_directory(LLVMFuzzer-DSO1
+    BINARY_DIR "${CMAKE_BINARY_DIR}/lib/Fuzzer/test"
+    LIBRARY_DIR "${CMAKE_BINARY_DIR}/lib/Fuzzer/test")
+  set_output_directory(LLVMFuzzer-DSO2
+    BINARY_DIR "${CMAKE_BINARY_DIR}/lib/Fuzzer/test"
+    LIBRARY_DIR "${CMAKE_BINARY_DIR}/lib/Fuzzer/test")
+else(MSVC)
+  set_output_directory(LLVMFuzzer-DSO1
+    LIBRARY_DIR "${CMAKE_BINARY_DIR}/lib/Fuzzer/lib")
+  set_output_directory(LLVMFuzzer-DSO2
+    LIBRARY_DIR "${CMAKE_BINARY_DIR}/lib/Fuzzer/lib")
+endif()
 
 set(TestBinaries ${TestBinaries} LLVMFuzzer-DSOTest)
 
index 4a293890f4b0d1094badd47deefcafba1a73efe3..72a5ec4a0cdefd60da051440d532deab1ed797a5 100644 (file)
@@ -2,7 +2,9 @@
 // License. See LICENSE.TXT for details.
 
 // Source code for a simple DSO.
-
+#ifdef _WIN32
+__declspec( dllexport )
+#endif
 int DSO1(int a) {
   if (a < 123456)
     return 0;
index 04b308d193ac59e19fd9470b630a06f3b993dcdd..2967055dc22795d93bc2190ebbebd332dd20c45d 100644 (file)
@@ -2,7 +2,9 @@
 // License. See LICENSE.TXT for details.
 
 // Source code for a simple DSO.
-
+#ifdef _WIN32
+__declspec( dllexport )
+#endif
 int DSO2(int a) {
   if (a < 3598235)
     return 0;