Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 540)
+++ CMakeLists.txt	(revision 727)
@@ -1,36 +1,72 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 
-IF(EXISTS ${CMAKE_SOURCE_DIR}/cmake/version.cmake)
-  INCLUDE(${CMAKE_SOURCE_DIR}/cmake/version.cmake)
-ELSE(EXISTS ${CMAKE_SOURCE_DIR}/cmake/version.cmake)
-  SET(PROJECT_NAME "LEMON")
-  SET(PROJECT_VERSION "hg-tip" CACHE STRING "LEMON version string.")
-ENDIF(EXISTS ${CMAKE_SOURCE_DIR}/cmake/version.cmake)
-
+SET(PROJECT_NAME "LEMON")
 PROJECT(${PROJECT_NAME})
 
-SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
+IF(EXISTS ${PROJECT_SOURCE_DIR}/cmake/version.cmake)
+  INCLUDE(${PROJECT_SOURCE_DIR}/cmake/version.cmake)
+ELSEIF(DEFINED ENV{LEMON_VERSION})
+  SET(LEMON_VERSION $ENV{LEMON_VERSION} CACHE STRING "LEMON version string.")
+ELSE()
+  EXECUTE_PROCESS(
+    COMMAND hg id -i
+    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
+    OUTPUT_VARIABLE HG_REVISION
+    ERROR_QUIET
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+  )
+  IF(HG_REVISION STREQUAL "")
+    SET(HG_REVISION "hg-tip")
+  ENDIF()
+  SET(LEMON_VERSION ${HG_REVISION} CACHE STRING "LEMON version string.")
+ENDIF()
 
-INCLUDE(FindDoxygen)
-INCLUDE(FindGhostscript)
+SET(PROJECT_VERSION ${LEMON_VERSION})
 
-ADD_DEFINITIONS(-DHAVE_CONFIG_H)
+SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
+
+FIND_PACKAGE(Doxygen)
+FIND_PACKAGE(Ghostscript)
+FIND_PACKAGE(GLPK 4.33)
+FIND_PACKAGE(CPLEX)
+FIND_PACKAGE(COIN)
 
 INCLUDE(CheckTypeSize)
-CHECK_TYPE_SIZE("long long" LEMON_LONG_LONG)
+CHECK_TYPE_SIZE("long long" LONG_LONG)
+SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
 
 ENABLE_TESTING()
 
 ADD_SUBDIRECTORY(lemon)
-ADD_SUBDIRECTORY(demo)
-ADD_SUBDIRECTORY(doc)
-ADD_SUBDIRECTORY(test)
+IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
+  ADD_SUBDIRECTORY(demo)
+  ADD_SUBDIRECTORY(tools)
+  ADD_SUBDIRECTORY(doc)
+  ADD_SUBDIRECTORY(test)
+ENDIF()
 
-IF(WIN32)
+CONFIGURE_FILE(
+  ${PROJECT_SOURCE_DIR}/cmake/LEMONConfig.cmake.in
+  ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
+  @ONLY
+)
+IF(UNIX)
+  INSTALL(
+    FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
+    DESTINATION share/lemon/cmake
+  )
+ELSEIF(WIN32)
+  INSTALL(
+    FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
+    DESTINATION cmake
+  )
+ENDIF()
+
+IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR} AND WIN32)
   SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
   SET(CPACK_PACKAGE_VENDOR "EGRES")
   SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY
-    "LEMON - Library of Efficient Models and Optimization in Networks")
-  SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
+    "LEMON - Library for Efficient Modeling and Optimization in Networks")
+  SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
 
   SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
@@ -41,8 +77,9 @@
     "${PROJECT_NAME} ${PROJECT_VERSION}")
 
-  SET(CPACK_COMPONENTS_ALL headers library html_documentation)
+  SET(CPACK_COMPONENTS_ALL headers library html_documentation bin)
 
   SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ headers")
   SET(CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "Dynamic-link library")
+  SET(CPACK_COMPONENT_BIN_DISPLAY_NAME "Command line utilities")
   SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DISPLAY_NAME "HTML documentation")
 
@@ -51,4 +88,6 @@
   SET(CPACK_COMPONENT_LIBRARY_DESCRIPTION
     "DLL and import library")
+  SET(CPACK_COMPONENT_BIN_DESCRIPTION
+    "Command line utilities")
   SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DESCRIPTION
     "Doxygen generated documentation")
@@ -72,7 +111,7 @@
 
   SET(CPACK_GENERATOR "NSIS")
-  SET(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/cmake/nsis/lemon.ico")
-  SET(CPACK_NSIS_MUI_UNIICON "${CMAKE_SOURCE_DIR}/cmake/nsis/uninstall.ico")
-  #SET(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/cmake/nsis\\\\installer.bmp")
+  SET(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis/lemon.ico")
+  SET(CPACK_NSIS_MUI_UNIICON "${PROJECT_SOURCE_DIR}/cmake/nsis/uninstall.ico")
+  #SET(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis\\\\installer.bmp")
   SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\lemon.ico")
   SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}")
@@ -89,3 +128,3 @@
 
   INCLUDE(CPack)
-ENDIF(WIN32)
+ENDIF()
