FindMFC.cmake 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. FindMFC
  5. -------
  6. Find Microsoft Foundation Class Library (MFC) on Windows
  7. Find the native MFC - i.e. decide if an application can link to the
  8. MFC libraries.
  9. ::
  10. MFC_FOUND - Was MFC support found
  11. You don't need to include anything or link anything to use it.
  12. #]=======================================================================]
  13. # Assume no MFC support
  14. set(MFC_FOUND "NO")
  15. # Only attempt the try_compile call if it has a chance to succeed:
  16. set(MFC_ATTEMPT_TRY_COMPILE 0)
  17. if(WIN32 AND NOT UNIX AND NOT BORLAND AND NOT MINGW)
  18. set(MFC_ATTEMPT_TRY_COMPILE 1)
  19. endif()
  20. if(MFC_ATTEMPT_TRY_COMPILE)
  21. if(NOT DEFINED MFC_HAVE_MFC)
  22. set(CHECK_INCLUDE_FILE_VAR "afxwin.h")
  23. file(READ ${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in _CIF_SOURCE_CONTENT)
  24. string(CONFIGURE "${_CIF_SOURCE_CONTENT}" _CIF_SOURCE_CONTENT)
  25. message(CHECK_START "Looking for MFC")
  26. # Try both shared and static as the root project may have set the /MT flag
  27. try_compile(MFC_HAVE_MFC
  28. SOURCE_FROM_VAR CheckIncludeFile.cxx _CIF_SOURCE_CONTENT
  29. CMAKE_FLAGS
  30. -DCMAKE_MFC_FLAG:STRING=2
  31. -DCOMPILE_DEFINITIONS:STRING=-D_AFXDLL
  32. OUTPUT_VARIABLE OUTPUT)
  33. if(NOT MFC_HAVE_MFC)
  34. try_compile(MFC_HAVE_MFC
  35. SOURCE_FROM_VAR CheckIncludeFile.cxx _CIF_SOURCE_CONTENT
  36. CMAKE_FLAGS
  37. -DCMAKE_MFC_FLAG:STRING=1
  38. OUTPUT_VARIABLE OUTPUT)
  39. endif()
  40. if(MFC_HAVE_MFC)
  41. message(CHECK_PASS "found")
  42. set(MFC_HAVE_MFC 1 CACHE INTERNAL "Have MFC?")
  43. else()
  44. message(CHECK_FAIL "not found")
  45. set(MFC_HAVE_MFC 0 CACHE INTERNAL "Have MFC?")
  46. endif()
  47. endif()
  48. if(MFC_HAVE_MFC)
  49. set(MFC_FOUND "YES")
  50. endif()
  51. endif()