CMake: Make dependencies private (#2697)

* CMake: Private dependencies

Closes #2694

* Fix build error

Co-authored-by: Davis King <davis@dlib.net>
This commit is contained in:
Julien Schueller 2022-12-16 04:13:19 +01:00 committed by GitHub
parent f932f33b10
commit 2ac3cdbad7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -275,9 +275,10 @@ if (NOT TARGET dlib)
test_for_odr_violations.cpp
)
set(dlib_needed_libraries)
set(dlib_needed_includes)
set(dlib_needed_public_libraries)
set(dlib_needed_public_includes)
set(dlib_needed_private_libraries)
set(dlib_needed_private_includes)
if (DLIB_ISO_CPP_ONLY)
add_library(dlib ${source_files} )
@ -325,15 +326,15 @@ if (NOT TARGET dlib)
if(UNIX)
set(CMAKE_THREAD_PREFER_PTHREAD ON)
find_package(Threads REQUIRED)
set(dlib_needed_libraries ${dlib_needed_libraries} ${CMAKE_THREAD_LIBS_INIT})
list (APPEND dlib_needed_private_libraries ${CMAKE_THREAD_LIBS_INIT})
endif()
# we want to link to the right stuff depending on our platform.
if (WIN32 AND NOT CYGWIN) ###############################################################################
if (DLIB_NO_GUI_SUPPORT)
set (dlib_needed_libraries ws2_32 winmm)
list (APPEND dlib_needed_private_libraries ws2_32 winmm)
else()
set (dlib_needed_libraries ws2_32 winmm comctl32 gdi32 imm32)
list (APPEND dlib_needed_private_libraries ws2_32 winmm comctl32 gdi32 imm32)
endif()
elseif(APPLE) ############################################################################
set(CMAKE_MACOSX_RPATH 1)
@ -347,8 +348,8 @@ if (NOT TARGET dlib)
list (REMOVE_ITEM X11_INCLUDE_DIR ${ITR})
endif ()
endforeach(ITR)
include_directories(${X11_INCLUDE_DIR})
set (dlib_needed_libraries ${dlib_needed_libraries} ${X11_LIBRARIES})
list (APPEND dlib_needed_public_includes ${X11_INCLUDE_DIR})
list (APPEND dlib_needed_public_libraries ${X11_LIBRARIES})
else()
find_library(xlib X11)
# Make sure X11 is in the include path. Note that we look for
@ -362,8 +363,8 @@ if (NOT TARGET dlib)
)
if (xlib AND xlib_path)
get_filename_component(x11_path ${xlib_path} PATH CACHE)
include_directories(${x11_path})
set(dlib_needed_libraries ${dlib_needed_libraries} ${xlib} )
list (APPEND dlib_needed_public_includes ${x11_path})
list (APPEND dlib_needed_public_libraries ${xlib})
set(X11_FOUND 1)
endif()
endif()
@ -383,14 +384,14 @@ if (NOT TARGET dlib)
# link to the socket library if it exists. this is something you need on solaris
find_library(socketlib socket)
if (socketlib)
set (dlib_needed_libraries ${dlib_needed_libraries} ${socketlib})
list (APPEND dlib_needed_private_libraries ${socketlib})
endif ()
if (NOT DLIB_NO_GUI_SUPPORT)
include(FindX11)
if (X11_FOUND)
include_directories(${X11_INCLUDE_DIR})
set (dlib_needed_libraries ${dlib_needed_libraries} ${X11_LIBRARIES})
list (APPEND dlib_needed_private_includes ${X11_INCLUDE_DIR})
list (APPEND dlib_needed_private_libraries ${X11_LIBRARIES})
else()
message(" *****************************************************************************")
message(" *** DLIB GUI SUPPORT DISABLED BECAUSE X11 DEVELOPMENT LIBRARIES NOT FOUND ***")
@ -422,8 +423,8 @@ if (NOT TARGET dlib)
if (DLIB_GIF_SUPPORT)
find_package(GIF QUIET)
if (GIF_FOUND)
set (dlib_needed_includes ${dlib_needed_includes} ${GIF_INCLUDE_DIR})
set (dlib_needed_libraries ${dlib_needed_libraries} ${GIF_LIBRARY})
list (APPEND dlib_needed_public_includes ${GIF_INCLUDE_DIR})
list (APPEND dlib_needed_public_libraries ${GIF_LIBRARY})
else()
set(DLIB_GIF_SUPPORT OFF CACHE STRING ${DLIB_GIF_SUPPORT_STR} FORCE )
toggle_preprocessor_switch(DLIB_GIF_SUPPORT)
@ -433,8 +434,8 @@ if (NOT TARGET dlib)
if (DLIB_PNG_SUPPORT)
include(cmake_utils/find_libpng.cmake)
if (PNG_FOUND)
include_directories(${PNG_INCLUDE_DIR})
set (dlib_needed_libraries ${dlib_needed_libraries} ${PNG_LIBRARIES})
list (APPEND dlib_needed_private_includes ${PNG_INCLUDE_DIR})
list (APPEND dlib_needed_private_libraries ${PNG_LIBRARIES})
else()
# If we can't find libpng then statically compile it in.
include_directories(external/libpng external/zlib)
@ -495,8 +496,8 @@ if (NOT TARGET dlib)
if (DLIB_JPEG_SUPPORT)
include(cmake_utils/find_libjpeg.cmake)
if (JPEG_FOUND)
include_directories(${JPEG_INCLUDE_DIR})
set (dlib_needed_libraries ${dlib_needed_libraries} ${JPEG_LIBRARY})
list (APPEND dlib_needed_private_includes ${JPEG_INCLUDE_DIR})
list (APPEND dlib_needed_private_libraries ${JPEG_LIBRARY})
else()
# If we can't find libjpeg then statically compile it in.
add_definitions(-DDLIB_JPEG_STATIC)
@ -555,8 +556,8 @@ if (NOT TARGET dlib)
if (DLIB_WEBP_SUPPORT)
include(cmake_utils/find_libwebp.cmake)
if (WEBP_FOUND)
include_directories(${WEBP_INCLUDE_DIR})
set (dlib_needed_libraries ${dlib_needed_libraries} ${WEBP_LIBRARY})
list (APPEND dlib_needed_private_includes ${WEBP_INCLUDE_DIR})
list (APPEND dlib_needed_private_libraries ${WEBP_LIBRARY})
set(source_files ${source_files}
image_loader/webp_loader.cpp
image_saver/save_webp.cpp
@ -581,7 +582,7 @@ if (NOT TARGET dlib)
if (DLIB_USE_BLAS)
if (blas_found)
set (dlib_needed_libraries ${dlib_needed_libraries} ${blas_libraries})
list (APPEND dlib_needed_private_libraries ${blas_libraries})
else()
set(DLIB_USE_BLAS OFF CACHE STRING ${DLIB_USE_BLAS_STR} FORCE )
toggle_preprocessor_switch(DLIB_USE_BLAS)
@ -590,7 +591,7 @@ if (NOT TARGET dlib)
if (DLIB_USE_LAPACK)
if (lapack_found)
set (dlib_needed_libraries ${dlib_needed_libraries} ${lapack_libraries})
list (APPEND dlib_needed_private_libraries ${lapack_libraries})
if (lapack_with_underscore)
set(LAPACK_FORCE_UNDERSCORE 1)
enable_preprocessor_switch(LAPACK_FORCE_UNDERSCORE)
@ -606,8 +607,8 @@ if (NOT TARGET dlib)
if (DLIB_USE_MKL_FFT)
if (found_intel_mkl AND found_intel_mkl_headers)
set (dlib_needed_includes ${dlib_needed_includes} ${mkl_include_dir})
set (dlib_needed_libraries ${dlib_needed_libraries} ${mkl_libraries})
list (APPEND dlib_needed_public_includes ${mkl_include_dir})
list (APPEND dlib_needed_public_libraries ${mkl_libraries})
else()
set(DLIB_USE_MKL_FFT OFF CACHE STRING ${DLIB_USE_MKL_FFT_STR} FORCE )
toggle_preprocessor_switch(DLIB_USE_MKL_FFT)
@ -778,15 +779,13 @@ if (NOT TARGET dlib)
cuda/cuda_data_ptr.cpp
cuda/gpu_data.cpp
)
set(dlib_needed_libraries ${dlib_needed_libraries}
${CUDA_CUBLAS_LIBRARIES}
${cudnn}
${CUDA_curand_LIBRARY}
${CUDA_cusolver_LIBRARY}
${CUDA_CUDART_LIBRARY}
)
list (APPEND dlib_needed_private_libraries ${CUDA_CUBLAS_LIBRARIES})
list (APPEND dlib_needed_private_libraries ${cudnn})
list (APPEND dlib_needed_private_libraries ${CUDA_curand_LIBRARY})
list (APPEND dlib_needed_private_libraries ${CUDA_cusolver_LIBRARY})
list (APPEND dlib_needed_private_libraries ${CUDA_CUDART_LIBRARY})
if(openmp_libraries)
list(APPEND dlib_needed_libraries ${openmp_libraries})
list (APPEND dlib_needed_private_libraries ${openmp_libraries})
endif()
include_directories(${cudnn_include})
@ -807,8 +806,8 @@ if (NOT TARGET dlib)
# make sure sqlite3.h is in the include path
find_path(sqlite_path sqlite3.h)
if (sqlite AND sqlite_path)
set(dlib_needed_includes ${dlib_needed_includes} ${sqlite_path})
set(dlib_needed_libraries ${dlib_needed_libraries} ${sqlite} )
list (APPEND dlib_needed_public_includes ${sqlite_path})
list (APPEND dlib_needed_public_libraries ${sqlite} )
else()
set(DLIB_LINK_WITH_SQLITE3 OFF CACHE STRING ${DLIB_LINK_WITH_SQLITE3_STR} FORCE )
endif()
@ -822,8 +821,8 @@ if (NOT TARGET dlib)
# make sure fftw3.h is in the include path
find_path(fftw_path fftw3.h)
if (fftw AND fftw_path)
set(dlib_needed_includes ${dlib_needed_includes} ${fftw_path})
set(dlib_needed_libraries ${dlib_needed_libraries} ${fftw} )
list (APPEND dlib_needed_private_includes ${fftw_path})
list (APPEND dlib_needed_private_libraries ${fftw})
else()
set(DLIB_USE_FFTW OFF CACHE STRING ${DLIB_USE_FFTW_STR} FORCE )
toggle_preprocessor_switch(DLIB_USE_FFTW)
@ -837,7 +836,7 @@ if (NOT TARGET dlib)
if (DLIB_USE_CUDA)
# The old cuda_add_library() command doesn't support CMake's newer dependency
# stuff, so we have to set the include path manually still, which we do here.
include_directories(${dlib_needed_includes})
include_directories(${dlib_needed_public_includes})
cuda_add_library(dlib ${source_files} )
else()
add_library(dlib ${source_files} )
@ -849,9 +848,11 @@ if (NOT TARGET dlib)
target_include_directories(dlib
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
INTERFACE $<INSTALL_INTERFACE:include>
PUBLIC ${dlib_needed_includes}
PUBLIC ${dlib_needed_public_includes}
PRIVATE ${dlib_needed_private_includes}
)
target_link_libraries(dlib PUBLIC ${dlib_needed_libraries})
target_link_libraries(dlib PUBLIC ${dlib_needed_public_libraries})
target_link_libraries(dlib PRIVATE ${dlib_needed_private_libraries})
if (DLIB_IN_PROJECT_BUILD)
target_compile_options(dlib PUBLIC ${active_preprocessor_switches})
else()
@ -892,9 +893,9 @@ if (NOT TARGET dlib)
# Install the library
if (NOT DLIB_IN_PROJECT_BUILD)
string (REPLACE ";" " " pkg_config_dlib_needed_libraries "${dlib_needed_libraries}")
string (REPLACE ";" " " pkg_config_dlib_needed_libraries "${dlib_needed_public_libraries}")
# Make the -I include options for pkg-config
foreach (ITR ${dlib_needed_includes})
foreach (ITR ${dlib_needed_public_includes})
set (pkg_config_dlib_needed_includes "${pkg_config_dlib_needed_includes} -I${ITR}")
endforeach()
set_target_properties(dlib PROPERTIES