# Copyright (c) 2008,2009,2010, CodeSloop Team
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

INCLUDE(TestBigEndian)
INCLUDE(DetectIgep)
INCLUDE(DetectGcc)

# endianness
TEST_BIG_ENDIAN(BIG_ENDIAN)
SET(ENDIAN_FLAGS " -DCSL_LITTLE_ENDIAN -DCSL_BYTE_ORDER=4321 " )
IF(BIG_ENDIAN)
  SET(ENDIAN_FLAGS " -DCSL_BIG_ENDIAN -DCSL_BYTE_ORDER=1234 " )
ENDIF(BIG_ENDIAN)

# platform flags
SET(PLATFORM_FLAGS " -D${CMAKE_SYSTEM_NAME}_PLATFORM ")

IF(WIN32)
  SET(PLATFORM_FLAGS " ${PLATFORM_FLAGS} -DWIN32 ")
ENDIF(WIN32)

IF(MINGW)
  SET(PLATFORM_FLAGS " ${PLATFORM_FLAGS} -DMINGW ")
ENDIF(MINGW)

IF(CMAKE_SYSTEM_NAME MATCHES "MSYS")
  SET(PLATFORM_FLAGS " ${PLATFORM_FLAGS} -DMSYS ")
ENDIF(CMAKE_SYSTEM_NAME MATCHES "MSYS")

IF(CYGWIN)
  SET(PLATFORM_FLAGS " ${PLATFORM_FLAGS} -DCYGWIN ")
ENDIF(CYGWIN)

IF(UNIX)
  SET(PLATFORM_FLAGS " ${PLATFORM_FLAGS} -DUNIX ")
ENDIF(UNIX)

IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
  SET(PLATFORM_FLAGS " ${PLATFORM_FLAGS} -DLINUX ")
ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux")

IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
  SET(PLATFORM_FLAGS " ${PLATFORM_FLAGS} -DFREEBSD ")
ENDIF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")

IF(APPLE)
  SET(PLATFORM_FLAGS " ${PLATFORM_FLAGS} -DAPPLE ")
ENDIF(APPLE)

IF(MSVC)
  SET(PLATFORM_FLAGS " ${PLATFORM_FLAGS} -DMSVC ")
ENDIF(MSVC)

# IGEP and GCC flags can safely be added here
# because they are set to empty if not usable

SET(COMMON_CXX_FLAGS " ${IGEP_CXX_FLAGS} ${PLATFORM_FLAGS} ${ENDIAN_FLAGS} ")
SET(COMMON_C_FLAGS " ${IGEP_C_FLAGS} ${PLATFORM_FLAGS} ${ENDIAN_FLAGS} ")

SET(CMAKE_C_FLAGS_DEBUG " ${GCC_C_FLAGS_DEBUG} ${COMMON_C_FLAGS} ")
SET(CMAKE_C_FLAGS_RELEASE " ${GCC_C_FLAGS_RELEASE} ${COMMON_C_FLAGS} ")

SET(CMAKE_CXX_FLAGS_DEBUG " ${GCC_CXX_FLAGS_DEBUG} ${COMMON_CXX_FLAGS} ")
SET(CMAKE_CXX_FLAGS_RELEASE " ${GCC_CXX_FLAGS_RELEASE} ${COMMON_CXX_FLAGS} ")

# default is debug configuration
SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_DEBUG})
SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_DEBUG})

# change config if release
IF(CMAKE_BUILD_TYPE MATCHES "release")
  SET(CMAKE_C_FLAGS ${CMAKE_CXX_FLAGS_RELEASE})
  SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_RELEASE})
ENDIF(CMAKE_BUILD_TYPE MATCHES "release")

MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
MESSAGE(STATUS "C FLAGS:    " ${CMAKE_C_FLAGS})
MESSAGE(STATUS "CXX FLAGS:  " ${CMAKE_CXX_FLAGS})

# -- EOF --
