From 414ad3a07f4bb9a4a6678d25e992d337771684b3 Mon Sep 17 00:00:00 2001
From: Nikoli <nikoli@lavabit.com>
Date: Wed, 22 Sep 2010 08:18:48 +0400
Subject: [PATCH] cmake: fix automagic, config installation; make examples and resources optional

---
 CMakeLists.txt                     |   30 ++++++++++++++++++----------
 examples/mandelbrot/CMakeLists.txt |    6 ++--
 examples/style/CMakeLists.txt      |    6 ++--
 src/CMakeLists.txt                 |   28 +++++++++++++++-----------
 src/Wt/CMakeLists.txt              |   12 ++++++++++-
 src/Wt/Dbo/backend/CMakeLists.txt  |   17 ++++++++++++---
 test/CMakeLists.txt                |   37 +++++++++++++++++++++--------------
 7 files changed, 87 insertions(+), 49 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 896bd2d..9c6f679 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,6 +27,10 @@ SET(WTDBOPOSTGRES_SOVERSION 23)
 #
 # Various things that must be configured by the user or packager ...
 #
+option(BUILD_EXAMPLES "Build examples" OFF)
+option(INSTALL_RESOURCES "Install resources directory" ON)
+option(ENABLE_GM "Enable GraphicsMagick, for supporting painting to raster images (PNG, GIF, ...) (WRasterImage)" ON)
+option(ENABLE_HARU "Enable Haru Free PDF Library, which is used to provide support for painting to PDF (WPdfImage)" ON)
 
 IF(NOT SHARED_LIBS)
   IF(WIN32)
@@ -296,11 +300,11 @@ IF (DOXYGEN_FOUND)
   ADD_DEPENDENCIES(doc doxygen-examples)
  ENDIF (DOXYGEN_FOUND)
 
-IF(WIN32)
-  SUBDIRS(src examples)
-ELSE(WIN32)
-  SUBDIRS(src EXCLUDE_FROM_ALL examples)
-ENDIF(WIN32)
+SUBDIRS(src)
+
+IF(BUILD_EXAMPLES)
+  SUBDIRS(examples)
+ENDIF(BUILD_EXAMPLES)
 
 IF(BUILD_TESTS)
   SUBDIRS(test)
@@ -313,20 +317,24 @@ ENDIF( NOT DEFINED WT_CMAKE_FINDER_INSTALL_DIR)
 INSTALL(FILES ${PROJECT_SOURCE_DIR}/cmake/FindWt.cmake DESTINATION
     ${CMAKE_INSTALL_PREFIX}/${WT_CMAKE_FINDER_INSTALL_DIR} )
 
+IF(INSTALL_RESOURCES)
 INSTALL(DIRECTORY ${PROJECT_SOURCE_DIR}/resources DESTINATION
     ${CMAKE_INSTALL_PREFIX}/share/Wt/)
+ENDIF(INSTALL_RESOURCES)
 
-IF(NOT EXISTS ${CONFIGDIR}/wt_config.xml)
+IF(NOT EXISTS ${DESTDIR}${CONFIGDIR}/wt_config.xml)
   INSTALL(FILES ${WT_BINARY_DIR}/wt_config.xml DESTINATION ${CONFIGDIR})
-ENDIF (NOT EXISTS ${CONFIGDIR}/wt_config.xml)
+ENDIF (NOT EXISTS ${DESTDIR}${CONFIGDIR}/wt_config.xml)
 
-IF(HARU_FOUND)
+IF(ENABLE_HARU AND HARU_FOUND)
+  SET(HAVE_HARU ON)
   SET(WT_HAS_WPDFIMAGE true)
-ENDIF(HARU_FOUND)
+ENDIF(ENABLE_HARU AND HARU_FOUND)
 
-IF(GM_FOUND)
+IF(ENABLE_GM AND GM_FOUND)
+  SET(HAVE_GM ON)
   SET(WT_HAS_WRASTERIMAGE true)
-ENDIF(GM_FOUND)
+ENDIF(ENABLE_GM AND GM_FOUND)
 
 # Compile time constants & make sure our build finds it
 FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Wt)
diff --git a/examples/mandelbrot/CMakeLists.txt b/examples/mandelbrot/CMakeLists.txt
index 176cab6..64b8ff7 100644
--- a/examples/mandelbrot/CMakeLists.txt
+++ b/examples/mandelbrot/CMakeLists.txt
@@ -1,6 +1,6 @@
-IF(NOT GM_FOUND)
+IF(NOT HAVE_GM)
   MESSAGE(STATUS "** Not building mandelbrot example: requires Wt::WRasterImage.")
