FindMFC.cmake 2.5 KB

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