Skip to content

Commit

Permalink
Convert all usages of target_link_libraries to use PUBLIC/PRIVATE spe…
Browse files Browse the repository at this point in the history
…cifiers (#81924)

Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
  • Loading branch information
jkoritzinsky and lambdageek committed Feb 24, 2023
1 parent 4dd649b commit e11c334
Show file tree
Hide file tree
Showing 121 changed files with 347 additions and 318 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/debug/createdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if(CLR_CMAKE_HOST_WIN32)
)

target_link_libraries(createdump
PRIVATE
kernel32.lib
${STATIC_MT_CRT_LIB}
advapi32.lib
Expand Down Expand Up @@ -83,6 +84,7 @@ else()
endif(CLR_CMAKE_HOST_OSX)

target_link_libraries(createdump
PRIVATE
corguids
dbgutil
# share the PAL in the dac module
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/dlls/mscordbi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ if(CLR_CMAKE_HOST_WIN32)
${STATIC_MT_VCRT_LIB}
)

target_link_libraries(mscordbi ${COREDBI_LIBRARIES})
target_link_libraries(mscordbi PRIVATE ${COREDBI_LIBRARIES})

elseif(CLR_CMAKE_HOST_UNIX)

Expand All @@ -114,7 +114,7 @@ elseif(CLR_CMAKE_HOST_UNIX)
# COREDBI_LIBRARIES is mentioned twice because ld is one pass linker and will not find symbols
# if they are defined after they are used. Having all libs twice makes sure that ld will actually
# find all symbols.
target_link_libraries(mscordbi ${COREDBI_LIBRARIES} ${COREDBI_LIBRARIES})
target_link_libraries(mscordbi PRIVATE ${COREDBI_LIBRARIES} ${COREDBI_LIBRARIES})

add_dependencies(mscordbi mscordaccore)

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/gc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ convert_to_absolute_path(GC_SOURCES ${GC_SOURCES})

add_library_clr(clrgc SHARED ${GC_SOURCES})
add_dependencies(clrgc eventing_headers)
target_link_libraries(clrgc ${GC_LINK_LIBRARIES})
target_link_libraries(clrgc PRIVATE ${GC_LINK_LIBRARIES})
install_clr(TARGETS clrgc DESTINATIONS . COMPONENT runtime)

add_definitions(-DBUILD_AS_STANDALONE)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/gc/sample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ add_executable_clr(gcsample
)

if(CLR_CMAKE_TARGET_WIN32)
target_link_libraries(gcsample ${GC_LINK_LIBRARIES})
target_link_libraries(gcsample PRIVATE ${GC_LINK_LIBRARIES})
endif()
7 changes: 4 additions & 3 deletions src/coreclr/hosts/corerun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_executable_clr(corerun

if(CLR_CMAKE_HOST_WIN32)
target_link_libraries(corerun
PRIVATE
advapi32.lib
oleaut32.lib
uuid.lib
Expand All @@ -27,13 +28,13 @@ if(CLR_CMAKE_HOST_WIN32)
${STATIC_MT_VCRT_LIB}
)
else(CLR_CMAKE_HOST_WIN32)
target_link_libraries(corerun ${CMAKE_DL_LIBS})
target_link_libraries(corerun PRIVATE ${CMAKE_DL_LIBS})
# Required to expose symbols for global symbol discovery
target_link_libraries(corerun -rdynamic)
target_link_libraries(corerun PRIVATE -rdynamic)

# Android implements pthread natively
if(NOT CLR_CMAKE_TARGET_ANDROID)
target_link_libraries(corerun pthread)
target_link_libraries(corerun PRIVATE pthread)
endif()
endif(CLR_CMAKE_HOST_WIN32)

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/hosts/coreshim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_library_clr(CoreShim
)

target_link_libraries(CoreShim
PRIVATE
utilcodestaticnohost
advapi32.lib
oleaut32.lib
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/ilasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ endif(CLR_CMAKE_TARGET_WIN32)

if(CLR_CMAKE_HOST_UNIX)
target_link_libraries(ilasm
PRIVATE
${ILASM_LINK_LIBRARIES}
utilcodestaticnohost
mscorrc
Expand All @@ -118,6 +119,7 @@ if(CLR_CMAKE_HOST_UNIX)
)
else()
target_link_libraries(ilasm
PRIVATE
${ILASM_LINK_LIBRARIES}
ole32
oleaut32
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/ildasm/exe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ endif(CLR_CMAKE_HOST_WIN32)

if(CLR_CMAKE_HOST_UNIX)
target_link_libraries(ildasm
PRIVATE
${ILDASM_LINK_LIBRARIES}
mscorrc
coreclrpal
Expand All @@ -107,6 +108,7 @@ if(CLR_CMAKE_HOST_UNIX)
)
else()
target_link_libraries(ildasm
PRIVATE
${ILDASM_LINK_LIBRARIES}
ole32
oleaut32
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ function(add_jit jitName)
set_property(TARGET ${jitName} APPEND_STRING PROPERTY LINK_DEPENDS ${JIT_EXPORTS_FILE})

target_link_libraries(${jitName}
PRIVATE
${JIT_LINK_LIBRARIES}
${JIT_ARCH_LINK_LIBRARIES}
)
Expand Down
11 changes: 9 additions & 2 deletions src/coreclr/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ if(CLR_CMAKE_TARGET_OSX)
find_library(SECURITY Security)
find_library(SYSTEM System)
target_link_libraries(coreclrpal
PUBLIC
${COREFOUNDATION}
${CORESERVICES}
${SECURITY}
Expand All @@ -282,6 +283,7 @@ endif(CLR_CMAKE_TARGET_OSX)

if(CLR_CMAKE_TARGET_FREEBSD)
target_link_libraries(coreclrpal
PUBLIC
pthread
rt
${UNWIND_LIBS}
Expand All @@ -292,27 +294,30 @@ if(CLR_CMAKE_TARGET_LINUX)
# On Android, we don't need to link with gcc_s, pthread and rt
if(NOT CLR_CMAKE_TARGET_ANDROID)
target_link_libraries(coreclrpal
PUBLIC
gcc_s
pthread
rt
)
else(NOT CLR_CMAKE_TARGET_ANDROID)
target_link_libraries(coreclrpal
PUBLIC
${ANDROID_GLOB}
${LZMA})
endif(NOT CLR_CMAKE_TARGET_ANDROID)

target_link_libraries(coreclrpal
PUBLIC
dl
)

if(CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
target_link_libraries(coreclrpal ${UNWIND_LIBS})
target_link_libraries(coreclrpal PUBLIC ${UNWIND_LIBS})
endif(CLR_CMAKE_USE_SYSTEM_LIBUNWIND)

# bundled libunwind requires using libucontext on alpine and x86 and ppc64le
if(CLR_CMAKE_TARGET_ALPINE_LINUX AND (CLR_CMAKE_TARGET_ARCH_I386 OR CLR_CMAKE_TARGET_ARCH_POWERPC64))
target_link_libraries(coreclrpal ucontext)
target_link_libraries(coreclrpal PUBLIC ucontext)
endif(CLR_CMAKE_TARGET_ALPINE_LINUX AND (CLR_CMAKE_TARGET_ARCH_I386 OR CLR_CMAKE_TARGET_ARCH_POWERPC64))

endif(CLR_CMAKE_TARGET_LINUX)
Expand All @@ -324,6 +329,7 @@ if(CLR_CMAKE_TARGET_NETBSD)
add_definitions(-D_KMEMUSER)
find_library(KVM kvm)
target_link_libraries(coreclrpal
PUBLIC
pthread
rt
${UNWIND}
Expand All @@ -333,6 +339,7 @@ endif(CLR_CMAKE_TARGET_NETBSD)

if(CLR_CMAKE_TARGET_SUNOS)
target_link_libraries(coreclrpal
PUBLIC
pthread
rt
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ add_dependencies(coreclrtraceptprovider generated_eventing_headers)
find_library(LTTNG NAMES lttng-ust)

target_link_libraries(coreclrtraceptprovider
PRIVATE
${LTTNG}
)

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/pal/tests/palsuite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ add_executable_clr(paltests
add_dependencies(paltests coreclrpal)

target_link_libraries(paltests
PUBLIC
${COMMON_TEST_LIBRARIES}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if(FEATURE_EVENT_TRACE)
endif(CLR_CMAKE_HOST_LINUX)
endif(FEATURE_EVENT_TRACE)

target_link_libraries(eventprovidertest ${EVENT_PROVIDER_DEPENDENCIES} coreclrpal)
target_link_libraries(eventprovidertest PUBLIC ${EVENT_PROVIDER_DEPENDENCIES} coreclrpal)
add_dependencies(eventprovidertest eventing_headers)

install (TARGETS eventprovidertest DESTINATION paltests/eventprovider COMPONENT paltests EXCLUDE_FROM_ALL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ add_dependencies(paltest_pal_sxs_test1_dll1
)

target_link_libraries(paltest_pal_sxs_test1_dll1
PUBLIC
${COMMON_TEST_LIBRARIES}
m
coreclrpal
Expand Down Expand Up @@ -71,6 +72,7 @@ add_dependencies(paltest_pal_sxs_test1_dll2
)

target_link_libraries(paltest_pal_sxs_test1_dll2
PUBLIC
${COMMON_TEST_LIBRARIES}
)

Expand All @@ -86,6 +88,7 @@ add_dependencies(paltest_pal_sxs_test1
)

target_link_libraries(paltest_pal_sxs_test1
PUBLIC
paltest_pal_sxs_test1_dll1
paltest_pal_sxs_test1_dll2
)
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/tools/StressLogAnalyzer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
add_executable_clr(StressLogAnalyzer StressLogAnalyzer.cpp StressLogDump.cpp StressLogPlugin.cpp)

if(CLR_CMAKE_TARGET_WIN32)
target_link_libraries(StressLogAnalyzer
PRIVATE
${STATIC_MT_CRT_LIB}
${STATIC_MT_VCRT_LIB}
)
else()
target_link_libraries(StressLogAnalyzer
PRIVATE
coreclrpal
)
endif(CLR_CMAKE_TARGET_WIN32)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/tools/superpmi/mcs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ target_precompile_headers(mcs PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:standardpch.h>"

if(CLR_CMAKE_HOST_UNIX)
target_link_libraries(mcs
PRIVATE
utilcodestaticnohost
mscorrc
coreclrpal
palrt
)
else()
target_link_libraries(mcs
PRIVATE
advapi32.lib
${STATIC_MT_CRT_LIB}
${STATIC_MT_CPP_LIB}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ set_property(TARGET superpmi-shim-collector APPEND_STRING PROPERTY LINK_DEPENDS

if(CLR_CMAKE_HOST_UNIX)
target_link_libraries(superpmi-shim-collector
PRIVATE
utilcodestaticnohost
mscorrc
coreclrpal
palrt
)
else()
target_link_libraries(superpmi-shim-collector
PRIVATE
advapi32.lib
${STATIC_MT_CRT_LIB}
${STATIC_MT_CPP_LIB}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ target_precompile_headers(superpmi-shim-counter PRIVATE "$<$<COMPILE_LANGUAGE:CX

if(CLR_CMAKE_HOST_UNIX)
target_link_libraries(superpmi-shim-counter
PRIVATE
utilcodestaticnohost
mscorrc
coreclrpal
palrt
)
else()
target_link_libraries(superpmi-shim-counter
PRIVATE
advapi32.lib
${STATIC_MT_CRT_LIB}
${STATIC_MT_CPP_LIB}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ target_precompile_headers(superpmi-shim-simple PRIVATE "$<$<COMPILE_LANGUAGE:CXX

if(CLR_CMAKE_HOST_UNIX)
target_link_libraries(superpmi-shim-simple
PRIVATE
utilcodestaticnohost
mscorrc
coreclrpal
palrt
)
else()
target_link_libraries(superpmi-shim-simple
PRIVATE
advapi32.lib
${STATIC_MT_CRT_LIB}
${STATIC_MT_CPP_LIB}
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/tools/superpmi/superpmi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ target_precompile_headers(superpmi PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:standardpc

if(CLR_CMAKE_HOST_UNIX)
target_link_libraries(superpmi
PRIVATE
utilcodestaticnohost
mscorrc
coreclrpal
palrt
)
else()
target_link_libraries(superpmi
PRIVATE
version.lib
advapi32.lib
${STATIC_MT_CRT_LIB}
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/utilcode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ target_sources(utilcode INTERFACE $<TARGET_OBJECTS:utilcode_obj>)
add_library_clr(utilcodestaticnohost STATIC ${UTILCODE_STATICNOHOST_SOURCES})

if(CLR_CMAKE_HOST_UNIX)
target_link_libraries(utilcodestaticnohost nativeresourcestring)
target_link_libraries(utilcode_dac nativeresourcestring)
target_link_libraries(utilcodestaticnohost PUBLIC nativeresourcestring)
target_link_libraries(utilcode_dac PUBLIC nativeresourcestring)
target_link_libraries(utilcode INTERFACE nativeresourcestring)
add_dependencies(utilcode_dac coreclrpal)
add_dependencies(utilcode_obj coreclrpal)
Expand Down
2 changes: 1 addition & 1 deletion src/mono/dlls/dbgshim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ if(CLR_CMAKE_HOST_UNIX)
)
endif()

target_link_libraries(dbgshim ${DBGSHIM_LIBRARIES} monoapi)
target_link_libraries(dbgshim PRIVATE ${DBGSHIM_LIBRARIES} monoapi)
install(TARGETS dbgshim DESTINATION lib)
2 changes: 1 addition & 1 deletion src/mono/dlls/mscordbi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,5 @@ if(CLR_CMAKE_HOST_UNIX)
)
endif()

target_link_libraries(mscordbi ${COREDBI_LIBRARIES} monoapi)
target_link_libraries(mscordbi PRIVATE ${COREDBI_LIBRARIES} monoapi)
install(TARGETS mscordbi DESTINATION lib)
2 changes: 1 addition & 1 deletion src/mono/mono/eventpipe/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if(ENABLE_PERFTRACING)
set(CMAKE_SKIP_RPATH 1)
add_executable(ep-test ${EVENTPIPE_TEST_SOURCES} ${EVENTPIPE_TEST_HEADERS})
target_sources(ep-test PRIVATE "${mono-components-objects}")
target_link_libraries(ep-test monosgen-static ${OS_LIBS} ${LLVM_LIBS} ${ICU_LIBS} ${Z_LIBS} monoapi)
target_link_libraries(ep-test PUBLIC monosgen-static ${OS_LIBS} ${LLVM_LIBS} ${ICU_LIBS} ${Z_LIBS} monoapi)
if(ICU_LDFLAGS)
set_target_properties(ep-test PROPERTIES LINK_FLAGS ${ICU_LDFLAGS})
endif()
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/mini/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ endif()

if(ENABLE_INTERP_LIB)
add_library(mono-ee-interp STATIC "${interp_sources}")
target_link_libraries(mono-ee-interp monoapi eglib_api)
target_link_libraries(mono-ee-interp PRIVATE monoapi eglib_api)
target_include_directories(mono-ee-interp PRIVATE ${PROJECT_BINARY_DIR}/../..
${PROJECT_SOURCE_DIR}/../..
${PROJECT_SOURCE_DIR}/..)
Expand Down Expand Up @@ -412,7 +412,7 @@ if(NOT DISABLE_SHARED_LIBS)
install(TARGETS monosgen-shared LIBRARY)
if(HOST_WIN32 AND TARGET_AMD64)
add_library(monosgen-shared-dac SHARED "mini-windows-dlldac.c")
target_link_libraries(monosgen-shared-dac monoapi eglib_api)
target_link_libraries(monosgen-shared-dac PRIVATE monoapi eglib_api)
set_target_properties(monosgen-shared-dac PROPERTIES OUTPUT_NAME ${MONO_SHARED_LIB_NAME}-dac)
endif()

Expand Down
Loading

0 comments on commit e11c334

Please sign in to comment.