#------------------------------------------------------------------------------
#   Adjust needed compile flags for this project/package
#------------------------------------------------------------------------------

include( CheckCCompilerFlag )   # Check compiler support for certain flags
include( targetver.txt      )   # Define minimum required Windows platform


#------------------------------------------------------------------------------

if( WIN32 )
  set( PKG_C_FLAGS "${PKG_C_FLAGS} -D _CRT_SECURE_NO_WARNINGS" )
endif()

#------------------------------------------------------------------------------

set( CMAKE_C_FLAGS_DEBUG          "${CMAKE_C_FLAGS_DEBUG}          ${PKG_C_FLAGS}" )
set( CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${PKG_C_FLAGS}" )

set( CMAKE_C_FLAGS_DEBUG          "${CMAKE_C_FLAGS_DEBUG}          -D HAVE_PLATFORM_H -D DEBUG" )
set( CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D HAVE_PLATFORM_H" )

set( CMAKE_C_FLAGS_DEBUG          "${CMAKE_C_FLAGS_DEBUG}          -D VERS_STRING=${VERS_STRING}" )
set( CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D VERS_STRING=${VERS_STRING}" )


#------------------------------------------------------------------------------
# Some compilers don't accept either of the '-m32' or '-m64' machine options
# when support only exists for building 32-bit binaries but not 64-bit (i.e.
# if 64-bit support hasn't been installed then neither flag is accepted).
#------------------------------------------------------------------------------

if( NOT WIN32 )

  set( TEMP_CMAKE_REQUIRED_FLAGS  "${CMAKE_REQUIRED_FLAGS}" )
  set( CMAKE_REQUIRED_FLAGS  "-m32" )
  Check_C_Compiler_Flag( -m32  OK )

  if( OK )
    set( m32 "-m32" )
  else()
    set( m32   ""   )
  endif()

  set( CMAKE_REQUIRED_FLAGS  "-m64" )
  Check_C_Compiler_Flag( -m64  OK )
  set( CMAKE_REQUIRED_FLAGS  "${TEMP_CMAKE_REQUIRED_FLAGS}" )

  if( OK )
    set( m64 "-m64" )
  else()
    set( m64   ""   )
  endif()

endif()

#------------------------------------------------------------------------------
