CMake创建MFC桌面应用
安装
项目代码
cmake_minimum_required(VERSION 3.0)
project(mfc_demo)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
# 1: static MFC library, 2: shared MFC library
set(CMAKE_MFC_FLAG 2)
#find_package(MFC)
#if(NOT MFC_FOUND)
# message(FATAL_ERROR "MFC is not found, please check MFC installation")
#endif()
add_executable(mfc_demo mfc.cpp)
#target_sources(mfc_demo PRIVATE
# mfc.cpp
# )
#set_target_properties(mfc_demo PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
target_compile_definitions(mfc_demo PRIVATE
-DWIN32
-D_DEBUG
-D_WINDOWS
-D_UNICODE
-DUNICODE
-D_AFXDLL
)
target_link_options(mfc_demo PRIVATE
/ENTRY:wWinMainCRTStartup
)
#ifndef MFC_DEMO_MFC_H
#define MFC_DEMO_MFC_H
#include <afxwin.h>
class MyApp:public CWinApp {
public:
virtual BOOL InitInstance();
};
class MyFrame:public CFrameWnd
{
public:
MyFrame();
};
#endif
#include "mfc.h"
MyApp app;
BOOL MyApp::InitInstance()
{
MyFrame* frame = new MyFrame;
frame->ShowWindow(SW_SHOWNORMAL);
frame->UpdateWindow();
m_pMainWnd = frame;
return TRUE;
}
MyFrame::MyFrame() {
Create(NULL, TEXT("mfc"));
}