-ELSE(NOT GM_FOUND)
+ELSE(NOT HAVE_GM)
 
   WT_ADD_EXAMPLE(mandelbrot.wt MandelbrotImage.C MandelbrotExample.C)
 
@@ -11,5 +11,5 @@ ELSE(NOT GM_FOUND)
 
   ADD_DEPENDENCIES(mandelbrot.wt wt ${EXAMPLES_CONNECTOR})
 
-ENDIF(NOT GM_FOUND)
+ENDIF(NOT HAVE_GM)
 
diff --git a/examples/style/CMakeLists.txt b/examples/style/CMakeLists.txt
index 6443035..04a71f7 100644
--- a/examples/style/CMakeLists.txt
+++ b/examples/style/CMakeLists.txt
@@ -1,8 +1,8 @@
-IF(NOT GM_FOUND)
+IF(NOT HAVE_GM)
 
   MESSAGE(STATUS "** Not building style example: requires WRasterImage.")
 
-ELSE(NOT GM_FOUND)
+ELSE(NOT HAVE_GM)
 
   WT_ADD_EXAMPLE(styleexample.wt CornerImage.C RoundedWidget.C StyleExample.C)
 
@@ -12,5 +12,5 @@ ELSE(NOT GM_FOUND)
 
   ADD_DEPENDENCIES(styleexample.wt wt ${EXAMPLES_CONNECTOR})
 
-ENDIF(NOT GM_FOUND)
+ENDIF(NOT HAVE_GM)
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7d11b67..4523540 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -238,33 +238,37 @@ IF (MULTI_THREADED_BUILD)
   SET(libsources ${libsources} web/SocketNotifier.C)
 ENDIF(MULTI_THREADED_BUILD)
 
-IF(HARU_FOUND)
+IF(HAVE_HARU)
   SET(libsources ${libsources} Wt/WPdfImage.C)
-ENDIF(HARU_FOUND)
+ENDIF(HAVE_HARU)
 
-IF(GM_FOUND)
+IF(HAVE_GM)
   SET(libsources ${libsources} Wt/WRasterImage.C)
-ENDIF(GM_FOUND)
+ENDIF(HAVE_GM)
 
 ADD_LIBRARY(wt ${libsources})
 TARGET_LINK_LIBRARIES(wt ${BOOST_WT_LIBRARIES})
 
-IF(HARU_FOUND)
+IF(HAVE_HARU)
   TARGET_LINK_LIBRARIES(wt ${HARU_LIBRARIES})
   INCLUDE_DIRECTORIES(${HARU_INCLUDE_DIRS})
-ELSE(HARU_FOUND)
+ELSE(HAVE_HARU)
   MESSAGE("** Disabling PDF support (WPdfImage): requires libharu.")
-  MESSAGE("   Indicate the location of your haru library using -DHARU_PREFIX=...")
-ENDIF(HARU_FOUND)
+  IF(ENABLE_HARU)
+    MESSAGE("   Indicate the location of your haru library using -DHARU_PREFIX=...")
+  ENDIF(ENABLE_HARU)
+ENDIF(HAVE_HARU)
 
-IF(GM_FOUND)
+IF(HAVE_GM)
   TARGET_LINK_LIBRARIES(wt ${GM_LIBRARIES})
   INCLUDE_DIRECTORIES(${GM_INCLUDE_DIRS})
   ADD_DEFINITIONS(-DHAVE_RASTER_IMAGE)
-ELSE(GM_FOUND)
+ELSE(HAVE_GM)
   MESSAGE("** Disabling raster image support (WRasterImage): requires graphicsmagick.")
-  MESSAGE("   Indicate the location of your graphicsmagick library using -DGM_PREFIX=...")
-ENDIF(GM_FOUND)
+  IF(ENABLE_GM)
+    MESSAGE("   Indicate the location of your graphicsmagick library using -DGM_PREFIX=...")
+  ENDIF(ENABLE_GM)
+ENDIF(HAVE_GM)
 
 IF(MULTI_THREADED_BUILD)
   TARGET_LINK_LIBRARIES(wt ${CMAKE_THREAD_LIBS_INIT})
diff --git a/src/Wt/CMakeLists.txt b/src/Wt/CMakeLists.txt
index d5a3c58..67faae8 100644
--- a/src/Wt/CMakeLists.txt
+++ b/src/Wt/CMakeLists.txt
@@ -1,4 +1,14 @@
-SUBDIRS(Dbo Ext Chart Http Test)
+SUBDIRS(Chart Http Test)
+
+# FIXME we should use (HAVE_SQLITE OR HAVE_POSTGRES)
+IF(ENABLE_SQLITE OR ENABLE_POSTGRES)
+  SUBDIRS(Dbo)
+ENDIF(ENABLE_SQLITE OR ENABLE_POSTGRES)
+
+option(ENABLE_EXT "Build Wt Ext library with JavaScript-only widgets (http://extjs.com/)" ON)
+IF(ENABLE_EXT)
+  SUBDIRS(Ext)
+ENDIF(ENABLE_EXT)
 
 INSTALL_FILES(/include/Wt "^W.*[^C~]$")
 #INSTALL(
