Skip to content

Commit

Permalink
Move install function to file
Browse files Browse the repository at this point in the history
  • Loading branch information
alxvth committed Sep 23, 2024
1 parent 5cf3240 commit 2438bca
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ build
x64
*.dir
*.bak
ExampleDependencies/cmake/install_dependencies.cmake
53 changes: 2 additions & 51 deletions ExampleDependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,57 +109,8 @@ install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION Plugins COMPONENT PLUGINS # Linux/Mac .so
)

install(CODE [[
if(WIN32)
set(PRE_EXCLUDE ".*[\\/]api-ms.*" ".*[\\/]ext-ms.*" ".*[\\/]hvsi.*" ".*[\\/]pdmutilities.*" ".*[\\/]wpaxholder.*" ".*[\\/]dxgi.*" ".*[\\/]uxtheme.*" ".*[\\/]d3d11.*" ".*[\\/]winmm.*" ".*[\\/]wldp.*")
set(POST_EXCLUDE ".*[\\/]system32[\\/].*\\.dll")
elseif(APPLE)
set(PRE_EXCLUDE "/usr/lib" "/System/")
set(POST_EXCLUDE "")
else()
set(PRE_EXCLUDE ".*/ld-linux-.*" ".*/linux-vdso.*" ".*/libm\\..*" ".*/libc\\..*" ".*/libpthread\\..*" ".*/libdl\\..*")
set(POST_EXCLUDE "")
endif()

function(install_deps LIBRARY)
file(INSTALL
DESTINATION "${CMAKE_INSTALL_PREFIX}/PluginDependencies/ExampleDependenciesPlugin"
TYPE SHARED_LIBRARY
FOLLOW_SYMLINK_CHAIN
FILES "${LIBRARY}"
)
endfunction()
file(GET_RUNTIME_DEPENDENCIES
EXECUTABLES "$<TARGET_FILE:ExampleDependenciesPlugin>"
RESOLVED_DEPENDENCIES_VAR RESOLVED_DEPS
UNRESOLVED_DEPENDENCIES_VAR UNRESOLVED_DEPS
CONFLICTING_DEPENDENCIES_PREFIX CONFLICTING_DEPS
DIRECTORIES "$<TARGET_FILE_DIR:ExampleDependenciesPlugin>" "$<TARGET_FILE_DIR:hwy>" "$<TARGET_FILE_DIR:hwy_contrib>"
PRE_EXCLUDE_REGEXES "${PRE_EXCLUDE}"
POST_EXCLUDE_REGEXES "${POST_EXCLUDE}"
)

message(STATUS "${PRE_EXCLUDE}")
message(STATUS "${POST_EXCLUDE}")
foreach(FILE ${RESOLVED_DEPS})
message(STATUS "Resolved: ${FILE}")
install_deps(${FILE})
endforeach()

foreach(FILE ${UNRESOLVED_DEPS})
message(STATUS "Unresolved: ${FILE}")
endforeach()

if(CONFLICTING_DEPS)
message(WARNING "Conflicting dependencies!")
foreach(FILE ${CONFLICTING_DEPS})
message(STATUS "Conflicting: ${FILE}")
endforeach()
endif()

]]
COMPONENT DEP_PLUGIN_PRINT
)
include(cmake/install_dependencies_utils.cmake)
install_dependencies(${PROJECT_NAME} "hwy" "hwy_contrib")

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Installing: Plugin files"
Expand Down
55 changes: 55 additions & 0 deletions ExampleDependencies/cmake/install_dependencies.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
install(CODE [[

if(WIN32)
set(PRE_EXCLUDE ".*[\\/]api-ms.*" ".*[\\/]ext-ms.*" ".*[\\/]hvsi.*" ".*[\\/]pdmutilities.*" ".*[\\/]wpaxholder.*" ".*[\\/]dxgi.*" ".*[\\/]uxtheme.*" ".*[\\/]d3d11.*" ".*[\\/]winmm.*" ".*[\\/]wldp.*")
set(POST_EXCLUDE ".*[\\/]system32[\\/].*\\.dll")
elseif(APPLE)
set(PRE_EXCLUDE "/usr/lib" "/System/")
set(POST_EXCLUDE "")
else()
set(PRE_EXCLUDE ".*/ld-linux-.*" ".*/linux-vdso.*" ".*/libm\\..*" ".*/libc\\..*" ".*/libpthread\\..*" ".*/libdl\\..*")
set(POST_EXCLUDE "")
endif()

message(STATUS "PRE_EXCLUDE: ${PRE_EXCLUDE}")
message(STATUS "POST_EXCLUDE: ${POST_EXCLUDE}")
message(STATUS "DEPENDENCIES_FOLDERS: ${DEPENDENCIES_FOLDERS}")

function(install_deps LIBRARY)
file(INSTALL
DESTINATION "${CMAKE_INSTALL_PREFIX}/PluginDependencies/@MAIN_PROJECT_TARGET@"
TYPE SHARED_LIBRARY
FOLLOW_SYMLINK_CHAIN
FILES "${LIBRARY}"
)
endfunction()

file(GET_RUNTIME_DEPENDENCIES
EXECUTABLES "$<TARGET_FILE:@MAIN_PROJECT_TARGET@>"
RESOLVED_DEPENDENCIES_VAR RESOLVED_DEPS
UNRESOLVED_DEPENDENCIES_VAR UNRESOLVED_DEPS
CONFLICTING_DEPENDENCIES_PREFIX CONFLICTING_DEPS
DIRECTORIES @DEPENDENCIES_FOLDERS@
PRE_EXCLUDE_REGEXES "${PRE_EXCLUDE}"
POST_EXCLUDE_REGEXES "${POST_EXCLUDE}"
)

foreach(FILE ${RESOLVED_DEPS})
message(STATUS "Resolved: ${FILE}")
install_deps(${FILE})
endforeach()

foreach(FILE ${UNRESOLVED_DEPS})
message(STATUS "Unresolved: ${FILE}")
endforeach()

if(CONFLICTING_DEPS)
message(WARNING "Conflicting dependencies!")
foreach(FILE ${CONFLICTING_DEPS})
message(STATUS "Conflicting: ${FILE}")
endforeach()
endif()

]]
COMPONENT DEP_PLUGIN_PRINT
)
13 changes: 13 additions & 0 deletions ExampleDependencies/cmake/install_dependencies_utils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function(install_dependencies main_target)

set(MAIN_PROJECT_TARGET ${main_target})

foreach(TARGET_STR IN LISTS ARGV)
list(APPEND DEPENDENCIES_FOLDERS "$<TARGET_FILE_DIR:${TARGET_STR}>")
endforeach()

include(CMakePackageConfigHelpers)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/install_dependencies.cmake.in" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/install_dependencies.cmake" @ONLY)

include(cmake/install_dependencies.cmake)
endfunction()

0 comments on commit 2438bca

Please sign in to comment.