summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CMakeLists.txt138
1 files changed, 103 insertions, 35 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 123d2e6..7cbdc2e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,50 +11,118 @@ if(NOT MSVC)
 	add_compile_options(-Wall -Wextra -pedantic)
 endif()
 
-add_executable(sol MACOSX_BUNDLE sol.c)
-add_executable(freecell MACOSX_BUNDLE freecell.c)
+set(games sol freecell)
+set(tools exe2ico ico2png)
 
-set_target_properties(
-	sol freecell PROPERTIES
-	MACOSX_BUNDLE_INFO_PLIST
-	${CMAKE_CURRENT_SOURCE_DIR}/MacOSXBundleInfo.plist.in
-)
-if(CMAKE_MACOSX_BUNDLE OR CMAKE_SYSTEM_NAME STREQUAL Darwin)
+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()
 
-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/CARDS.DLL)
-	target_sources(sol PRIVATE CARDS.DLL)
-	target_sources(freecell PRIVATE CARDS.DLL)
-	set_target_properties(sol freecell PROPERTIES RESOURCE CARDS.DLL)
-endif()
-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/FREECELL.EXE)
-	target_sources(freecell PRIVATE FREECELL.EXE)
-	set_target_properties(freecell PROPERTIES RESOURCE "CARDS.DLL;FREECELL.EXE")
-endif()
+foreach(tool ${tools})
+	add_executable(${tool} EXCLUDE_FROM_ALL tools/${tool}.c)
+	target_link_libraries(${tool} SDL2::SDL2)
+endforeach()
 
-# Workaround possible bugs in SDL2Config.cmake
-if(MINGW)
-	target_link_libraries(sol mingw32) # -lmingw32 -lSDL2main -lSDL2 in that order.
-	target_link_libraries(freecell mingw32)
-	set_target_properties(sol PROPERTIES WIN32_EXECUTABLE 1) # -mwindows
-	set_target_properties(freecell PROPERTIES WIN32_EXECUTABLE 1)
-endif()
+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"
+)
 
-target_link_libraries(sol cards SDL2::SDL2main SDL2::SDL2)
-target_link_libraries(freecell cards SDL2::SDL2main SDL2::SDL2)
+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()
 
-# Avoid conflicting with SOL.EXE, FREECELL.EXE on Windows
-if(WIN32)
-	set_target_properties(sol PROPERTIES OUTPUT_NAME wepsol)
-	set_target_properties(freecell PROPERTIES OUTPUT_NAME wepfreecell)
+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()
 
-add_executable(exe2ico EXCLUDE_FROM_ALL tools/exe2ico.c)
-target_link_libraries(exe2ico SDL2::SDL2)
+foreach(game ${games})
+	string(TOUPPER ${game} shouting)
+	set(game_exe ${WEP_DIRECTORY}/${shouting}.EXE)
+	if(NOT EXISTS ${game_exe})
+		continue()
+	endif()
 
-add_executable(ico2png EXCLUDE_FROM_ALL tools/ico2png.c)
-target_link_libraries(ico2png SDL2::SDL2)
+	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 sol freecell BUNDLE DESTINATION /Applications)
+install(TARGETS ${games} BUNDLE DESTINATION /Applications)