Skip to content

Commit

Permalink
build: separate public and public link dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Dubtsov committed Feb 25, 2019
1 parent bf1c6ad commit 25959d1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
4 changes: 3 additions & 1 deletion cmake/MKL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,13 @@ if(HAVE_MKL)
set(MKLDLL "")
get_filename_component(MKLLIBPATH "${MKLLIB}" PATH)
set_static_mkl_libs(${MKLLIBPATH})
list(APPEND EXTRA_STATIC_LIBS ${MKLLIB})
else()
list(APPEND EXTRA_SHARED_LIBS ${MKLLIB})
endif()

add_definitions(-DUSE_MKL -DUSE_CBLAS)
include_directories(AFTER ${MKLINC})
list(APPEND mkldnn_LINKER_LIBS ${MKLLIB})

set(MSG "Intel(R) MKL:")
message(STATUS "${MSG} include ${MKLINC}")
Expand Down
4 changes: 2 additions & 2 deletions cmake/OpenMP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ macro(use_intel_omp_rt)
NAMES "libiomp5.dll" "libiomp5md.dll"
HINTS ${MKLIOMP5DLL})
endif()
list(APPEND EXTRA_LIBS ${IOMP5LIB})
list(APPEND EXTRA_SHARED_LIBS ${IOMP5LIB})
else()
if (MKLDNN_THREADING STREQUAL "OMP:INTEL")
message(${_omp_severity} "Intel OpenMP runtime could not be found. "
Expand All @@ -87,7 +87,7 @@ elseif(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
append(CMAKE_C_FLAGS "-Xclang -fopenmp")
append(CMAKE_CXX_FLAGS "-Xclang -fopenmp")
set(OpenMP_CXX_FOUND true)
list(APPEND EXTRA_LIBS ${IOMP5LIB})
list(APPEND EXTRA_SHARED_LIBS ${IOMP5LIB})
else()
find_package(OpenMP)
#newer version for findOpenMP (>= v. 3.9)
Expand Down
2 changes: 1 addition & 1 deletion cmake/TBB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ elseif(UNIX)
endif()

set_threading("TBB")
list(APPEND mkldnn_LINKER_LIBS ${TBB_IMPORTED_TARGETS})
list(APPEND EXTRA_SHARED_LIBS ${TBB_IMPORTED_TARGETS})

message(STATUS "Intel(R) TBB: ${TBBROOT}")
2 changes: 1 addition & 1 deletion cmake/profiling.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ if("${VTUNEROOT}" STREQUAL "")
message(STATUS "VTune profiling environment is unset")
else()
set_ternary(JITPROFLIB MSVC "jitprofiling.lib" "libjitprofiling.a")
list(APPEND EXTRA_LIBS "${VTUNEROOT}/lib64/${JITPROFLIB}")
list(APPEND EXTRA_STATIC_LIBS "${VTUNEROOT}/lib64/${JITPROFLIB}")
message(STATUS "VTune profiling environment is set")
endif()
10 changes: 9 additions & 1 deletion cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ endfunction()
# arg4 -- (optional) list of extra library dependencies
function(register_exe name srcs test)
add_executable(${name} ${srcs})
target_link_libraries(${name} ${LIB_NAME} ${EXTRA_LIBS} ${ARGV3})
target_link_libraries(${name} ${LIB_NAME} ${EXTRA_SHARED_LIBS} ${ARGV3})
if("${test}" STREQUAL "test")
add_test(${name} ${name})
maybe_configure_windows_test(${name} TEST)
Expand Down Expand Up @@ -104,3 +104,11 @@ macro(append_to_windows_path_list path_list path)
"${append_to_windows_path_list_tmp__}")
endif()
endmacro()

# Strip path from all files in a list
macro(strip_paths out_list path_list)
foreach(item ${path_list})
get_filename_component(basename "${item}" NAME)
list(APPEND ${out_list} "${basename}")
endforeach(item)
endmacro()
16 changes: 10 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,21 @@ if(WIN32)
set(CTESTCONFIG_PATH "${CTESTCONFIG_PATH}" PARENT_SCOPE)
endif()

target_link_libraries(
${TARGET_NAME}
LINK_PUBLIC
$<BUILD_INTERFACE:${${TARGET_NAME}_LINKER_LIBS}>
$<BUILD_INTERFACE:${EXTRA_LIBS}>
)
# This is rather ugly, but required for the generator expressions to
# expand correctly
foreach(l IN LISTS EXTRA_SHARED_LIBS EXTRA_STATIC_LIBS)
target_link_libraries(${TARGET_NAME} LINK_PRIVATE $<BUILD_INTERFACE:${l}>)
endforeach()
strip_paths(EXTRA_SHARED_LIBS_PUBLIC "${EXTRA_SHARED_LIBS}")
foreach(l IN LISTS EXTRA_SHARED_LIBS_PUBLIC)
target_link_libraries(${TARGET_NAME} LINK_PUBLIC $<INSTALL_INTERFACE:${l}>)
endforeach()

set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 11)
set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET ${TARGET_NAME} PROPERTY VERSION "${PROJECT_VERSION}.0")
set_property(TARGET ${TARGET_NAME} PROPERTY SOVERSION "0")
set_property(TARGET ${TARGET_NAME} PROPERTY PUBLIC_HEADER ${HEADERS})

install(TARGETS ${TARGET_NAME}
EXPORT "${TARGETS_EXPORT_NAME}"
Expand Down

0 comments on commit 25959d1

Please sign in to comment.