project (perls)

set (CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

cmake_minimum_required (VERSION 2.6)
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.6)
  message (FATAL_ERROR ">>>>
**Note**: for Ubuntu 8.04 hardy systems, cmake-2.4 is the default install.  To install cmake-2.6 simply issue the following command:
sudo apt-get install -t hardy-backports cmake

You may need to enable the hardy-backports channel in your /etc/apt/sources.list file.  If so, just uncomment or add the following line:
deb http://us.archive.ubuntu.com/ubuntu/ hardy-backports main restricted universe multiverse
<<<<")
endif ()


# Set a default build type for single-configuration
# CMake generators if no build type is set.
if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
   set (CMAKE_BUILD_TYPE Release)
endif ()


# CMAKE_SYSTEM_PROCESSOR doesn't seem to work reliably on ubuntu
# so do this the hard way
execute_process (
  COMMAND uname -a 
  OUTPUT_VARIABLE CMAKE_SYSTEM_PROCESSOR
  )
if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
  set (CMAKE_SYSTEM_PROCESSOR "x86_64" CACHE INTERNAL "processor type (i386 and x86_64)")
else ()
  set (CMAKE_SYSTEM_PROCESSOR "i386" CACHE INTERNAL "processor type (i386 and x86_64)")      
endif ()

# GCC_VERSION
execute_process (COMMAND gcc -dumpversion OUTPUT_VARIABLE GCC_VERSION)

# setup output directories
set (LIBRARY_OUTPUT_PATH 
  "${PROJECT_SOURCE_DIR}/lib"
  CACHE PATH
  "Single directory for all libraries."
  )

set (EXECUTABLE_OUTPUT_PATH 
  "${PROJECT_SOURCE_DIR}/bin"
  CACHE PATH
  "Single directory for all executables."
  )

mark_as_advanced (
  LIBRARY_OUTPUT_PATH
  EXECUTABLE_OUTPUT_PATH
  CMAKE_INSTALL_PREFIX
  )

set (FIND_LIBRARY_USE_LIB64_PATHS 1)

# be helpful and let all projects look for libraries here
link_directories ("${LIBRARY_OUTPUT_PATH}")


option (BUILD_THIRD_PARTY "Build third-party apps?" ON)
if (BUILD_THIRD_PARTY)
  # build third-party libs first before all others
  add_subdirectory (third-party)
elseif (NOT EXISTS ${PROJECT_SOURCE_DIR}/third-party/lcm/CMAKE_BUILT OR
        NOT EXISTS ${PROJECT_SOURCE_DIR}/third-party/prosilica/CMAKE_BUILT)
  message (SEND_ERROR "third-party apps are out of date, you need to rebuild them first")
else ()
  # define some useful third-party vars
  #---------------------------------------------
  # lcm
  find_program (LCM_GEN lcm-gen
    DOC "Fullpath to lcm-gen executable.")
  find_library (LIB_LCM lcm
    DOC "Fullpath to lcm library.")
  set (LCM_DEFS_DIR "${PROJECT_SOURCE_DIR}/lcmdefs")
  include (${LCM_DEFS_DIR}/PACKAGES.cmake)

  # go forth!
  add_subdirectory (src)
  add_subdirectory (java)
  add_subdirectory (python)
endif ()
