FindMFC.cmake 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. configure_file(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in
  24. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx)
  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. SOURCES ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx
  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. configure_file(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in
  35. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx)
  36. try_compile(MFC_HAVE_MFC
  37. SOURCES ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx
  38. CMAKE_FLAGS
  39. -DCMAKE_MFC_FLAG:STRING=1
  40. OUTPUT_VARIABLE OUTPUT)
  41. endif()
  42. if(MFC_HAVE_MFC)
  43. message(CHECK_PASS "found")
  44. set(MFC_HAVE_MFC 1 CACHE INTERNAL "Have MFC?")
  45. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  46. "Determining if MFC exists passed with the following output:\n"
  47. "${OUTPUT}\n\n")
  48. else()
  49. message(CHECK_FAIL "not found")
  50. set(MFC_HAVE_MFC 0 CACHE INTERNAL "Have MFC?")
  51. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  52. "Determining if MFC exists failed with the following output:\n"
  53. "${OUTPUT}\n\n")
  54. endif()
  55. endif()
  56. if(MFC_HAVE_MFC)
  57. set(MFC_FOUND "YES")
  58. endif()
  59. endif()