# config.h magic
SET(CONFIG_H_VALS_OLD "${CONFIG_H_VALS}")
SET(CONFIG_H_VALS "" CACHE INTERNAL "")
SET(CONFIG_H_FILE ${CMAKE_BINARY_DIR}/config.h)
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})


MACRO(ADD_DEFINE ARG)
SET(CONFIG_H_CONTENT "${CONFIG_H_CONTENT}#define ${ARG}

")
# can't cache mulitline values
SET(CONFIG_H_VALS "${CONFIG_H_VALS}${ARG}" CACHE INTERNAL "")
ENDMACRO(ADD_DEFINE ARG)

MACRO(GENERATE_CONFIG_H)
# Generate config.h only if values differ
IF(NOT CONFIG_H_VALS_OLD STREQUAL CONFIG_H_VALS OR NOT EXISTS ${CONFIG_H_FILE})
  MESSAGE(STATUS "Writing config.h")
  FILE(WRITE ${CONFIG_H_FILE} "${CONFIG_H_CONTENT}")
ENDIF(NOT CONFIG_H_VALS_OLD STREQUAL CONFIG_H_VALS OR NOT EXISTS ${CONFIG_H_FILE})
ENDMACRO(GENERATE_CONFIG_H)