CMakeLists.txt
author Ryan C. Gordon <icculus@icculus.org>
Fri, 13 Feb 2009 18:57:11 -0500
changeset 613 f48e56a16437
parent 599 cef9f9f0f4f4
child 669 fd14a7278a95
permissions -rw-r--r--
Have re2c omit the build timestamp. Now revision control won't think that this file changed every time I rebuild.

CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
PROJECT(MojoShader)

INCLUDE_DIRECTORIES(.)

FIND_PROGRAM(HG hg DOC "Path to hg command line app: http://www.selenic.com/mercurial/")
IF(NOT HG)
    MESSAGE(STATUS "Mercurial (hg) not found. You can go on, but version info will be wrong.")
    SET(MOJOSHADER_VERSION -1)
    SET(MOJOSHADER_CHANGESET "???")
ELSE(NOT HG)
    MARK_AS_ADVANCED(HG)
    EXECUTE_PROCESS(
        COMMAND hg tip --template {rev}
        WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
        RESULT_VARIABLE HGVERSION_RC
        OUTPUT_VARIABLE MOJOSHADER_VERSION
        ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    EXECUTE_PROCESS(
        COMMAND hg tip --template hg-{rev}:{node|short}
        WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
        RESULT_VARIABLE HGVERSION_RC
        OUTPUT_VARIABLE MOJOSHADER_CHANGESET
        ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )
ENDIF(NOT HG)

WRITE_FILE(
    "${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_version.h"
    "/* This file was autogenerated. Do not edit! */\n"
    "#ifndef _INCL_MOJOSHADER_VERSION_H_\n"
    "#define _INCL_MOJOSHADER_VERSION_H_\n"
    "#define MOJOSHADER_VERSION ${MOJOSHADER_VERSION}\n"
    "#define MOJOSHADER_CHANGESET \"${MOJOSHADER_CHANGESET}\"\n"
    "#endif\n"
)

IF(CMAKE_COMPILER_IS_GNUCC)
    ADD_DEFINITIONS(-Wall -ggdb3)
ENDIF(CMAKE_COMPILER_IS_GNUCC)

# testparse uses this when I'm looking at memory usage patterns.
#ADD_DEFINITIONS(-DMOJOSHADER_DEBUG_MALLOC=1)

IF(MSVC)
    ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS=1)
    ADD_DEFINITIONS(-TP)  # force .c files to compile as C++.
ENDIF(MSVC)

ADD_LIBRARY(mojoshader STATIC
    mojoshader.c
    mojoshader_preprocessor.c
    mojoshader_lexer.c
    mojoshader_assembler.c
    mojoshader_opengl.c
)

FIND_PROGRAM(RE2C re2c DOC "Path to re2c command line app: http://re2c.org/")
IF(NOT RE2C)
    MESSAGE(STATUS "re2c missing. You can go on, but can't rebuild the lexer.")
ELSE(NOT RE2C)
    MARK_AS_ADVANCED(RE2C)
    ADD_CUSTOM_COMMAND(
        OUTPUT mojoshader_lexer.c
        DEPENDS mojoshader_lexer.re
        COMMAND ${RE2C}
        ARGS -is --no-generation-date -o ${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_lexer.c ${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_lexer.re
    )
ENDIF(NOT RE2C)

FIND_PACKAGE(SDL)
IF(SDL_FOUND)
    INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
    ADD_DEFINITIONS(-DFINDERRORS_COMPILE_SHADERS=1)
    ADD_EXECUTABLE(glcaps utils/glcaps.c)
    TARGET_LINK_LIBRARIES(glcaps ${SDL_LIBRARY})
    ADD_EXECUTABLE(bestprofile utils/bestprofile.c)
    TARGET_LINK_LIBRARIES(bestprofile mojoshader ${SDL_LIBRARY})
    ADD_EXECUTABLE(availableprofiles utils/availableprofiles.c)
    TARGET_LINK_LIBRARIES(availableprofiles mojoshader ${SDL_LIBRARY})
ENDIF(SDL_FOUND)

ADD_EXECUTABLE(testparse utils/testparse.c)
TARGET_LINK_LIBRARIES(testparse mojoshader)
ADD_EXECUTABLE(testoutput utils/testoutput.c)
TARGET_LINK_LIBRARIES(testoutput mojoshader)
ADD_EXECUTABLE(finderrors utils/finderrors.c)
TARGET_LINK_LIBRARIES(finderrors mojoshader ${SDL_LIBRARY})
ADD_EXECUTABLE(assemble utils/assemble.c)
TARGET_LINK_LIBRARIES(assemble mojoshader)
ADD_EXECUTABLE(preprocess utils/preprocess.c)
TARGET_LINK_LIBRARIES(preprocess mojoshader)

# End of CMakeLists.txt ...