Skip to content

Commit e2ac1fa

Browse files
author
Fomenko, Evarist M
committed
build: mkldnn compat: put symlinks together with generate lib
CMake allows overriding the place where the libraries are being generated using: ``` cmake set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY some_place) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY some_place) ``` In this case, the `libdnnl.so` will be put in `some_place` instead of usual `${CMAKE_CURRENT_BINARY_DIR}` location. However, we generate the compat symlinks in the latter location. This makes them point to non-existent library, which in turn: 1. Invalidates the symlink; 2. Betrays users expectations on find the library (which is though a symlink) in the proper location `some_place`. 3. Makes `make` regenerate the symlink all the time no matter whether it exists or not. That happens because `make` checks whether the target (symlink) is _older_ than the prerequisite (`libdnnl.so`). It seems that the date for symlink is checked by the date of the object it points to. Since the symlink points to nowhere, the target is considered always outdated. This closes #743.
1 parent f72bfc5 commit e2ac1fa

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/CMakeLists.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,19 @@ else()
164164
endif()
165165
foreach(ver "" ${vers})
166166
set_ternary(ext_and_ver APPLE "${ver}${ext}" "${ext}${ver}")
167-
add_custom_command(OUTPUT libmkldnn${ext_and_ver}
167+
get_property(lib_location TARGET ${LIB_NAME} PROPERTY LIBRARY_OUTPUT_DIRECTORY)
168+
if(lib_location)
169+
set(compat_link "${lib_location}/libmkldnn${ext_and_ver}")
170+
else()
171+
set(compat_link "${CMAKE_CURRENT_BINARY_DIR}/libmkldnn${ext_and_ver}")
172+
endif()
173+
add_custom_command(OUTPUT ${compat_link}
168174
# to make the next command work fine
169-
COMMAND ${CMAKE_COMMAND} -E remove -f libmkldnn${ext_and_ver}
170-
COMMAND ${CMAKE_COMMAND} -E create_symlink libdnnl${ext_and_ver} libmkldnn${ext_and_ver}
175+
COMMAND ${CMAKE_COMMAND} -E remove -f ${compat_link}
176+
COMMAND ${CMAKE_COMMAND} -E create_symlink libdnnl${ext_and_ver} ${compat_link}
171177
DEPENDS ${LIB_NAME})
172-
add_custom_target(compat_libs${ver} ALL
173-
DEPENDS libmkldnn${ext_and_ver})
174-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libmkldnn${ext_and_ver}
175-
DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
178+
add_custom_target(compat_libs${ver} ALL DEPENDS ${compat_link})
179+
install(FILES ${compat_link} DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
176180
endforeach()
177181
endif()
178182

0 commit comments

Comments
 (0)