PROJECT( telldus-core )

CMAKE_MINIMUM_REQUIRED( VERSION 2.6.0 )

CMAKE_POLICY(SET CMP0003 NEW)

OPTION(FORCE_COMPILE_FROM_TRUNK FALSE "Accept compiling source from trunk. This is unsupported and highly unrecommended")
IF(NOT FORCE_COMPILE_FROM_TRUNK)
	MESSAGE(FATAL_ERROR "You are compiling sources from trunk. Don't do that!")
ENDIF(NOT FORCE_COMPILE_FROM_TRUNK)

SET(PACKAGE_MAJOR_VERSION 2)
SET(PACKAGE_MINOR_VERSION 1)
SET(PACKAGE_PATCH_VERSION 1)
SET(PACKAGE_VERSION "${PACKAGE_MAJOR_VERSION}.${PACKAGE_MINOR_VERSION}.${PACKAGE_PATCH_VERSION}")
SET(PACKAGE_SUBVERSION "")
SET(PACKAGE_SOVERSION 2)

SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

IF (PACKAGE_SUBVERSION)
	SET(DISPLAYED_VERSION "${PACKAGE_VERSION}_${PACKAGE_SUBVERSION}")
ELSE (PACKAGE_SUBVERSION)
	SET(DISPLAYED_VERSION ${PACKAGE_VERSION})
ENDIF(PACKAGE_SUBVERSION)

SET(BUILD_LIBTELLDUS-CORE	TRUE	CACHE BOOL "Build libtelldus-core")

IF (WIN32)
	SET(TDADMIN_DEFAULT FALSE)
ELSEIF(APPLE)
	SET(TDADMIN_DEFAULT FALSE)
ELSE (WIN32)
	SET(TDADMIN_DEFAULT TRUE)
ENDIF (WIN32)

IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
	INCLUDE_DIRECTORIES(/usr/local/include)
	LINK_DIRECTORIES(/usr/local/lib)
ENDIF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")

SET(BUILD_TDTOOL	TRUE				CACHE BOOL "Build tdtool")
SET(BUILD_TDADMIN	${TDADMIN_DEFAULT}	CACHE BOOL "Build tdadmin")

SET(GENERATE_MAN	FALSE	CACHE	BOOL "Enable generation of man-files")

ADD_SUBDIRECTORY(common)
ADD_SUBDIRECTORY(service)
ADD_SUBDIRECTORY(client)

IF(BUILD_TDTOOL)
	IF(WIN32)
		ADD_SUBDIRECTORY(3rdparty/openbsd-getopt)
	ENDIF()
	ADD_SUBDIRECTORY(tdtool)
ENDIF(BUILD_TDTOOL)
IF(BUILD_TDADMIN)
	ADD_SUBDIRECTORY(tdadmin)
ENDIF(BUILD_TDADMIN)

ENABLE_TESTING()
ADD_SUBDIRECTORY(tests)

FIND_PACKAGE(Doxygen)

IF(DOXYGEN_FOUND)
	SET(DOXY_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

	CONFIGURE_FILE(
		"${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in"
		${DOXY_CONFIG} @ONLY
	)

	ADD_CUSTOM_TARGET(docs
		${DOXYGEN_EXECUTABLE} ${DOXY_CONFIG}
		DEPENDS ${DOXY_CONFIG}
		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
		COMMENT "Generating doxygen documentation" VERBATIM
	)
ENDIF()
