]> granicus.if.org Git - llvm/commitdiff
CMake: Disable ENABLE_EXPORTS for executables with MSVC
authorReid Kleckner <reid@kleckner.net>
Wed, 18 Mar 2015 20:09:13 +0000 (20:09 +0000)
committerReid Kleckner <reid@kleckner.net>
Wed, 18 Mar 2015 20:09:13 +0000 (20:09 +0000)
The MSVC linker won't produce a .lib file for an executable that doesn't
export anything, and LLVM doesn't maintain dllexport annotations or .def
files listing all C++ symbols. It also doesn't support exporting all
symbols, like binutils ld.

CMake 3.2 changed the Ninja generator to list both the .exe and .lib
files as outputs of executable build targets. Ninja would always re-link
executables with ENABLE_EXPORTS because the .lib output file was not
present, and therefore the target was out of date.

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

CMakeLists.txt
cmake/modules/AddLLVM.cmake
examples/ExceptionDemo/CMakeLists.txt
tools/bugpoint/CMakeLists.txt
tools/llc/CMakeLists.txt
tools/lli/CMakeLists.txt
tools/llvm-stress/CMakeLists.txt
tools/opt/CMakeLists.txt

index cfbf9562f0385d51a35c6cc6c857cf6d14c408c5..b91ba15f5534a6264a233ed4576d34a4ab2dccd2 100644 (file)
@@ -557,7 +557,7 @@ if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
 endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
 
 # Make sure we don't get -rdynamic in every binary. For those that need it,
-# use set_target_properties(target PROPERTIES ENABLE_EXPORTS 1)
+# use export_executable_symbols(target).
 set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
 
 include(AddLLVM)
index de542f54b3a8bfeb2d45de7ec4f406bd5a91f888..83897935e27d4edab4b3849f97cbc03152415774 100644 (file)
@@ -490,6 +490,12 @@ macro(add_llvm_executable name)
   endif( LLVM_COMMON_DEPENDS )
 endmacro(add_llvm_executable name)
 
+function(export_executable_symbols target)
+  if (NOT MSVC) # MSVC's linker doesn't support exporting all symbols.
+    set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
+  endif()
+endfunction()
+
 
 set (LLVM_TOOLCHAIN_TOOLS
   llvm-ar
index 9cadd94c24a59be9bfc24fb833c02eab249c927f..2a7667dfba42c0f11f7d75aa52b2251f409df40b 100644 (file)
@@ -15,4 +15,4 @@ add_llvm_example(ExceptionDemo
   ExceptionDemo.cpp
   )
 
-set_target_properties(ExceptionDemo PROPERTIES ENABLE_EXPORTS 1)
+export_executable_symbols(ExceptionDemo)
index d71e097918c40d47785d3dd2d55446501107dd7b..daf502e16ccdd1cba30d8da47c4a6604f7433dc6 100644 (file)
@@ -31,7 +31,7 @@ add_llvm_tool(bugpoint
   ToolRunner.cpp
   bugpoint.cpp
   )
-set_target_properties(bugpoint PROPERTIES ENABLE_EXPORTS 1)
+export_executable_symbols(bugpoint)
 
 if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
   target_link_libraries(bugpoint Polly)
index 484ff4028f83c140a5475a9dddd8194b013b97cc..dcbcf9da6128be8658c23129b660e9053cf939bd 100644 (file)
@@ -17,4 +17,4 @@ set(LLVM_NO_DEAD_STRIP 1)
 add_llvm_tool(llc
   llc.cpp
   )
-set_target_properties(llc PROPERTIES ENABLE_EXPORTS 1)
+export_executable_symbols(llc)
index 463c8530894ad29247a6ed4d38ccad19e35336f8..aad8367f34ec3c5d678f49f80bef2aeca35d7bb4 100644 (file)
@@ -39,4 +39,4 @@ add_llvm_tool(lli
   RemoteTarget.cpp
   RemoteTargetExternal.cpp
   )
-set_target_properties(lli PROPERTIES ENABLE_EXPORTS 1)
+export_executable_symbols(llvm-stress)
index 106ced1419444e5e964aaf64fad9e448d43aee43..d5c10e13f5b3c19734364e1c996ec12f669a77bb 100644 (file)
@@ -7,4 +7,4 @@ set(LLVM_LINK_COMPONENTS
 add_llvm_tool(llvm-stress
   llvm-stress.cpp
   )
-set_target_properties(llvm-stress PROPERTIES ENABLE_EXPORTS 1)
+export_executable_symbols(llvm-stress)
index 12dc4f0a9f558115dcc7489459b4ecb9b3fd2ac4..5f825220cc889d018c0eb3d75ca39f6ebc22a363 100644 (file)
@@ -31,7 +31,7 @@ add_llvm_tool(opt
   PrintSCC.cpp
   opt.cpp
   )
-set_target_properties(opt PROPERTIES ENABLE_EXPORTS 1)
+export_executable_symbols(opt)
 
 if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
   target_link_libraries(opt Polly)