diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -1180,6 +1180,13 @@ umbrella_lit_testsuite_begin(check-all) endif() +if (NOT BUILD_SHARED_LIBS AND NOT APPLE AND + (NOT (WIN32 OR CYGWIN) OR (MINGW AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND + NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX") AND + NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET) + set(LLVM_CAN_USE_HIDDEN_VISIBILITY ON) +endif() + # Put this before tblgen. Else we have a circular dependence. add_subdirectory(lib/Demangle) add_subdirectory(lib/Support) diff --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt --- a/llvm/lib/CodeGen/CMakeLists.txt +++ b/llvm/lib/CodeGen/CMakeLists.txt @@ -1,3 +1,7 @@ +if (LLVM_CAN_USE_HIDDEN_VISIBILITY) + set(CMAKE_CXX_VISIBILITY_PRESET hidden) +endif() + if (DEFINED LLVM_HAVE_TF_AOT OR DEFINED LLVM_HAVE_TF_API) include(TensorFlowCompile) set(LLVM_RAEVICT_MODEL_PATH_DEFAULT "models/regalloc-eviction") diff --git a/llvm/lib/Target/CMakeLists.txt b/llvm/lib/Target/CMakeLists.txt --- a/llvm/lib/Target/CMakeLists.txt +++ b/llvm/lib/Target/CMakeLists.txt @@ -21,12 +21,7 @@ # When building shared objects for each target there are some internal APIs # that are used across shared objects which we can't hide. -if (NOT BUILD_SHARED_LIBS AND NOT APPLE AND - (NOT (WIN32 OR CYGWIN) OR (MINGW AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND - NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX") AND - NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET) - # Set default visibility to hidden, so we don't export all the Target classes - # in libLLVM.so. +if (LLVM_CAN_USE_HIDDEN_VISIBILITY) set(CMAKE_CXX_VISIBILITY_PRESET hidden) endif()