diff --git a/src/Wt/Dbo/backend/CMakeLists.txt b/src/Wt/Dbo/backend/CMakeLists.txt
index 653a830..7668b90 100644
--- a/src/Wt/Dbo/backend/CMakeLists.txt
+++ b/src/Wt/Dbo/backend/CMakeLists.txt
@@ -1,3 +1,8 @@
+OPTION(ENABLE_SQLITE "Build SQLite3 backend for Wt::Dbo" ON)
+OPTION(ENABLE_POSTGRES "Build PostgreSQL backend for Wt::Dbo" OFF)
+
+IF(ENABLE_SQLITE)
+
 OPTION( USE_SYSTEM_SQLITE3 "Use system-wide Sqlite3 instead of Wt's version" OFF)
 
 IF(USE_SYSTEM_SQLITE3)
@@ -41,7 +46,9 @@ PROPERTIES
 INSTALL_FILES(/include/Wt/Dbo/backend "^Sqlite3$")
 INSTALL_FILES(/include/Wt/Dbo/backend "^.*Sqlite3.*h$")
 
-IF(POSTGRES_FOUND)
+ENDIF(ENABLE_SQLITE)
+
+IF(ENABLE_POSTGRES AND POSTGRES_FOUND)
   MESSAGE("** Wt::Dbo: building Postgres backend.")
   ADD_LIBRARY(wtdbopostgres
     Postgres.C
@@ -65,8 +72,10 @@ IF(POSTGRES_FOUND)
 
   INSTALL_FILES(/include/Wt/Dbo/backend "^Postgres$")
   INSTALL_FILES(/include/Wt/Dbo/backend "^.*Postgres.*h$")
-ELSE(POSTGRES_FOUND)
+ELSE(ENABLE_POSTGRES AND POSTGRES_FOUND)
   MESSAGE("** Wt::Dbo: not building Postgres backend.")
-  MESSAGE("    Indicate the location of your postgres installation using -DPOSTGRES_PREFIX=...")
-ENDIF(POSTGRES_FOUND)
+  IF(ENABLE_POSTGRES)
+    MESSAGE("    Indicate the location of your postgres installation using -DPOSTGRES_PREFIX=...")
+  ENDIF(ENABLE_POSTGRES)
+ENDIF(ENABLE_POSTGRES AND POSTGRES_FOUND)
 
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index d18ca2e..2a928ae 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,20 +1,27 @@
-ADD_EXECUTABLE(test
-  test.C
-  chart/WChartTest.C
-  dbo/DboTest.C
-  dbo/DboTest2.C
-  models/WBatchEditProxyModelTest.C
-  utf8/Utf8Test.C
-  wdatetime/WDateTimeTest.C
-)
+# Tests need sqlite
+IF(ENABLE_SQLITE)
 
-# SQLITE3 test
-TARGET_LINK_LIBRARIES(test wt wtdbo wtdbosqlite3)
-ADD_DEFINITIONS(-DSQLITE3)
+  ADD_EXECUTABLE(test
+    test.C
+    chart/WChartTest.C
+    dbo/DboTest.C
+    dbo/DboTest2.C
+    models/WBatchEditProxyModelTest.C
+    utf8/Utf8Test.C
+    wdatetime/WDateTimeTest.C
+  )
 
-# POSTGRES test
-#TARGET_LINK_LIBRARIES(test wt wtdbo wtdbopostgres)
-#ADD_DEFINITIONS(-DPOSTGRES)
+  # SQLITE3 test
+  TARGET_LINK_LIBRARIES(test wt wtdbo wtdbosqlite3)
+  ADD_DEFINITIONS(-DSQLITE3)
+
+ENDIF(ENABLE_SQLITE)
+
+## # POSTGRES test
+## IF(ENABLE_POSTGRES AND POSTGRES_FOUND)
+##   TARGET_LINK_LIBRARIES(test wt wtdbo wtdbopostgres)
+##   ADD_DEFINITIONS(-DPOSTGRES)
+## ENDIF(ENABLE_POSTGRES AND POSTGRES_FOUND)
 
 INCLUDE_DIRECTORIES(${WT_SOURCE_DIR}/src)
 
-- 
1.7.2.2