3

I've written a CMakeLists.txt as shown below:

cmake_minimum_required (VERSION 3.22)

project(tutorial)

set(wxWidgets_CONFIGURATION mswu)

find_package(wxWidgets REQUIRED COMPONENTS net core base)
include(${wxWidgets_USE_FILE})
add_executable(tutorial main.cpp)
target_link_libraries(tutorial ${wxWidgets_LIBRARIES})

install(TARGETS tutorial DESTINATION bin)

include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "1")
include(CPack)

As you might guess, this is WxWidgets application.

Look at the bottom. It includes InstallRequiredSystemLibraries and CPack.

With this cmake I have generated a NSIS Cpack installer "tutorial-0.1.1-win64.exe". But this installer only installs the project binary and some runtime libraries. It doesn't install any WxWidgets library. So the project binary fails to run on other systems that is not installed WxWidgets libraries.

I'd like to make NSIS Cpack installer installs WxWidgets DLL libraries also. How can I make it?

enter image description here

See! Those binaries are needed to be installed! But NSIS Cpack installer doesn't install wxbase315ud_vc14x_x64.dll and wxmsw315ud_core_vc14x_x64.dll

I am working on Windows 10

I don't want to statically link to the WxWidgets libraries. I'd like to make it link dynamically with shared libraries.

Jumogehn
  • 1,102
  • 3
  • 11
  • 29
  • 1
    @Jeonghun, why not use static linking of wxWidgets? Especially since you are on Windows... – Igor Jan 16 '22 at 15:55
  • Hi, that,s because I'd like to know general cmake and cpack usage. The WxWidgets could be replaced with qt or any other opensource library. And some libraries requies shared usage unless the source code of application is also open-source. – Jumogehn Jan 16 '22 at 19:29
  • 1
    @Jeonghun, in Windows there is no dedicated place to install the dynamic libraries comparing to *nix. Since it is 3rd party libraries you probably should specify the place where you want them to be installed. But I definitely think you should look into static linking. – Igor Jan 16 '22 at 20:41
  • @Igor I guess cmake can handle application and library at the same time. It would look like visual studio solution. In one solution, there exists one application and one library. So the application binary and library binaries are installed in the same directory... Wouldn't this possible solution? In this case the library is dedicated to the application not shared but the binaries are separated so that application can be closed-source even with LGPL library.. – Jumogehn Jan 16 '22 at 23:07
  • 1
    @Jeonghun, true. But while in *nix one can issue `make install` and the OS will know what to do, i believe in Windows you have to exactly specify where the libraries will be installed. However I'm not an installer guru. – Igor Jan 16 '22 at 23:33
  • @Igor You helped me. Thank you very much. – Jumogehn Jan 17 '22 at 00:35
  • @Jeonghun, please upvote the answer that did. Thx. – Igor Jan 17 '22 at 02:46

1 Answers1

1

There exists a previous talk for the similar subject :

Including external libraries in cpack output

I tried this way and it works :

cmake_minimum_required (VERSION 3.22)

project(tutorial)

if(CMAKE_BUILD_TYPE MATCHES Release)
  message("release mode")
  set(wxWidgets_CONFIGURATION mswu)
else()
  message("debug mode")
  set(wxWidgets_CONFIGURATION mswud)
endif()

find_package(wxWidgets REQUIRED COMPONENTS net core base)
include(${wxWidgets_USE_FILE})
add_executable(tutorial main.cpp)
target_link_libraries(tutorial ${wxWidgets_LIBRARIES})
    
install(TARGETS tutorial DESTINATION bin)
if(CMAKE_BUILD_TYPE MATCHES Release)
  install(FILES ${wxWidgets_LIB_DIR}/wxbase315u_vc_custom.dll DESTINATION bin)
  install(FILES ${wxWidgets_LIB_DIR}/wxmsw315u_core_vc_custom.dll DESTINATION bin)
else()
  install(FILES ${wxWidgets_LIB_DIR}/wxbase315ud_vc_custom.dll DESTINATION bin)
  install(FILES ${wxWidgets_LIB_DIR}/wxmsw315ud_core_vc_custom.dll DESTINATION bin)
endif()

include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "1")
include(CPack)

Look I added this below :

if(CMAKE_BUILD_TYPE MATCHES Release)
  install(FILES ${wxWidgets_LIB_DIR}/wxbase315u_vc_custom.dll DESTINATION bin)
  install(FILES ${wxWidgets_LIB_DIR}/wxmsw315u_core_vc_custom.dll DESTINATION bin)
else()
  install(FILES ${wxWidgets_LIB_DIR}/wxbase315ud_vc_custom.dll DESTINATION bin)
  install(FILES ${wxWidgets_LIB_DIR}/wxmsw315ud_core_vc_custom.dll DESTINATION bin)
endif()

And It works as I wanted!

Jumogehn
  • 1,102
  • 3
  • 11
  • 29