summaryrefslogtreecommitdiffstats
path: root/Tests/MFC/CMakeLists.txt.in
blob: bae3d2fb19058f18e6f101e10d52b5eeba337c69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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}>")