# Copyright (C) 2006, 2007, 2008, 2009 Thomas Cort <tcort@tomcort.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR)

PROJECT(libproccpuinfo C)

INCLUDE(InstallRequiredSystemLibraries)

# Version Information
SET(CPACK_PACKAGE_VERSION_MAJOR "0")
SET(CPACK_PACKAGE_VERSION_MINOR "0")
SET(CPACK_PACKAGE_VERSION_PATCH "8")
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
SET(VERSION "${CPACK_PACKAGE_VERSION}")
SET(SOVERSION "${CPACK_PACKAGE_VERSION}")

INCLUDE(CTest)
ENABLE_TESTING()

FIND_PROGRAM(FLEX_EXECUTABLE NAMES flex PATHS /usr/bin DOC "Flex executable")
IF (FLEX_EXECUTABLE)
  MESSAGE(STATUS "Found flex: ${FLEX_EXECUTABLE}")
  ADD_CUSTOM_COMMAND(OUTPUT lex.yy.c DEPENDS scanner.l COMMAND ${FLEX_EXECUTABLE} scanner.l)
ELSE (FLEX_EXECUTABLE)
  MESSAGE (FATAL_ERROR "flex not found")
ENDIF (FLEX_EXECUTABLE)

ADD_LIBRARY(proccpuinfo SHARED libproccpuinfo.c cputype.c lex.yy.c)
SET_TARGET_PROPERTIES(proccpuinfo PROPERTIES SOVERSION "${SOVERSION}")
INSTALL(TARGETS proccpuinfo DESTINATION lib)
INSTALL(FILES proccpuinfo.h DESTINATION include)

ADD_SUBDIRECTORY(examples)
ADD_SUBDIRECTORY(tests)
