Hi there!
I am building an app using CMake and wxwidgets. The issue I am facing is that I can’t compile my app in release mode because is using the debug libs. I don’t know how to set the directories to look for in different places depending on the compiling mode.
My current CMake is:
cmake_minimum_required(VERSION 3.18)
message(STATUS "Building SUN")
set(wxWidgets_USE_DEBUG ON)
set(wxWidgets_USE_UNICODE ON)
set(wxWidgets_ROOT_DIR C:/wx314_install/Debug)
set(wxWidgets_LIB_DIR C:/wx314_install/Debug/lib/vc_x64_lib)
set(wxWidgets_INCLUDE_DIRS C:/wx314_install/Debug/include)
message(STATUS "${wxWidgets_ROOT_DIR}")
# Note that for MinGW users the order of libs is important!
find_package(wxWidgets REQUIRED net gl core base)
include(${wxWidgets_USE_FILE})
add_executable(app WIN32)
target_sources(app PRIVATE
src/app.cpp)
target_link_libraries(app PRIVATE ${wxWidgets_LIBRARIES})
As you can see, I have the wxwidgets directories links to the Debug folder, I have another folder called Release where I have the release binaries of CMake.
How can I set the different wxwidgets variables to use one or other binaries to compile my project?
Thank you in advance.
At the moment I am doing the following as a workaround:
IF(CMAKE_BUILD_TYPE MATCHES Release)
message(STATUS "Release mode" )
set(wxWidgets_ROOT_DIR C:/wx314_install/Release)
set(wxWidgets_LIB_DIR C:/wx314_install/Release/lib/vc_x64_lib)
set(wxWidgets_INCLUDE_DIRS C:/wx314_install/Release/include)
ENDIF()
IF(CMAKE_BUILD_TYPE MATCHES Debug)
message(STATUS "Debug mode" )
set(wxWidgets_ROOT_DIR C:/wx314_install/Debug)
set(wxWidgets_LIB_DIR C:/wx314_install/Debug/lib/vc_x64_lib)
set(wxWidgets_INCLUDE_DIRS C:/wx314_install/Debug/include)
ENDIF()
but I don’t know if there is cleaner way.
The cleaner way would be to have imported targets with config-specific paths:
add_library(wxWidgets::foolib UNKNOWN IMPORTED)
set_target_properties(wxWidgets::foolib PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "$<IF:$<CONFIG:Debug>,${debug_root}/include,${release_root}/include>"
IMPORTED_LOCATION_RELEASE "${release_root}/lib/…"
IMPORTED_LOCATION_DEBUG "${debg_root}/lib/…")
You may need to map configurations for RelWithDebInfo
or MinSizeRel
.
Hi Ben,
I am doing the exact same thing with OpenCV. That was one hell of a job because I am using many libraries for different executables and libraries and trying to identify all of them was a bit tuff.
Here is the example:
add_library(opencv_core STATIC IMPORTED)
set_property(TARGET opencv_core APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(opencv_core PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
IMPORTED_LOCATION_DEBUG "${PROJECT_SOURCE_DIR}/3rdparty/ImageAccumulation/3rdparty/OpenCV/lib/Debug/opencv_core411d.lib")
set_property(TARGET opencv_core APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(opencv_core PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
IMPORTED_LOCATION_RELEASE "${PROJECT_SOURCE_DIR}/3rdparty/ImageAccumulation/3rdparty/OpenCV/lib/Release/opencv_core411.lib")
set_target_properties(opencv_core PROPERTIES
MAP_IMPORTED_CONFIG_MINSIZEREL Release
MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release)
That is done for each .lib file. The example that you wrote it’s for a whole directory instead? I would like to avoid doing 100 lines in CMake to populate each .lib.
No, my example is per-library. However, OpenCV uses CMake and should be installing its own opencv-config.cmake
file that you can use directly with find_package(OpenCV)
.
Yes, same as wxWidgets, but currently the setup that was made by a another guy that is not here, it was badly done. So I am refactoring the whole project setup at the moment.
Thank you for your comments, Ben.