UsewxWidgets.cmake 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. UsewxWidgets
  5. ------------
  6. Convenience include for using wxWidgets library.
  7. Determines if wxWidgets was FOUND and sets the appropriate libs,
  8. incdirs, flags, etc. INCLUDE_DIRECTORIES and LINK_DIRECTORIES are
  9. called.
  10. USAGE
  11. ::
  12. # Note that for MinGW users the order of libs is important!
  13. find_package(wxWidgets REQUIRED net gl core base)
  14. include(${wxWidgets_USE_FILE})
  15. # and for each of your dependent executable/library targets:
  16. target_link_libraries(<YourTarget> ${wxWidgets_LIBRARIES})
  17. DEPRECATED
  18. ::
  19. LINK_LIBRARIES is not called in favor of adding dependencies per target.
  20. AUTHOR
  21. ::
  22. Jan Woetzel <jw -at- mip.informatik.uni-kiel.de>
  23. #]=======================================================================]
  24. # debug message and logging.
  25. # comment these out for distribution
  26. if (NOT LOGFILE )
  27. # set(LOGFILE "${PROJECT_BINARY_DIR}/CMakeOutput.log")
  28. endif ()
  29. macro(MSG _MSG)
  30. # file(APPEND ${LOGFILE} "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}\n")
  31. # message(STATUS "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}")
  32. endmacro()
  33. MSG("wxWidgets_FOUND=${wxWidgets_FOUND}")
  34. if (wxWidgets_FOUND)
  35. if (wxWidgets_INCLUDE_DIRS)
  36. if(wxWidgets_INCLUDE_DIRS_NO_SYSTEM)
  37. include_directories(${wxWidgets_INCLUDE_DIRS})
  38. else()
  39. include_directories(SYSTEM ${wxWidgets_INCLUDE_DIRS})
  40. endif()
  41. MSG("wxWidgets_INCLUDE_DIRS=${wxWidgets_INCLUDE_DIRS}")
  42. endif()
  43. if (wxWidgets_LIBRARY_DIRS)
  44. link_directories(${wxWidgets_LIBRARY_DIRS})
  45. MSG("wxWidgets_LIBRARY_DIRS=${wxWidgets_LIBRARY_DIRS}")
  46. endif()
  47. if (wxWidgets_DEFINITIONS)
  48. set_property(DIRECTORY APPEND
  49. PROPERTY COMPILE_DEFINITIONS ${wxWidgets_DEFINITIONS})
  50. MSG("wxWidgets_DEFINITIONS=${wxWidgets_DEFINITIONS}")
  51. endif()
  52. if (wxWidgets_DEFINITIONS_DEBUG)
  53. set_property(DIRECTORY APPEND
  54. PROPERTY COMPILE_DEFINITIONS_DEBUG ${wxWidgets_DEFINITIONS_DEBUG})
  55. MSG("wxWidgets_DEFINITIONS_DEBUG=${wxWidgets_DEFINITIONS_DEBUG}")
  56. endif()
  57. if (wxWidgets_CXX_FLAGS)
  58. # Flags are expected to be a string here, not a list.
  59. string(REPLACE ";" " " wxWidgets_CXX_FLAGS_str "${wxWidgets_CXX_FLAGS}")
  60. string(APPEND CMAKE_CXX_FLAGS " ${wxWidgets_CXX_FLAGS_str}")
  61. MSG("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS_str}")
  62. unset(wxWidgets_CXX_FLAGS_str)
  63. endif()
  64. # DEPRECATED JW
  65. # just for backward compatibility: add deps to all targets
  66. # library projects better use advanced find_package(wxWidgets) directly.
  67. #if(wxWidgets_LIBRARIES)
  68. # link_libraries(${wxWidgets_LIBRARIES})
  69. # # BUG: str too long: MSG("wxWidgets_LIBRARIES=${wxWidgets_LIBRARIES}")
  70. # if(LOGFILE)
  71. # file(APPEND ${LOGFILE} "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${wxWidgets_LIBRARIES}\n")
  72. # endif()
  73. #endif()
  74. else ()
  75. message("wxWidgets requested but not found.")
  76. endif()