From 8c046a3efe00b3a4d87f07cff4363b30aa417db0 Mon Sep 17 00:00:00 2001
From: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Tue, 20 Oct 2009 19:18:15 -0500
Subject: [PATCH] Make puzzles as part of build.

---
 puzzles/CMakeLists.txt  |   46 +++++++++++++++++++++++++++++++---------------
 puzzles/make-puzzles.sh |    8 --------
 2 files changed, 31 insertions(+), 23 deletions(-)
 delete mode 100644 puzzles/make-puzzles.sh

diff --git a/puzzles/CMakeLists.txt b/puzzles/CMakeLists.txt
index 1a7be5c..1526f40 100644
--- a/puzzles/CMakeLists.txt
+++ b/puzzles/CMakeLists.txt
@@ -1,15 +1,31 @@
-if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/castle-maintenon.puzzle)
-	install(FILES
-		castle-maintenon.puzzle
-		cincinnati-bridge.puzzle
-		citrus-fruits.puzzle
-		european-honey-bee.puzzle
-		panther-chameleon-female.puzzle
-	DESTINATION ${DATA_INSTALL_DIR}/palapeli/puzzlelibrary
-	PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
-	install(FILES
-		default-collection.conf
-	DESTINATION ${CONFIG_INSTALL_DIR}
-	PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
-	RENAME palapeli-libraryrc)
-endif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/castle-maintenon.puzzle)
+macro(make_puzzle NAME)
+	add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.puzzle
+	                   COMMAND ${palapeli_BINARY_DIR}/tools/libpala-puzzlebuilder
+	                           ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}.conf
+	                           ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.puzzle
+	                   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	                   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}.conf
+	                           libpala-puzzlebuilder)
+	list(APPEND puzzle_outputs ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.puzzle)
+endmacro()
+
+set(PUZZLES
+    castle-maintenon cincinnati-bridge citrus-fruits european-honey-bee
+    panther-chameleon-female
+)
+set(puzzle_outputs)
+
+foreach(PUZZLE ${PUZZLES})
+	make_puzzle(${PUZZLE})
+	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PUZZLE}.puzzle
+	        DESTINATION ${DATA_INSTALL_DIR}/palapeli/puzzlelibrary
+	        PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
+	)
+endforeach()
+install(FILES default-collection.conf
+        DESTINATION ${CONFIG_INSTALL_DIR}
+        PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
+        RENAME palapeli-libraryrc
+)
+
+add_custom_target(puzzles ALL DEPENDS ${puzzle_outputs})
diff --git a/puzzles/make-puzzles.sh b/puzzles/make-puzzles.sh
deleted file mode 100644
index 092a032..0000000
--- a/puzzles/make-puzzles.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-
-for MANIFEST in *.conf; do
-	[ "$MANIFEST" = "default-collection.conf" ] && continue
-	TARGET=$(basename $MANIFEST .conf).puzzle
-	echo "Creating $TARGET"
-	libpala-puzzlebuilder $MANIFEST $TARGET
-done
-- 
1.6.0.6
