The cmake script FindwxWidgets create the list of all .lib files.
However this script does not provide the list of wxWidgets dlls.
What is the CMake script to store in a list all wxWidgets Dll file for debug and release targets ?
ps: I found some project based on wxWidgets and CMake but they all link statically with wxWidgets.
Work in progress:
The current dirty solution is to fetch all dll's in the wxWidgets directory and install in the same folder as the exe. However there is no filter for used components as it is not linked with the find_package command.
# Copy wxWidgets Dll's
# extract folder path
file(GLOB wxwidgets_dlls "${wxWidgets_LIB_DIR}/*.dll")
list(APPEND WXWidgets_DLL_Slash "")
foreach(WXWidgets_DLL ${wxwidgets_dlls})
# Check if dll does not contain "ud" for debug dll
get_filename_component(DLL_FILENAME ${WXWidgets_DLL} NAME_WE)
string(FIND ${DLL_FILENAME} "ud" debug_annot)
if(${debug_annot} LESS 0)
string(REPLACE "\\" "/" WXWidgets_DLL ${WXWidgets_DLL})
MESSAGE(STATUS "Install ${WXWidgets_DLL}")
list(APPEND WXWidgets_DLL_Slash ${WXWidgets_DLL})
endif()
endforeach(WXWidgets_DLL)
install(FILES
${WXWidgets_DLL_Slash}
DESTINATION .)
Here is example of what I use together with CPack. It will analyse the .exe
with dumpbin
/readelf
to find what libraries to copy.
My script also tries to strip the resulting DLL's (you can remove that part if you want). Insert this after your install(TARGETS ...)
command.
Things you might need to adjust (careful, they will be expanded before install time):
RUNTIME_DIR
- subdirectory like bin
where your .exe
and .dll
files are installedEXECUTABLE_NAME
- name of your target without the .exe
fixup_bundle
- its \"\"
but you might need to change it to \"${wxWidgets_LIB_DIR}\"
(the directory from which to copy the dlls)install(CODE "
include(BundleUtilities)
fixup_bundle(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${RUNTIME_DIR}/${EXECUTABLE_NAME}${CMAKE_EXECUTABLE_SUFFIX}\" \"\" \"\")
file(GLOB dynamic_libs \"\${CMAKE_INSTALL_PREFIX}/${RUNTIME_DIR}/*${CMAKE_SHARED_LIBRARY_SUFFIX}*\")
message(STATUS \"GLOB: \${dynamic_libs}\")
foreach(dll IN LISTS dynamic_libs)
if(\"${CMAKE_STRIP}\")
execute_process(COMMAND ${CMAKE_STRIP} \"-s\" \${dll})
endif()
endforeach(dll)
")
Update: install(CODE ...)
adds commands inside of string to cmake_install.cmake
file verbatim, so generator expressions are not expanded.
Number of useful variables is also quite limited, for example ${CMAKE_INSTALL_PREFIX}
in my example is expanded inside cmake_install.cmake
, but ${CMAKE_SHARED_LIBRARY_SUFFIX}
should be expanded before going there.
You can try using ${PROJECT_BINARY_DIR}
/\${CMAKE_INSTALL_PREFIX}
to create full path to .exe
manually.