Files
CMake/Tests/MFC/CMakeLists.txt.in
Brad King f53bd6f450 Tests: Bump CMake minimum required in tests to 3.5
CMake 3.27 deprecates compatibility with CMake < 3.5.  Update tests that
do not cover older interfaces to avoid the deprecation warning.

Follow the pattern from:

* commit 7b07ccdd2b (Tests/*Only: Update cmake_minimum_required versions,
                     2020-06-15, v3.19.0-rc1~629^2~1)

* commit 72e7c45e98 (Tests: Bump CMake minimum required in tests to 2.8.12,
                     2020-12-22, v3.20.0-rc1~224^2)

* commit f6b4db365a (Tests: bump cmake_minimum_required version to 2.8.12,
                     2021-04-04, v3.21.0-rc1~372^2)

Also remove explicit `cmake_policy` settings made redundant by the
version.
2023-03-01 16:36:54 -05:00

71 lines
1.7 KiB
CMake

cmake_minimum_required(VERSION 3.5)
project(mfc1)
macro(replace_flags var these those)
if("${${var}}" MATCHES "${these}")
string(REGEX REPLACE "${these}" "${those}" ${var} "${${var}}")
#message(STATUS "info: ${var} changed to '${${var}}'")
endif()
message(STATUS "info: ${var}='${${var}}'")
endmacro()
macro(msvc_link_to_static_crt)
if(MSVC)
set(has_correct_flag 0)
foreach(lang C CXX)
foreach(suffix "" _DEBUG _MINSIZEREL _RELEASE _RELWITHDEBINFO)
replace_flags("CMAKE_${lang}_FLAGS${suffix}" "/MD" "/MT")
if(CMAKE_${lang}_FLAGS${suffix} MATCHES "/MT")
set(has_correct_flag 1)
endif()
endforeach()
endforeach()
if(NOT has_correct_flag)
message(FATAL_ERROR "no CMAKE_*_FLAGS var contains /MT")
endif()
endif()
endmacro()
set(files
ChildFrm.cpp
ChildFrm.h
MainFrm.cpp
MainFrm.h
mfc1.cpp
mfc1.h
mfc1.rc
mfc1Doc.cpp
mfc1Doc.h
mfc1View.cpp
mfc1View.h
Resource.h
stdafx.cpp
stdafx.h
)
set(CMAKE_MFC_FLAG "@CMAKE_MFC_FLAG_VALUE@")
FIND_PACKAGE(MFC)
IF (NOT MFC_FOUND)
MESSAGE(FATAL_ERROR "MFC Could not be found during the MFC test")
ENDIF()
if("${CMAKE_MFC_FLAG}" STREQUAL "1")
msvc_link_to_static_crt()
else()
# VS generators add this automatically based on the CMAKE_MFC_FLAG value,
# but generators matching "Make" require:
add_definitions(-D_AFXDLL)
endif()
add_executable(mfc1 WIN32 ${files})
install(TARGETS mfc1 DESTINATION bin)
if("${CMAKE_MFC_FLAG}" STREQUAL "2")
set(CMAKE_INSTALL_MFC_LIBRARIES ON)
include(InstallRequiredSystemLibraries)
endif()
# Encode the value inside a generator expression to test evaluation.
set(CMAKE_MFC_FLAG "$<1:${CMAKE_MFC_FLAG}>")