forked from MonoGame/mojoshader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
223 lines (186 loc) · 6.91 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(MojoShader)
INCLUDE_DIRECTORIES(.)
set(CMAKE_BUILD_TYPE Release)
IF(MACOSX)
SET (CMAKE_OSX_ARCHITECTURES "i386" "x86_64")
ADD_DEFINITIONS("-arch i386")
ADD_DEFINITIONS("-arch x86_64")
ENDIF(MACOSX)
IF(IOS)
SET (CMAKE_SYSTEM_PROCESSOR arm)
SET (SDKVER "5.0")
SET (DEVROOT "/Developer/Platforms/iPhoneOS.platform/Developer")
SET (SDKROOT "${DEVROOT}/SDKs/iPhoneOS${SDKVER}.sdk")
SET (CMAKE_OSX_SYSROOT "${SDKROOT}")
SET (CMAKE_OSX_ARCHITECTURES "armv6" "armv7")
SET (CMAKE_C_COMPILER "${DEVROOT}/usr/bin/gcc")
SET (CMAKE_CXX_COMPILER "${DEVROOT}/usr/bin/g++")
ADD_DEFINITIONS("-std=c99")
ADD_DEFINITIONS("-arch armv6")
ADD_DEFINITIONS("-arch armv7")
ADD_DEFINITIONS("-pipe")
ADD_DEFINITIONS("-no-cpp-precomp")
ADD_DEFINITIONS("--sysroot=${SDKROOT}")
ADD_DEFINITIONS("-miphoneos-version-min=${SDKVER}")
INCLUDE_DIRECTORIES(SYSTEM "${SDKROOT}/usr/include")
LINK_DIRECTORIES("${SDKROOT}/usr/lib")
SET (CMAKE_FIND_ROOT_PATH "${SDKROOT}")
SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
ENDIF(IOS)
IF(IOSSIM)
SET (CMAKE_SYSTEM_PROCESSOR i686)
SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
SET (SDKVER "5.0")
SET (DEVROOT "/Developer/Platforms/iPhoneSimulator.platform/Developer")
SET (SDKROOT "${DEVROOT}/SDKs/iPhoneSimulator${SDKVER}.sdk")
SET (CMAKE_OSX_SYSROOT "${SDKROOT}")
SET (CMAKE_OSX_ARCHITECTURES "i386" "x86_64")
SET (CMAKE_C_COMPILER "${DEVROOT}/usr/bin/gcc")
SET (CMAKE_CXX_COMPILER "${DEVROOT}/usr/bin/g++")
ADD_DEFINITIONS("-std=c99")
ADD_DEFINITIONS("-arch i386")
ADD_DEFINITIONS("-arch x86_64")
ADD_DEFINITIONS("-pipe")
ADD_DEFINITIONS("-no-cpp-precomp")
ADD_DEFINITIONS("--sysroot=${SDKROOT}")
ADD_DEFINITIONS("-miphoneos-version-min=${SDKVER}")
INCLUDE_DIRECTORIES(SYSTEM "${SDKROOT}/usr/include")
LINK_DIRECTORIES("${SDKROOT}/usr/lib")
SET (CMAKE_FIND_ROOT_PATH "${SDKROOT}")
SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
ENDIF(IOSSIM)
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)
# We build lemon, then use it to generate parser C code.
IF(NOT IOS AND NOT IOSSIM)
ADD_EXECUTABLE(lemon "misc/lemon.c")
GET_TARGET_PROPERTY(LEMON lemon LOCATION)
ADD_CUSTOM_COMMAND(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_parser_hlsl.h"
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_parser_hlsl.lemon"
DEPENDS lemon "${CMAKE_CURRENT_SOURCE_DIR}/misc/lempar.c"
COMMAND "${LEMON}"
ARGS -q "-T${CMAKE_CURRENT_SOURCE_DIR}/misc/lempar.c" "${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_parser_hlsl.lemon"
)
ENDIF(NOT IOS AND NOT IOSSIM)
IF(IOS OR IOSSIM)
ADD_LIBRARY(mojoshader STATIC
mojoshader.c
mojoshader_common.c
mojoshader_effects.c
mojoshader_compiler.c
mojoshader_preprocessor.c
mojoshader_lexer.c
mojoshader_assembler.c
mojoshader_opengl.c
)
ELSE(IOS OR IOSSIM)
ADD_LIBRARY(mojoshader SHARED
mojoshader.c
mojoshader_common.c
mojoshader_effects.c
mojoshader_compiler.c
mojoshader_preprocessor.c
mojoshader_lexer.c
mojoshader_assembler.c
mojoshader_opengl.c
)
ENDIF(IOS OR IOSSIM)
IF(UNIX)
SET(LIBM -lm)
ENDIF(UNIX)
SET_SOURCE_FILES_PROPERTIES(
mojoshader_compiler.c
PROPERTIES OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/mojoshader_parser_hlsl.h"
)
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 "${CMAKE_CURRENT_SOURCE_DIR}/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_EXECUTABLE(glcaps utils/glcaps.c)
TARGET_LINK_LIBRARIES(glcaps ${SDL_LIBRARY} ${LIBM})
ADD_EXECUTABLE(bestprofile utils/bestprofile.c)
TARGET_LINK_LIBRARIES(bestprofile mojoshader ${SDL_LIBRARY} ${LIBM})
ADD_EXECUTABLE(availableprofiles utils/availableprofiles.c)
TARGET_LINK_LIBRARIES(availableprofiles mojoshader ${SDL_LIBRARY} ${LIBM})
ENDIF(SDL_FOUND)
ADD_EXECUTABLE(finderrors utils/finderrors.c)
TARGET_LINK_LIBRARIES(finderrors mojoshader ${SDL_LIBRARY} ${LIBM})
IF(SDL_FOUND)
SET_SOURCE_FILES_PROPERTIES(
utils/finderrors.c
PROPERTIES COMPILE_FLAGS "-DFINDERRORS_COMPILE_SHADERS=1"
)
ENDIF(SDL_FOUND)
ADD_EXECUTABLE(testparse utils/testparse.c)
TARGET_LINK_LIBRARIES(testparse mojoshader ${LIBM})
ADD_EXECUTABLE(testoutput utils/testoutput.c)
TARGET_LINK_LIBRARIES(testoutput mojoshader ${LIBM})
ADD_EXECUTABLE(mojoshader-compiler utils/mojoshader-compiler.c)
TARGET_LINK_LIBRARIES(mojoshader-compiler mojoshader ${LIBM})
# Unit tests...
ADD_CUSTOM_TARGET(
test
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/run_tests.pl"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
DEPENDS mojoshader-compiler
COMMENT "Running unit tests..."
VERBATIM
)
# End of CMakeLists.txt ...