Skip to content

FindwxWidgets: Add an imported target

Nacho Diez Lambies requested to merge CheesyNacho/cmake:master into master
Original Description

This changes aim to do a more modern approach to the old fashioned FindwxWidgets.cmake script. I'm trying to make this script to return an imported target named wx::wxWidgets for a more simple usage in any project that needs the library but is not working as pretended.

In the updated documentation of the script I specify the desired usage of the script but it doesn't work for me. I looked a lot of other scripts to gain inspiration for this. I have been trying to make it work properly but I can not find what I am missing.

The pretended usage I think that it has to be like:

find_package(wxWidgets REQUIRED gl core base OPTIONAL_COMPONENTS net)
# and for each of your dependent executable/library targets:
target_include_directories(<YourTarget> wx::wxWidgets)
target_link_libraries(<YourTarget> wx::wxWidgets)
target_compile_definitions(<YourTarget> wx::wxWidgets)
target_compile_options(<YourTarget> wx::wxWidgets)

But in my case only works like this:

find_package(wxWidgets REQUIRED gl core base OPTIONAL_COMPONENTS net)
# and for each of your dependent executable/library targets:
target_include_directories(<YourTarget> $<TARGET_PROPERTY:wx::wxWidgets,INTERFACE_INCLUDE_DIRECTORIES>)
target_link_libraries(<YourTarget> $<TARGET_PROPERTY:wx::wxWidgets,IMPORTED_LOCATION>)
target_compile_definitions(<YourTarget> $<TARGET_PROPERTY:wx::wxWidgets,INTERFACE_COMPILE_DEFINITIONS>)
target_compile_options(<YourTarget> $<TARGET_PROPERTY:wx::wxWidgets,INTERFACE_COMPILE_OPTIONS>)

I don't really know what is happening as I am setting all necessary properties to the imported library. The output error that CMake shows me when using the "desired way" is the following: c1xx: fatal error C1003: Could not open the source file: 'wx::wxWidgets': No such file or directory

The conclussion I reached is that my CMakeLists.txt is not identifying the name wx::wxWidgets as a target and is guessing that is instead a directory for the includes (like ${CMAKE_SOURCE_DIR}/wx::wxWidgets) that does not exist.

I hope someone has any idea of what is going on. I think if we can solve this the script will be more usable and compatible with the actual CMake way of doing things.

Thank you all in advance :)

Topic-rename: FindwxWidgets-imported-target

Edited by Brad King

Merge request reports