summary refs log tree commit diff
path: root/CMakeLists.txt
blob: 7cbdc2eba1ab269ecaae3422616bdc9b905bda2d (plain) (blame)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
cmake_minimum_required(VERSION 3.13)

project(WEP C)

find_package(SDL2 REQUIRED)

add_subdirectory(cards)
include_directories(cards)

if(NOT MSVC)
	add_compile_options(-Wall -Wextra -pedantic)
endif()

set(games sol freecell)
set(tools exe2ico ico2png)

foreach(game ${games})
	add_executable(${game} MACOSX_BUNDLE ${game}.c)
	target_link_libraries(${game} cards)

	# Work around possible bugs in SDL2Config.cmake
	if(MINGW)
		target_link_libraries(${game} mingw32)
		set_target_properties(${game} PROPERTIES WIN32_EXECUTABLE 1)
	endif()

	target_link_libraries(${game} SDL2::SDL2main SDL2::SDL2)

	# Avoid conflicting with SOL.EXE, FREECELL.EXE on Windows
	if(WIN32)
		set_target_properties(${game} PROPERTIES OUTPUT_NAME wep${game})
	endif()

	set_target_properties(
		${game} PROPERTIES
		MACOSX_BUNDLE_INFO_PLIST
		${CMAKE_CURRENT_SOURCE_DIR}/MacOSXBundleInfo.plist.in
	)
endforeach()

if(APPLE)
	set_target_properties(sol PROPERTIES OUTPUT_NAME Solitaire)
	set_target_properties(freecell PROPERTIES OUTPUT_NAME FreeCell)
endif()

foreach(tool ${tools})
	add_executable(${tool} EXCLUDE_FROM_ALL tools/${tool}.c)
	target_link_libraries(${tool} SDL2::SDL2)
endforeach()

set(
	WEP_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH
	"Directory containing WEP DLLs and EXEs"
)
set(
	SOL_DIRECTORY ${WEP_DIRECTORY} CACHE PATH
	"Directory containing SOL.EXE"
)

set(cards_dll ${WEP_DIRECTORY}/CARDS.DLL)
if(NOT EXISTS ${cards_dll})
	set(cards_dll ${SOL_DIRECTORY}/SOL.EXE)
endif()
if(EXISTS ${cards_dll})
	foreach(game ${games})
		target_sources(${game} PRIVATE ${cards_dll})
		set_target_properties(${game} PROPERTIES RESOURCE ${cards_dll})
	endforeach()
endif()

set(freecell_exe ${WEP_DIRECTORY}/FREECELL.EXE)
if(EXISTS ${freecell_exe})
	target_sources(freecell PRIVATE ${freecell_exe})
	set_target_properties(
		freecell PROPERTIES RESOURCE "${cards_dll};${freecell_exe}"
	)
endif()

foreach(game ${games})
	string(TOUPPER ${game} shouting)
	set(game_exe ${WEP_DIRECTORY}/${shouting}.EXE)
	if(NOT EXISTS ${game_exe})
		continue()
	endif()

	add_custom_command(
		OUTPUT ${shouting}.ICO
		COMMAND exe2ico ${game_exe}
		DEPENDS ${game_exe}
		VERBATIM
	)
	if(APPLE)
		add_custom_command(
			OUTPUT ${shouting}.PNG
			COMMAND ico2png ${shouting}.ICO
			DEPENDS ${shouting}.ICO
			VERBATIM
		)
		file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${game}.iconset)
		add_custom_command(
			OUTPUT ${game}.iconset/icon_32x32.png
			COMMAND cp ${shouting}.PNG ${game}.iconset/icon_32x32.png
			DEPENDS ${shouting}.PNG
			VERBATIM
		)
		add_custom_command(
			OUTPUT ${game}.icns
			COMMAND iconutil -c icns ${game}.iconset
			DEPENDS ${game}.iconset/icon_32x32.png
			VERBATIM
		)
		target_sources(${game} PRIVATE ${game}.icns)
		get_property(game_resource TARGET ${game} PROPERTY RESOURCE)
		set_target_properties(
			${game} PROPERTIES
			RESOURCE "${game_resource};${game}.icns"
			MACOSX_BUNDLE_ICON_FILE ${game}.icns
		)
	elseif(WIN32)
		file(
			GENERATE OUTPUT ${game}.rc
			CONTENT "IDI_ICON1 ICON DISCARDABLE \"${shouting}.ICO\"\n"
		)
		target_sources(${game} PRIVATE ${game}.rc ${shouting}.ICO)
	endif()
endforeach()

install(TARGETS ${games} BUNDLE DESTINATION /Applications)