FindMFC.cmake 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindMFC
  5. -------
  6. Finds the native Microsoft Foundation Class Library (MFC) for developing MFC
  7. applications on Windows:
  8. .. code-block:: cmake
  9. find_package(MFC [...])
  10. .. note::
  11. MFC is an optional component in Visual Studio and must be installed
  12. separately for this module to succeed.
  13. Once the MFC libraries and headers are found, no additional manual linking is
  14. needed, as they are part of the development environment.
  15. Result Variables
  16. ^^^^^^^^^^^^^^^^
  17. This module defines the following variables:
  18. ``MFC_FOUND``
  19. Boolean indicating whether MFC support was found.
  20. Examples
  21. ^^^^^^^^
  22. Using this module to check if the application can link to the MFC libraries:
  23. .. code-block:: cmake
  24. find_package(MFC)
  25. if(MFC_FOUND)
  26. # Example logic when MFC is available...
  27. set(CMAKE_MFC_FLAG 2)
  28. add_executable(app WIN32 main.cpp)
  29. target_compile_definitions(app PRIVATE _AFXDLL)
  30. endif()
  31. See Also
  32. ^^^^^^^^
  33. * The :variable:`CMAKE_MFC_FLAG` variable.
  34. #]=======================================================================]
  35. # Assume no MFC support
  36. set(MFC_FOUND "NO")
  37. # Only attempt the try_compile call if it has a chance to succeed:
  38. set(MFC_ATTEMPT_TRY_COMPILE 0)
  39. if(WIN32 AND NOT UNIX AND NOT BORLAND AND NOT MINGW)
  40. set(MFC_ATTEMPT_TRY_COMPILE 1)
  41. endif()
  42. if(MFC_ATTEMPT_TRY_COMPILE)
  43. if(NOT DEFINED MFC_HAVE_MFC)
  44. set(CHECK_INCLUDE_FILE_VAR "afxwin.h")
  45. file(READ ${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in _CIF_SOURCE_CONTENT)
  46. string(CONFIGURE "${_CIF_SOURCE_CONTENT}" _CIF_SOURCE_CONTENT)
  47. message(CHECK_START "Looking for MFC")
  48. # Try both shared and static as the root project may have set the /MT flag
  49. try_compile(MFC_HAVE_MFC
  50. SOURCE_FROM_VAR CheckIncludeFile.cxx _CIF_SOURCE_CONTENT
  51. CMAKE_FLAGS
  52. -DCMAKE_MFC_FLAG:STRING=2
  53. -DCOMPILE_DEFINITIONS:STRING=-D_AFXDLL
  54. OUTPUT_VARIABLE OUTPUT)
  55. if(NOT MFC_HAVE_MFC)
  56. try_compile(MFC_HAVE_MFC
  57. SOURCE_FROM_VAR CheckIncludeFile.cxx _CIF_SOURCE_CONTENT
  58. CMAKE_FLAGS
  59. -DCMAKE_MFC_FLAG:STRING=1
  60. OUTPUT_VARIABLE OUTPUT)
  61. endif()
  62. if(MFC_HAVE_MFC)
  63. message(CHECK_PASS "found")
  64. set(MFC_HAVE_MFC 1 CACHE INTERNAL "Have MFC?")
  65. else()
  66. message(CHECK_FAIL "not found")
  67. set(MFC_HAVE_MFC 0 CACHE INTERNAL "Have MFC?")
  68. endif()
  69. endif()
  70. if(MFC_HAVE_MFC)
  71. set(MFC_FOUND "YES")
  72. endif()
  73. endif()