OSDN Git Service

glGetFragDataLocation implementation
[android-x86/external-swiftshader.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8)
2
3 project(SwiftShader C CXX)
4
5 ###########################################################
6 # Detect system
7 ###########################################################
8
9 if(CMAKE_SYSTEM_NAME MATCHES "Linux")
10     set(LINUX ON)
11 elseif(WIN32)
12 elseif(APPLE)
13 else()
14     message(FATAL_ERROR "Platform is not supported")
15 endif()
16
17 if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch")
18     if(CMAKE_SIZEOF_VOID_P EQUAL 8)
19         set(ARCH "aarch64")
20     else()
21         set(ARCH "arm")
22     endif()
23 else()
24     if(CMAKE_SIZEOF_VOID_P EQUAL 8)
25         set(ARCH "x86_64")
26     else()
27         set(ARCH "x86")
28     endif()
29 endif()
30
31 set(CMAKE_MACOSX_RPATH ON)
32
33 ###########################################################
34 # Options
35 ###########################################################
36
37 if(NOT CMAKE_BUILD_TYPE)
38     set(CMAKE_BUILD_TYPE "Release" CACHE STRING "The type of build: Debug Release MinSizeRel RelWithDebInfo." FORCE)
39 endif()
40 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo)
41
42 option(BUILD_EGL "Build the EGL library" 1)
43 if(WIN32)
44     option(BUILD_GL32 "Build the OpenGL32 library" 1)
45 endif()
46 option(BUILD_GLESv2 "Build the OpenGL ES 2 library" 1)
47 option(BUILD_GLES_CM "Build the OpenGL ES 1.1 library" 1)
48
49 option(USE_GROUP_SOURCES "Group the source files in a folder tree for Visual Studio" 1)
50
51 option(BUILD_SAMPLES "Build sample programs" 1)
52 option(BUILD_TESTS "Build test programs" 1)
53
54 if(ARCH STREQUAL "arm")
55     set(DEFAULT_REACTOR_BACKEND "Subzero")
56 else()
57     set(DEFAULT_REACTOR_BACKEND "LLVM")
58 endif()
59
60 set(REACTOR_BACKEND DEFAULT_REACTOR_BACKEND CACHE STRING "JIT compiler back-end used by Reactor")
61 set_property(CACHE REACTOR_BACKEND PROPERTY STRINGS LLVM Subzero)
62
63 # LLVM disallows calling cmake . from the main LLVM dir, the reason is that
64 # it builds header files that could overwrite the orignal ones. Here we
65 # want to include LLVM as a subdirectory and even though it wouldn't cause
66 # the problem, if cmake . is called from the main dir, the condition that
67 # LLVM checkes, "CMAKE_SOURCE_DIR == CMAKE_BINARY_DIR" will be true. So we
68 # disallow it ourselves too to. In addition if there are remining CMakeFiles
69 # and CMakeCache in the directory, cmake .. from a subdirectory will still
70 # try to build from the main directory so we instruct users to delete these
71 # files when they get the error.
72 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
73     message(FATAL_ERROR "In source builds are not allowed by LLVM, please create a build/ directory and build from there. You may have to delete the CMakeCache.txt file and CMakeFiles directory that are next to the CMakeLists.txt.")
74 endif()
75
76 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
77
78 ###########################################################
79 # Convenience macros
80 ###########################################################
81
82 # Recursively calls source_group on the files of the directory
83 # so that Visual Studio has the files in a folder tree
84 macro(group_all_sources directory)
85     file(GLOB files RELATIVE ${CMAKE_SOURCE_DIR}/${directory} ${CMAKE_SOURCE_DIR}/${directory}/*)
86     foreach(file ${files})
87         if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/${directory}/${file})
88             group_all_sources(${directory}/${file})
89         else()
90             string(REPLACE "/" "\\" groupname ${directory})
91             source_group(${groupname} FILES ${CMAKE_SOURCE_DIR}/${directory}/${file})
92         endif()
93     endforeach()
94 endmacro()
95
96 # Takes target library and a directory where the export map is
97 # and add the linker options so that only the API symbols are
98 # exported.
99 macro(set_target_export_map TARGET DIR)
100     get_target_property(LINKFLAGS ${TARGET} LINK_FLAGS)
101     if(LINKFLAGS MATCHES "NOTFOUND")
102         set(LINKFLAGS "")
103     endif()
104     if(MSVC)
105         set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "/DEF:\"${DIR}/${TARGET}.def\"")
106     elseif(LINUX)
107         # Both hash-style are needed, because we want both gold and
108         # GNU ld to be able to read our libraries (maybe?).
109         # The version script only exports the API functions and
110         # hides all the others. Gc sections is used in combination
111         # with each functions being in its section, to reduce the
112         # binary size.
113         set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "${LINKFLAGS} -Wl,--hash-style=both,--version-script=${DIR}/exports.map,--gc-sections,--no-undefined")
114     endif()
115 endmacro()
116
117 if(USE_GROUP_SOURCES)
118     group_all_sources(src)
119 endif()
120
121 ###########################################################
122 # Directories
123 ###########################################################
124
125 set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
126 set(OPENGL_DIR ${SOURCE_DIR}/OpenGL)
127 set(OPENGL_COMPILER_DIR ${OPENGL_DIR}/compiler)
128 set(LLVM_DIR ${CMAKE_SOURCE_DIR}/third_party/LLVM)
129 set(SUBZERO_DIR ${CMAKE_SOURCE_DIR}/third_party/subzero)
130 set(SUBZERO_LLVM_DIR ${CMAKE_SOURCE_DIR}/third_party/llvm-subzero)
131 set(TESTS_DIR ${CMAKE_SOURCE_DIR}/tests)
132 set(HELLO2_DIR ${CMAKE_SOURCE_DIR}/third_party/PowerVR_SDK/Examples/Beginner/01_HelloAPI/OGLES2)
133
134 ###########################################################
135 # Compile flags
136 ###########################################################
137
138 macro(set_cpp_flag FLAG)
139     if(${ARGC} GREATER 1)
140         set(CMAKE_CXX_FLAGS_${ARGV1} "${CMAKE_CXX_FLAGS_${ARGV1}} ${FLAG}")
141     else()
142         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
143     endif()
144 endmacro()
145
146 if(MSVC)
147     set_cpp_flag("/MP")
148     add_definitions(-D_CRT_SECURE_NO_WARNINGS)
149 else()
150     set_cpp_flag("--std=c++11")
151     set_cpp_flag("-Wall")
152     set_cpp_flag("-fno-exceptions")
153
154     # Don't allow symbols to be overridden by another module.
155     # This enables libGLES_CM and libGLESv2 to statically link LLVM.
156     set_cpp_flag("-fvisibility=protected")
157
158     # Remove xor, and, or and friends from the list of keywords, they are used
159     # by Reactor
160     set_cpp_flag("-fno-operator-names")
161
162     # LLVM headers requires these flags to be set
163     set_cpp_flag("-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS")
164
165     if(ARCH EQUAL "x86")
166         set_cpp_flag("-m32")
167         set_cpp_flag("-msse2")
168         set_cpp_flag("-march=i686")
169     endif()
170     if(ARCH EQUAL "x86_64")
171         set_cpp_flag("-m64")
172         set_cpp_flag("-fPIC")
173         set_cpp_flag("-march=core2")
174     endif()
175
176     # Use -g3 to have even more debug info
177     set_cpp_flag("-g -g3" DEBUG)
178     set_cpp_flag("-g -g3" RELWITHDEBINFO)
179     set_cpp_flag("-s" RELEASE)
180
181     # For distribution it is more important to be slim than super optimized
182     set_cpp_flag("-Os" RELEASE)
183     set_cpp_flag("-Os" RELWITHDEBINFO)
184
185     set_cpp_flag("-DNDEBUG" RELEASE)
186     set_cpp_flag("-DNDEBUG" RELWITHDEBINFO)
187     set_cpp_flag("-DANGLE_DISABLE_TRACE" RELEASE)
188     set_cpp_flag("-DANGLE_DISABLE_TRACE" RELWITHDEBINFO)
189
190     # Put each variable and function in its own section so that when linking
191     # with -gc-sections unused functions and variables are removed.
192     set_cpp_flag("-ffunction-sections" RELEASE)
193     set_cpp_flag("-fdata-sections" RELEASE)
194     set_cpp_flag("-fomit-frame-pointer" RELEASE)
195 endif()
196
197 if( WIN32 )
198     add_definitions(-DWINVER=0x501 -DNOMINMAX -DSTRICT)
199     set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "" "lib")
200 endif()
201
202
203 ###########################################################
204 # LLVM
205 ###########################################################
206
207 set(LLVM_LIST
208     ${LLVM_DIR}/lib/Analysis/AliasAnalysis.cpp
209     ${LLVM_DIR}/lib/Analysis/AliasSetTracker.cpp
210     ${LLVM_DIR}/lib/Analysis/BasicAliasAnalysis.cpp
211     ${LLVM_DIR}/lib/Analysis/BranchProbabilityInfo.cpp
212     ${LLVM_DIR}/lib/Analysis/CaptureTracking.cpp
213     ${LLVM_DIR}/lib/Analysis/ConstantFolding.cpp
214     ${LLVM_DIR}/lib/Analysis/DIBuilder.cpp
215     ${LLVM_DIR}/lib/Analysis/DebugInfo.cpp
216     ${LLVM_DIR}/lib/Analysis/IVUsers.cpp
217     ${LLVM_DIR}/lib/Analysis/InstructionSimplify.cpp
218     ${LLVM_DIR}/lib/Analysis/Loads.cpp
219     ${LLVM_DIR}/lib/Analysis/LoopInfo.cpp
220     ${LLVM_DIR}/lib/Analysis/LoopPass.cpp
221     ${LLVM_DIR}/lib/Analysis/MemoryBuiltins.cpp
222     ${LLVM_DIR}/lib/Analysis/MemoryDependenceAnalysis.cpp
223     ${LLVM_DIR}/lib/Analysis/NoAliasAnalysis.cpp
224     ${LLVM_DIR}/lib/Analysis/PHITransAddr.cpp
225     ${LLVM_DIR}/lib/Analysis/PathNumbering.cpp
226     ${LLVM_DIR}/lib/Analysis/ProfileInfo.cpp
227     ${LLVM_DIR}/lib/Analysis/ScalarEvolution.cpp
228     ${LLVM_DIR}/lib/Analysis/ScalarEvolutionExpander.cpp
229     ${LLVM_DIR}/lib/Analysis/ScalarEvolutionNormalization.cpp
230     ${LLVM_DIR}/lib/Analysis/TypeBasedAliasAnalysis.cpp
231     ${LLVM_DIR}/lib/Analysis/ValueTracking.cpp
232     ${LLVM_DIR}/lib/CodeGen/AggressiveAntiDepBreaker.cpp
233     ${LLVM_DIR}/lib/CodeGen/AllocationOrder.cpp
234     ${LLVM_DIR}/lib/CodeGen/Analysis.cpp
235     ${LLVM_DIR}/lib/CodeGen/BranchFolding.cpp
236     ${LLVM_DIR}/lib/CodeGen/CalcSpillWeights.cpp
237     ${LLVM_DIR}/lib/CodeGen/CallingConvLower.cpp
238     ${LLVM_DIR}/lib/CodeGen/CodePlacementOpt.cpp
239     ${LLVM_DIR}/lib/CodeGen/CriticalAntiDepBreaker.cpp
240     ${LLVM_DIR}/lib/CodeGen/DeadMachineInstructionElim.cpp
241     ${LLVM_DIR}/lib/CodeGen/DwarfEHPrepare.cpp
242     ${LLVM_DIR}/lib/CodeGen/ELFCodeEmitter.cpp
243     ${LLVM_DIR}/lib/CodeGen/ELFWriter.cpp
244     ${LLVM_DIR}/lib/CodeGen/EdgeBundles.cpp
245     ${LLVM_DIR}/lib/CodeGen/ExecutionDepsFix.cpp
246     ${LLVM_DIR}/lib/CodeGen/ExpandISelPseudos.cpp
247     ${LLVM_DIR}/lib/CodeGen/ExpandPostRAPseudos.cpp
248     ${LLVM_DIR}/lib/CodeGen/GCMetadata.cpp
249     ${LLVM_DIR}/lib/CodeGen/GCStrategy.cpp
250     ${LLVM_DIR}/lib/CodeGen/InlineSpiller.cpp
251     ${LLVM_DIR}/lib/CodeGen/InterferenceCache.cpp
252     ${LLVM_DIR}/lib/CodeGen/IntrinsicLowering.cpp
253     ${LLVM_DIR}/lib/CodeGen/LLVMTargetMachine.cpp
254     ${LLVM_DIR}/lib/CodeGen/LatencyPriorityQueue.cpp
255     ${LLVM_DIR}/lib/CodeGen/LexicalScopes.cpp
256     ${LLVM_DIR}/lib/CodeGen/LiveDebugVariables.cpp
257     ${LLVM_DIR}/lib/CodeGen/LiveInterval.cpp
258     ${LLVM_DIR}/lib/CodeGen/LiveIntervalAnalysis.cpp
259     ${LLVM_DIR}/lib/CodeGen/LiveIntervalUnion.cpp
260     ${LLVM_DIR}/lib/CodeGen/LiveRangeCalc.cpp
261     ${LLVM_DIR}/lib/CodeGen/LiveRangeEdit.cpp
262     ${LLVM_DIR}/lib/CodeGen/LiveStackAnalysis.cpp
263     ${LLVM_DIR}/lib/CodeGen/LiveVariables.cpp
264     ${LLVM_DIR}/lib/CodeGen/LocalStackSlotAllocation.cpp
265     ${LLVM_DIR}/lib/CodeGen/MachineBasicBlock.cpp
266     ${LLVM_DIR}/lib/CodeGen/MachineCSE.cpp
267     ${LLVM_DIR}/lib/CodeGen/MachineDominators.cpp
268     ${LLVM_DIR}/lib/CodeGen/MachineFunction.cpp
269     ${LLVM_DIR}/lib/CodeGen/MachineFunctionAnalysis.cpp
270     ${LLVM_DIR}/lib/CodeGen/MachineFunctionPass.cpp
271     ${LLVM_DIR}/lib/CodeGen/MachineFunctionPrinterPass.cpp
272     ${LLVM_DIR}/lib/CodeGen/MachineInstr.cpp
273     ${LLVM_DIR}/lib/CodeGen/MachineLICM.cpp
274     ${LLVM_DIR}/lib/CodeGen/MachineLoopInfo.cpp
275     ${LLVM_DIR}/lib/CodeGen/MachineModuleInfo.cpp
276     ${LLVM_DIR}/lib/CodeGen/MachineModuleInfoImpls.cpp
277     ${LLVM_DIR}/lib/CodeGen/MachinePassRegistry.cpp
278     ${LLVM_DIR}/lib/CodeGen/MachineRegisterInfo.cpp
279     ${LLVM_DIR}/lib/CodeGen/MachineSSAUpdater.cpp
280     ${LLVM_DIR}/lib/CodeGen/MachineSink.cpp
281     ${LLVM_DIR}/lib/CodeGen/MachineVerifier.cpp
282     ${LLVM_DIR}/lib/CodeGen/ObjectCodeEmitter.cpp
283     ${LLVM_DIR}/lib/CodeGen/OptimizePHIs.cpp
284     ${LLVM_DIR}/lib/CodeGen/PHIElimination.cpp
285     ${LLVM_DIR}/lib/CodeGen/PHIEliminationUtils.cpp
286     ${LLVM_DIR}/lib/CodeGen/Passes.cpp
287     ${LLVM_DIR}/lib/CodeGen/PeepholeOptimizer.cpp
288     ${LLVM_DIR}/lib/CodeGen/PostRASchedulerList.cpp
289     ${LLVM_DIR}/lib/CodeGen/ProcessImplicitDefs.cpp
290     ${LLVM_DIR}/lib/CodeGen/PrologEpilogInserter.cpp
291     ${LLVM_DIR}/lib/CodeGen/PseudoSourceValue.cpp
292     ${LLVM_DIR}/lib/CodeGen/RegAllocBasic.cpp
293     ${LLVM_DIR}/lib/CodeGen/RegAllocFast.cpp
294     ${LLVM_DIR}/lib/CodeGen/RegAllocGreedy.cpp
295     ${LLVM_DIR}/lib/CodeGen/RegAllocLinearScan.cpp
296     ${LLVM_DIR}/lib/CodeGen/RegisterClassInfo.cpp
297     ${LLVM_DIR}/lib/CodeGen/RegisterCoalescer.cpp
298     ${LLVM_DIR}/lib/CodeGen/RegisterScavenging.cpp
299     ${LLVM_DIR}/lib/CodeGen/RenderMachineFunction.cpp
300     ${LLVM_DIR}/lib/CodeGen/ScheduleDAG.cpp
301     ${LLVM_DIR}/lib/CodeGen/ScheduleDAGEmit.cpp
302     ${LLVM_DIR}/lib/CodeGen/ScheduleDAGInstrs.cpp
303     ${LLVM_DIR}/lib/CodeGen/ScheduleDAGPrinter.cpp
304     ${LLVM_DIR}/lib/CodeGen/ScoreboardHazardRecognizer.cpp
305     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
306     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/FastISel.cpp
307     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
308     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
309     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
310     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
311     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
312     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
313     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/LegalizeTypesGeneric.cpp
314     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
315     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
316     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/ScheduleDAGFast.cpp
317     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/ScheduleDAGList.cpp
318     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp
319     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
320     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
321     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
322     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
323     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
324     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/TargetLowering.cpp
325     ${LLVM_DIR}/lib/CodeGen/SelectionDAG/TargetSelectionDAGInfo.cpp
326     ${LLVM_DIR}/lib/CodeGen/ShrinkWrapping.cpp
327     ${LLVM_DIR}/lib/CodeGen/SjLjEHPrepare.cpp
328     ${LLVM_DIR}/lib/CodeGen/SlotIndexes.cpp
329     ${LLVM_DIR}/lib/CodeGen/SpillPlacement.cpp
330     ${LLVM_DIR}/lib/CodeGen/Spiller.cpp
331     ${LLVM_DIR}/lib/CodeGen/SplitKit.cpp
332     ${LLVM_DIR}/lib/CodeGen/StackProtector.cpp
333     ${LLVM_DIR}/lib/CodeGen/StackSlotColoring.cpp
334     ${LLVM_DIR}/lib/CodeGen/StrongPHIElimination.cpp
335     ${LLVM_DIR}/lib/CodeGen/TailDuplication.cpp
336     ${LLVM_DIR}/lib/CodeGen/TargetInstrInfoImpl.cpp
337     ${LLVM_DIR}/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
338     ${LLVM_DIR}/lib/CodeGen/TwoAddressInstructionPass.cpp
339     ${LLVM_DIR}/lib/CodeGen/UnreachableBlockElim.cpp
340     ${LLVM_DIR}/lib/CodeGen/VirtRegMap.cpp
341     ${LLVM_DIR}/lib/CodeGen/VirtRegRewriter.cpp
342     ${LLVM_DIR}/lib/ExecutionEngine/ExecutionEngine.cpp
343     ${LLVM_DIR}/lib/ExecutionEngine/JIT/Intercept.cpp
344     ${LLVM_DIR}/lib/ExecutionEngine/JIT/JIT.cpp
345     ${LLVM_DIR}/lib/ExecutionEngine/JIT/JITDebugRegisterer.cpp
346     ${LLVM_DIR}/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp
347     ${LLVM_DIR}/lib/ExecutionEngine/JIT/JITEmitter.cpp
348     ${LLVM_DIR}/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
349     ${LLVM_DIR}/lib/ExecutionEngine/JIT/OProfileJITEventListener.cpp
350     ${LLVM_DIR}/lib/ExecutionEngine/TargetSelect.cpp
351     ${LLVM_DIR}/lib/MC/ELFObjectWriter.cpp
352     ${LLVM_DIR}/lib/MC/MCAsmBackend.cpp
353     ${LLVM_DIR}/lib/MC/MCAsmInfo.cpp
354     ${LLVM_DIR}/lib/MC/MCAsmInfoCOFF.cpp
355     ${LLVM_DIR}/lib/MC/MCAsmInfoDarwin.cpp
356     ${LLVM_DIR}/lib/MC/MCAsmStreamer.cpp
357     ${LLVM_DIR}/lib/MC/MCAssembler.cpp
358     ${LLVM_DIR}/lib/MC/MCCodeEmitter.cpp
359     ${LLVM_DIR}/lib/MC/MCCodeGenInfo.cpp
360     ${LLVM_DIR}/lib/MC/MCContext.cpp
361     ${LLVM_DIR}/lib/MC/MCDwarf.cpp
362     ${LLVM_DIR}/lib/MC/MCELF.cpp
363     ${LLVM_DIR}/lib/MC/MCELFObjectTargetWriter.cpp
364     ${LLVM_DIR}/lib/MC/MCELFStreamer.cpp
365     ${LLVM_DIR}/lib/MC/MCExpr.cpp
366     ${LLVM_DIR}/lib/MC/MCInst.cpp
367     ${LLVM_DIR}/lib/MC/MCInstPrinter.cpp
368     ${LLVM_DIR}/lib/MC/MCInstrAnalysis.cpp
369     ${LLVM_DIR}/lib/MC/MCLoggingStreamer.cpp
370     ${LLVM_DIR}/lib/MC/MCMachOStreamer.cpp
371     ${LLVM_DIR}/lib/MC/MCMachObjectTargetWriter.cpp
372     ${LLVM_DIR}/lib/MC/MCNullStreamer.cpp
373     ${LLVM_DIR}/lib/MC/MCObjectFileInfo.cpp
374     ${LLVM_DIR}/lib/MC/MCObjectStreamer.cpp
375     ${LLVM_DIR}/lib/MC/MCObjectWriter.cpp
376     ${LLVM_DIR}/lib/MC/MCSection.cpp
377     ${LLVM_DIR}/lib/MC/MCSectionCOFF.cpp
378     ${LLVM_DIR}/lib/MC/MCSectionELF.cpp
379     ${LLVM_DIR}/lib/MC/MCSectionMachO.cpp
380     ${LLVM_DIR}/lib/MC/MCStreamer.cpp
381     ${LLVM_DIR}/lib/MC/MCSubtargetInfo.cpp
382     ${LLVM_DIR}/lib/MC/MCSymbol.cpp
383     ${LLVM_DIR}/lib/MC/MCWin64EH.cpp
384     ${LLVM_DIR}/lib/MC/MachObjectWriter.cpp
385     ${LLVM_DIR}/lib/MC/SubtargetFeature.cpp
386     ${LLVM_DIR}/lib/MC/WinCOFFObjectWriter.cpp
387     ${LLVM_DIR}/lib/MC/WinCOFFStreamer.cpp
388     ${LLVM_DIR}/lib/Support/APFloat.cpp
389     ${LLVM_DIR}/lib/Support/APInt.cpp
390     ${LLVM_DIR}/lib/Support/Allocator.cpp
391     ${LLVM_DIR}/lib/Support/Atomic.cpp
392     ${LLVM_DIR}/lib/Support/BlockFrequency.cpp
393     ${LLVM_DIR}/lib/Support/BranchProbability.cpp
394     ${LLVM_DIR}/lib/Support/CommandLine.cpp
395     ${LLVM_DIR}/lib/Support/ConstantRange.cpp
396     ${LLVM_DIR}/lib/Support/CrashRecoveryContext.cpp
397     ${LLVM_DIR}/lib/Support/DAGDeltaAlgorithm.cpp
398     ${LLVM_DIR}/lib/Support/DataExtractor.cpp
399     ${LLVM_DIR}/lib/Support/Debug.cpp
400     ${LLVM_DIR}/lib/Support/DeltaAlgorithm.cpp
401     ${LLVM_DIR}/lib/Support/Disassembler.cpp
402     ${LLVM_DIR}/lib/Support/Dwarf.cpp
403     ${LLVM_DIR}/lib/Support/DynamicLibrary.cpp
404     ${LLVM_DIR}/lib/Support/Errno.cpp
405     ${LLVM_DIR}/lib/Support/ErrorHandling.cpp
406     ${LLVM_DIR}/lib/Support/FileUtilities.cpp
407     ${LLVM_DIR}/lib/Support/FoldingSet.cpp
408     ${LLVM_DIR}/lib/Support/FormattedStream.cpp
409     ${LLVM_DIR}/lib/Support/GraphWriter.cpp
410     ${LLVM_DIR}/lib/Support/Host.cpp
411     ${LLVM_DIR}/lib/Support/IncludeFile.cpp
412     ${LLVM_DIR}/lib/Support/IntEqClasses.cpp
413     ${LLVM_DIR}/lib/Support/IntervalMap.cpp
414     ${LLVM_DIR}/lib/Support/IsInf.cpp
415     ${LLVM_DIR}/lib/Support/IsNAN.cpp
416     ${LLVM_DIR}/lib/Support/ManagedStatic.cpp
417     ${LLVM_DIR}/lib/Support/Memory.cpp
418     ${LLVM_DIR}/lib/Support/MemoryBuffer.cpp
419     ${LLVM_DIR}/lib/Support/MemoryObject.cpp
420     ${LLVM_DIR}/lib/Support/Mutex.cpp
421     ${LLVM_DIR}/lib/Support/Path.cpp
422     ${LLVM_DIR}/lib/Support/PathV2.cpp
423     ${LLVM_DIR}/lib/Support/PrettyStackTrace.cpp
424     ${LLVM_DIR}/lib/Support/Process.cpp
425     ${LLVM_DIR}/lib/Support/Program.cpp
426     ${LLVM_DIR}/lib/Support/RWMutex.cpp
427     ${LLVM_DIR}/lib/Support/SearchForAddressOfSpecialSymbol.cpp
428     ${LLVM_DIR}/lib/Support/Signals.cpp
429     ${LLVM_DIR}/lib/Support/SmallPtrSet.cpp
430     ${LLVM_DIR}/lib/Support/SmallVector.cpp
431     ${LLVM_DIR}/lib/Support/SourceMgr.cpp
432     ${LLVM_DIR}/lib/Support/Statistic.cpp
433     ${LLVM_DIR}/lib/Support/StringExtras.cpp
434     ${LLVM_DIR}/lib/Support/StringMap.cpp
435     ${LLVM_DIR}/lib/Support/StringPool.cpp
436     ${LLVM_DIR}/lib/Support/StringRef.cpp
437     ${LLVM_DIR}/lib/Support/SystemUtils.cpp
438     ${LLVM_DIR}/lib/Support/TargetRegistry.cpp
439     ${LLVM_DIR}/lib/Support/ThreadLocal.cpp
440     ${LLVM_DIR}/lib/Support/Threading.cpp
441     ${LLVM_DIR}/lib/Support/TimeValue.cpp
442     ${LLVM_DIR}/lib/Support/Timer.cpp
443     ${LLVM_DIR}/lib/Support/ToolOutputFile.cpp
444     ${LLVM_DIR}/lib/Support/Triple.cpp
445     ${LLVM_DIR}/lib/Support/Twine.cpp
446     ${LLVM_DIR}/lib/Support/Valgrind.cpp
447     ${LLVM_DIR}/lib/Support/circular_raw_ostream.cpp
448     ${LLVM_DIR}/lib/Support/raw_os_ostream.cpp
449     ${LLVM_DIR}/lib/Support/raw_ostream.cpp
450     ${LLVM_DIR}/lib/Support/system_error.cpp
451     ${LLVM_DIR}/lib/Target/Mangler.cpp
452     ${LLVM_DIR}/lib/Target/TargetData.cpp
453     ${LLVM_DIR}/lib/Target/TargetELFWriterInfo.cpp
454     ${LLVM_DIR}/lib/Target/TargetFrameLowering.cpp
455     ${LLVM_DIR}/lib/Target/TargetInstrInfo.cpp
456     ${LLVM_DIR}/lib/Target/TargetLibraryInfo.cpp
457     ${LLVM_DIR}/lib/Target/TargetLoweringObjectFile.cpp
458     ${LLVM_DIR}/lib/Target/TargetMachine.cpp
459     ${LLVM_DIR}/lib/Target/TargetRegisterInfo.cpp
460     ${LLVM_DIR}/lib/Target/TargetSubtargetInfo.cpp
461     ${LLVM_DIR}/lib/Target/X86/InstPrinter/X86ATTInstPrinter.cpp
462     ${LLVM_DIR}/lib/Target/X86/InstPrinter/X86InstComments.cpp
463     ${LLVM_DIR}/lib/Target/X86/InstPrinter/X86IntelInstPrinter.cpp
464     ${LLVM_DIR}/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
465     ${LLVM_DIR}/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
466     ${LLVM_DIR}/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
467     ${LLVM_DIR}/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
468     ${LLVM_DIR}/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
469     ${LLVM_DIR}/lib/Target/X86/TargetInfo/X86TargetInfo.cpp
470     ${LLVM_DIR}/lib/Target/X86/Utils/X86ShuffleDecode.cpp
471     ${LLVM_DIR}/lib/Target/X86/X86CodeEmitter.cpp
472     ${LLVM_DIR}/lib/Target/X86/X86ELFWriterInfo.cpp
473     ${LLVM_DIR}/lib/Target/X86/X86FastISel.cpp
474     ${LLVM_DIR}/lib/Target/X86/X86FloatingPoint.cpp
475     ${LLVM_DIR}/lib/Target/X86/X86FrameLowering.cpp
476     ${LLVM_DIR}/lib/Target/X86/X86ISelDAGToDAG.cpp
477     ${LLVM_DIR}/lib/Target/X86/X86ISelLowering.cpp
478     ${LLVM_DIR}/lib/Target/X86/X86InstrInfo.cpp
479     ${LLVM_DIR}/lib/Target/X86/X86JITInfo.cpp
480     ${LLVM_DIR}/lib/Target/X86/X86RegisterInfo.cpp
481     ${LLVM_DIR}/lib/Target/X86/X86SelectionDAGInfo.cpp
482     ${LLVM_DIR}/lib/Target/X86/X86Subtarget.cpp
483     ${LLVM_DIR}/lib/Target/X86/X86TargetMachine.cpp
484     ${LLVM_DIR}/lib/Target/X86/X86TargetObjectFile.cpp
485     ${LLVM_DIR}/lib/Target/X86/X86VZeroUpper.cpp
486     ${LLVM_DIR}/lib/Transforms/InstCombine/InstCombineAddSub.cpp
487     ${LLVM_DIR}/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
488     ${LLVM_DIR}/lib/Transforms/InstCombine/InstCombineCalls.cpp
489     ${LLVM_DIR}/lib/Transforms/InstCombine/InstCombineCasts.cpp
490     ${LLVM_DIR}/lib/Transforms/InstCombine/InstCombineCompares.cpp
491     ${LLVM_DIR}/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
492     ${LLVM_DIR}/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
493     ${LLVM_DIR}/lib/Transforms/InstCombine/InstCombinePHI.cpp
494     ${LLVM_DIR}/lib/Transforms/InstCombine/InstCombineSelect.cpp
495     ${LLVM_DIR}/lib/Transforms/InstCombine/InstCombineShifts.cpp
496     ${LLVM_DIR}/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
497     ${LLVM_DIR}/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
498     ${LLVM_DIR}/lib/Transforms/InstCombine/InstructionCombining.cpp
499     ${LLVM_DIR}/lib/Transforms/Scalar/ADCE.cpp
500     ${LLVM_DIR}/lib/Transforms/Scalar/CodeGenPrepare.cpp
501     ${LLVM_DIR}/lib/Transforms/Scalar/DeadStoreElimination.cpp
502     ${LLVM_DIR}/lib/Transforms/Scalar/GVN.cpp
503     ${LLVM_DIR}/lib/Transforms/Scalar/LICM.cpp
504     ${LLVM_DIR}/lib/Transforms/Scalar/LoopStrengthReduce.cpp
505     ${LLVM_DIR}/lib/Transforms/Scalar/Reassociate.cpp
506     ${LLVM_DIR}/lib/Transforms/Scalar/Reg2Mem.cpp
507     ${LLVM_DIR}/lib/Transforms/Scalar/SCCP.cpp
508     ${LLVM_DIR}/lib/Transforms/Scalar/ScalarReplAggregates.cpp
509     ${LLVM_DIR}/lib/Transforms/Scalar/SimplifyCFGPass.cpp
510     ${LLVM_DIR}/lib/Transforms/Utils/AddrModeMatcher.cpp
511     ${LLVM_DIR}/lib/Transforms/Utils/BasicBlockUtils.cpp
512     ${LLVM_DIR}/lib/Transforms/Utils/BreakCriticalEdges.cpp
513     ${LLVM_DIR}/lib/Transforms/Utils/BuildLibCalls.cpp
514     ${LLVM_DIR}/lib/Transforms/Utils/DemoteRegToStack.cpp
515     ${LLVM_DIR}/lib/Transforms/Utils/InstructionNamer.cpp
516     ${LLVM_DIR}/lib/Transforms/Utils/LCSSA.cpp
517     ${LLVM_DIR}/lib/Transforms/Utils/Local.cpp
518     ${LLVM_DIR}/lib/Transforms/Utils/LoopSimplify.cpp
519     ${LLVM_DIR}/lib/Transforms/Utils/LowerInvoke.cpp
520     ${LLVM_DIR}/lib/Transforms/Utils/LowerSwitch.cpp
521     ${LLVM_DIR}/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
522     ${LLVM_DIR}/lib/Transforms/Utils/SSAUpdater.cpp
523     ${LLVM_DIR}/lib/Transforms/Utils/SimplifyCFG.cpp
524     ${LLVM_DIR}/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
525     ${LLVM_DIR}/lib/VMCore/AsmWriter.cpp
526     ${LLVM_DIR}/lib/VMCore/Attributes.cpp
527     ${LLVM_DIR}/lib/VMCore/BasicBlock.cpp
528     ${LLVM_DIR}/lib/VMCore/ConstantFold.cpp
529     ${LLVM_DIR}/lib/VMCore/Constants.cpp
530     ${LLVM_DIR}/lib/VMCore/DebugInfoProbe.cpp
531     ${LLVM_DIR}/lib/VMCore/DebugLoc.cpp
532     ${LLVM_DIR}/lib/VMCore/Dominators.cpp
533     ${LLVM_DIR}/lib/VMCore/Function.cpp
534     ${LLVM_DIR}/lib/VMCore/Globals.cpp
535     ${LLVM_DIR}/lib/VMCore/IRBuilder.cpp
536     ${LLVM_DIR}/lib/VMCore/InlineAsm.cpp
537     ${LLVM_DIR}/lib/VMCore/Instruction.cpp
538     ${LLVM_DIR}/lib/VMCore/Instructions.cpp
539     ${LLVM_DIR}/lib/VMCore/IntrinsicInst.cpp
540     ${LLVM_DIR}/lib/VMCore/LLVMContext.cpp
541     ${LLVM_DIR}/lib/VMCore/LLVMContextImpl.cpp
542     ${LLVM_DIR}/lib/VMCore/LeakDetector.cpp
543     ${LLVM_DIR}/lib/VMCore/Metadata.cpp
544     ${LLVM_DIR}/lib/VMCore/Module.cpp
545     ${LLVM_DIR}/lib/VMCore/Pass.cpp
546     ${LLVM_DIR}/lib/VMCore/PassManager.cpp
547     ${LLVM_DIR}/lib/VMCore/PassRegistry.cpp
548     ${LLVM_DIR}/lib/VMCore/PrintModulePass.cpp
549     ${LLVM_DIR}/lib/VMCore/Type.cpp
550     ${LLVM_DIR}/lib/VMCore/Use.cpp
551     ${LLVM_DIR}/lib/VMCore/User.cpp
552     ${LLVM_DIR}/lib/VMCore/Value.cpp
553     ${LLVM_DIR}/lib/VMCore/ValueSymbolTable.cpp
554     ${LLVM_DIR}/lib/VMCore/ValueTypes.cpp
555     ${LLVM_DIR}/lib/VMCore/Verifier.cpp
556 )
557
558 if(WIN32)
559     set(LLVM_INCLUDE_DIR ${LLVM_DIR}/include)
560 elseif(LINUX)
561     set(LLVM_INCLUDE_DIR ${LLVM_DIR}/include-linux)
562 elseif(APPLE)
563     set(LLVM_INCLUDE_DIR ${LLVM_DIR}/include-osx)
564 endif()
565
566 list(APPEND LLVM_INCLUDE_DIR
567     ${LLVM_DIR}/include
568     ${LLVM_DIR}/lib/Target/X86
569 )
570 add_library(llvm STATIC ${LLVM_LIST})
571 set_target_properties(llvm PROPERTIES
572     POSITION_INDEPENDENT_CODE 1
573     INCLUDE_DIRECTORIES "${LLVM_INCLUDE_DIR}"
574     COMPILE_DEFINITIONS "__STDC_CONSTANT_MACROS; __STDC_LIMIT_MACROS;"
575     FOLDER "LLVM"
576 )
577
578 ###########################################################
579 # Subzero
580 ###########################################################
581
582 if(${REACTOR_BACKEND} STREQUAL "Subzero")
583     set(SUBZERO_LIST
584         ${SUBZERO_DIR}/src/IceAssembler.cpp
585         ${SUBZERO_DIR}/src/IceCfg.cpp
586         ${SUBZERO_DIR}/src/IceCfgNode.cpp
587         ${SUBZERO_DIR}/src/IceClFlags.cpp
588         ${SUBZERO_DIR}/src/IceELFObjectWriter.cpp
589         ${SUBZERO_DIR}/src/IceELFSection.cpp
590         ${SUBZERO_DIR}/src/IceFixups.cpp
591         ${SUBZERO_DIR}/src/IceGlobalContext.cpp
592         ${SUBZERO_DIR}/src/IceGlobalInits.cpp
593         ${SUBZERO_DIR}/src/IceInst.cpp
594         ${SUBZERO_DIR}/src/IceInstrumentation.cpp
595         ${SUBZERO_DIR}/src/IceIntrinsics.cpp
596         ${SUBZERO_DIR}/src/IceLiveness.cpp
597         ${SUBZERO_DIR}/src/IceLoopAnalyzer.cpp
598         ${SUBZERO_DIR}/src/IceMangling.cpp
599         ${SUBZERO_DIR}/src/IceMemory.cpp
600         ${SUBZERO_DIR}/src/IceOperand.cpp
601         ${SUBZERO_DIR}/src/IceRangeSpec.cpp
602         ${SUBZERO_DIR}/src/IceRegAlloc.cpp
603         ${SUBZERO_DIR}/src/IceRevision.cpp
604         ${SUBZERO_DIR}/src/IceRNG.cpp
605         ${SUBZERO_DIR}/src/IceSwitchLowering.cpp
606         ${SUBZERO_DIR}/src/IceTargetLowering.cpp
607         ${SUBZERO_DIR}/src/IceThreading.cpp
608         ${SUBZERO_DIR}/src/IceTimerTree.cpp
609         ${SUBZERO_DIR}/src/IceTypes.cpp
610         ${SUBZERO_DIR}/src/IceVariableSplitting.cpp
611     )
612
613     if(ARCH STREQUAL "x86_64")
614         list(APPEND SUBZERO_LIST
615             ${SUBZERO_DIR}/src/IceTargetLoweringX86.cpp
616             ${SUBZERO_DIR}/src/IceInstX8664.cpp
617             ${SUBZERO_DIR}/src/IceTargetLoweringX8664.cpp
618         )
619         set(SUBZERO_TARGET X8664)
620     elseif(ARCH STREQUAL "x86")
621         list(APPEND SUBZERO_LIST
622             ${SUBZERO_DIR}/src/IceTargetLoweringX86.cpp
623             ${SUBZERO_DIR}/src/IceInstX8632.cpp
624             ${SUBZERO_DIR}/src/IceTargetLoweringX8632.cpp
625         )
626         set(SUBZERO_TARGET X8632)
627     elseif(ARCH STREQUAL "arm")
628         list(APPEND SUBZERO_LIST
629             ${SUBZERO_DIR}/src/IceAssemblerARM32.cpp
630             ${SUBZERO_DIR}/src/IceInstARM32.cpp
631             ${SUBZERO_DIR}/src/IceTargetLoweringARM32.cpp
632         )
633         set(SUBZERO_TARGET ARM32)
634     else()
635         message(FATAL_ERROR "Architecture '${ARCH}' not supported by Subzero")
636     endif()
637
638     file(GLOB_RECURSE SUBZERO_DEPENDENCIES_LIST
639         ${SUBZERO_LLVM_DIR}/*.cpp
640         ${SUBZERO_LLVM_DIR}/*.c
641         ${SUBZERO_LLVM_DIR}/*.h
642     )
643
644     set(SUBZERO_REACTOR_LIST
645         ${SOURCE_DIR}/Reactor/SubzeroReactor.cpp
646         ${SOURCE_DIR}/Reactor/Routine.cpp
647         ${SOURCE_DIR}/Reactor/Optimizer.cpp
648         ${SOURCE_DIR}/Reactor/Nucleus.hpp
649         ${SOURCE_DIR}/Reactor/Routine.hpp
650     )
651
652     set(SUBZERO_INCLUDE_DIR
653         ${SUBZERO_DIR}/
654         ${SUBZERO_LLVM_DIR}/include/
655         ${SUBZERO_DIR}/pnacl-llvm/include/
656      )
657
658     if(WIN32)
659         list(APPEND SUBZERO_INCLUDE_DIR ${SUBZERO_LLVM_DIR}/build/Windows/include/)
660     elseif(LINUX)
661         list(APPEND SUBZERO_INCLUDE_DIR ${SUBZERO_LLVM_DIR}/build/Linux/include/)
662     elseif(APPLE)
663         list(APPEND SUBZERO_INCLUDE_DIR ${SUBZERO_LLVM_DIR}/build/MacOS/include/)
664     endif()
665
666     add_library(ReactorSubzero STATIC
667         ${SUBZERO_LIST}
668         ${SUBZERO_DEPENDENCIES_LIST}
669         ${SUBZERO_REACTOR_LIST}
670     )
671
672     set_target_properties(ReactorSubzero PROPERTIES
673         POSITION_INDEPENDENT_CODE 1
674         INCLUDE_DIRECTORIES "${SUBZERO_INCLUDE_DIR}"
675         COMPILE_DEFINITIONS "SZTARGET=${SUBZERO_TARGET}; ALLOW_DUMP=0; ALLOW_TIMERS=0; ALLOW_LLVM_CL=0; ALLOW_LLVM_IR=0; ALLOW_LLVM_IR_AS_INPUT=0; ALLOW_MINIMAL_BUILD=0; ALLOW_WASM=0; ICE_THREAD_LOCAL_HACK=0;"
676         FOLDER "Subzero"
677     )
678
679     if(WIN32)
680         target_compile_definitions(ReactorSubzero PRIVATE SUBZERO_USE_MICROSOFT_ABI)
681     endif()
682 endif()
683
684 ###########################################################
685 # Include Directories
686 ###########################################################
687
688 set(COMMON_INCLUDE_DIR
689     ${SOURCE_DIR}
690     ${SOURCE_DIR}/Common
691     ${SOURCE_DIR}/Main
692     ${SOURCE_DIR}/Reactor
693     ${SOURCE_DIR}/Renderer
694     ${SOURCE_DIR}/Shader
695     ${CMAKE_SOURCE_DIR}/include
696     ${LLVM_INCLUDE_DIR}
697 )
698 set(OPENGL_INCLUDE_DIR
699     ${OPENGL_DIR}
700     ${COMMON_INCLUDE_DIR}
701 )
702
703 ###########################################################
704 # File Lists
705 ###########################################################
706
707 file(GLOB_RECURSE SWIFTSHADER_LIST
708     ${SOURCE_DIR}/Common/*.cpp
709     ${SOURCE_DIR}/Common/*.h
710     ${SOURCE_DIR}/Common/*.hpp
711     ${SOURCE_DIR}/Renderer/*.cpp
712     ${SOURCE_DIR}/Renderer/*.h
713     ${SOURCE_DIR}/Renderer/*.hpp
714     ${SOURCE_DIR}/Shader/*.cpp
715     ${SOURCE_DIR}/Shader/*.h
716     ${SOURCE_DIR}/Shader/*.hpp
717 )
718 list(APPEND SWIFTSHADER_LIST
719     ${SOURCE_DIR}/Main/Config.cpp
720     ${SOURCE_DIR}/Main/Config.hpp
721     ${SOURCE_DIR}/Main/FrameBuffer.cpp
722     ${SOURCE_DIR}/Main/FrameBuffer.hpp
723     ${SOURCE_DIR}/Main/SwiftConfig.cpp
724     ${SOURCE_DIR}/Main/SwiftConfig.hpp
725 )
726 list(REMOVE_ITEM SWIFTSHADER_LIST
727     ${SOURCE_DIR}/Common/DebugAndroid.cpp
728     ${SOURCE_DIR}/Common/DebugAndroid.hpp
729     ${SOURCE_DIR}/Common/GrallocAndroid.cpp
730     ${SOURCE_DIR}/Common/GrallocAndroid.hpp
731 )
732
733 set(REACTOR_LLVM_LIST
734     ${SOURCE_DIR}/Reactor/LLVMReactor.cpp
735     ${SOURCE_DIR}/Reactor/Nucleus.hpp
736     ${SOURCE_DIR}/Reactor/Routine.cpp
737     ${SOURCE_DIR}/Reactor/Routine.hpp
738     ${SOURCE_DIR}/Reactor/LLVMRoutine.cpp
739     ${SOURCE_DIR}/Reactor/LLVMRoutine.hpp
740     ${SOURCE_DIR}/Reactor/LLVMRoutineManager.cpp
741     ${SOURCE_DIR}/Reactor/LLVMRoutineManager.hpp
742 )
743
744 file(GLOB_RECURSE EGL_LIST
745     ${OPENGL_DIR}/libEGL/*.cpp
746     ${OPENGL_DIR}/libEGL/*.h
747     ${OPENGL_DIR}/libEGL/*.hpp
748     ${OPENGL_DIR}/common/Object.cpp
749     ${OPENGL_DIR}/common/Object.hpp
750     ${OPENGL_DIR}/common/debug.cpp
751     ${OPENGL_DIR}/common/debug.h
752     ${CMAKE_SOURCE_DIR}/include/*.h
753 )
754
755 file(GLOB_RECURSE GL32_LIST
756     ${OPENGL_DIR}/libGL/*.cpp
757     ${OPENGL_DIR}/libGL/*.h
758     ${OPENGL_DIR}/libGL/*.hpp
759     ${OPENGL_DIR}/common/*.cpp
760     ${OPENGL_DIR}/common/*.h
761     ${OPENGL_DIR}/common/*.hpp
762     ${CMAKE_SOURCE_DIR}/include/GL/*.h
763 )
764
765 file(GLOB_RECURSE GLES2_LIST
766     ${OPENGL_DIR}/libGLESv2/*.cpp
767     ${OPENGL_DIR}/libGLESv2/*.h
768     ${OPENGL_DIR}/libGLESv2/*.hpp
769     ${OPENGL_DIR}/common/*.cpp
770     ${OPENGL_DIR}/common/*.h
771     ${OPENGL_DIR}/common/*.hpp
772     ${CMAKE_SOURCE_DIR}/include/KHR/*.h
773     ${CMAKE_SOURCE_DIR}/include/GLES2/*.h
774     ${CMAKE_SOURCE_DIR}/include/GLES3/*.h
775 )
776
777 file(GLOB_RECURSE GLES_CM_LIST
778     ${OPENGL_DIR}/libGLES_CM/*.cpp
779     ${OPENGL_DIR}/libGLES_CM/*.h
780     ${OPENGL_DIR}/libGLES_CM/*.hpp
781     ${OPENGL_DIR}/common/*.cpp
782     ${OPENGL_DIR}/common/*.h
783     ${OPENGL_DIR}/common/*.hpp
784     ${CMAKE_SOURCE_DIR}/include/KHR/*.h
785     ${CMAKE_SOURCE_DIR}/include/GLES/*.h
786 )
787
788 file(GLOB_RECURSE OPENGL_COMPILER_LIST
789     ${OPENGL_COMPILER_DIR}/*.cpp
790     ${OPENGL_COMPILER_DIR}/*.h
791     ${OPENGL_COMPILER_DIR}/*.hpp
792 )
793 file(GLOB_RECURSE OPENGL_COMPILER_OS_SPECIFIC_LIST
794     ${OPENGL_COMPILER_DIR}/ossource*.cpp
795     ${OPENGL_COMPILER_DIR}/ossource*.h
796     ${OPENGL_COMPILER_DIR}/ossource*.hpp
797 )
798 list(REMOVE_ITEM OPENGL_COMPILER_LIST ${OPENGL_COMPILER_OS_SPECIFIC_LIST})
799
800 ###########################################################
801 # Append OS specific files to lists
802 ###########################################################
803
804 if(WIN32)
805     list(APPEND SWIFTSHADER_LIST
806         ${SOURCE_DIR}/Main/FrameBufferDD.cpp
807         ${SOURCE_DIR}/Main/FrameBufferDD.hpp
808         ${SOURCE_DIR}/Main/FrameBufferGDI.cpp
809         ${SOURCE_DIR}/Main/FrameBufferGDI.hpp
810         ${SOURCE_DIR}/Main/FrameBufferWin.cpp
811         ${SOURCE_DIR}/Main/FrameBufferWin.hpp
812     )
813     list(APPEND OPENGL_COMPILER_LIST ${OPENGL_COMPILER_DIR}/ossource_win.cpp)
814     list(APPEND EGL_LIST ${OPENGL_DIR}/libEGL/libEGL.rc)
815     list(APPEND GL32_LIST ${OPENGL_DIR}/libGL/libGL.rc)
816     list(APPEND GLES2_LIST ${OPENGL_DIR}/libGLESv2/libGLESv2.rc)
817     list(APPEND GLES_CM_LIST ${OPENGL_DIR}/libGLES_CM/libGLES_CM.rc)
818 elseif(LINUX)
819     list(APPEND SWIFTSHADER_LIST
820         ${SOURCE_DIR}/Main/FrameBufferX11.cpp
821         ${SOURCE_DIR}/Main/FrameBufferX11.hpp
822         ${SOURCE_DIR}/Common/SharedLibrary.hpp
823         ${SOURCE_DIR}/Main/libX11.cpp
824         ${SOURCE_DIR}/Main/libX11.hpp
825     )
826     list(APPEND EGL_LIST
827         ${SOURCE_DIR}/Common/SharedLibrary.hpp
828         ${SOURCE_DIR}/Main/libX11.cpp
829         ${SOURCE_DIR}/Main/libX11.hpp
830     )
831     list(APPEND OPENGL_COMPILER_LIST
832         ${OPENGL_COMPILER_DIR}/ossource_posix.cpp
833     )
834 elseif(APPLE)
835     list(APPEND SWIFTSHADER_LIST
836         ${SOURCE_DIR}/Main/FrameBufferOSX.mm
837         ${SOURCE_DIR}/Main/FrameBufferOSX.hpp
838     )
839     list(APPEND EGL_LIST
840         ${OPENGL_DIR}/libEGL/OSXUtils.mm
841         ${OPENGL_DIR}/libEGL/OSXUtils.hpp
842     )
843     list(APPEND OPENGL_COMPILER_LIST
844         ${OPENGL_COMPILER_DIR}/ossource_posix.cpp
845     )
846 endif()
847
848 if(WIN32)
849     set(OS_LIBS odbc32 odbccp32 WS2_32 dxguid)
850 elseif(LINUX)
851     set(OS_LIBS dl pthread)
852 elseif(APPLE)
853     find_library(COCOA_FRAMEWORK Cocoa)
854     find_library(QUARTZ_FRAMEWORK Quartz)
855     set(OS_LIBS "${COCOA_FRAMEWORK}" "${QUARTZ_FRAMEWORK}")
856 endif()
857
858 ###########################################################
859 # SwiftShader Targets
860 ###########################################################
861
862 add_library(SwiftShader STATIC ${SWIFTSHADER_LIST})
863 set_target_properties(SwiftShader PROPERTIES
864     INCLUDE_DIRECTORIES "${COMMON_INCLUDE_DIR}"
865     POSITION_INDEPENDENT_CODE 1
866     FOLDER "Core"
867     COMPILE_DEFINITIONS "NO_SANITIZE_FUNCTION=;"
868 )
869 target_link_libraries(SwiftShader ${OS_LIBS})
870
871 add_library(ReactorLLVM STATIC ${REACTOR_LLVM_LIST})
872 set_target_properties(ReactorLLVM PROPERTIES
873     INCLUDE_DIRECTORIES "${COMMON_INCLUDE_DIR}"
874     POSITION_INDEPENDENT_CODE 1
875     FOLDER "Core"
876 )
877 target_link_libraries(ReactorLLVM llvm ${OS_LIBS})
878
879 if(${REACTOR_BACKEND} STREQUAL "LLVM")
880     set(Reactor ReactorLLVM)
881 elseif(${REACTOR_BACKEND} STREQUAL "Subzero")
882     set(Reactor ReactorSubzero)
883 else()
884     message(FATAL_ERROR "REACTOR_BACKEND must be 'LLVM' or 'Subzero'")
885 endif()
886
887 add_library(GLCompiler STATIC ${OPENGL_COMPILER_LIST})
888 set_target_properties(GLCompiler PROPERTIES
889     INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}"
890     POSITION_INDEPENDENT_CODE 1
891     FOLDER "OpenGL"
892 )
893 target_link_libraries(GLCompiler ${OS_LIBS})
894
895 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
896     set(LIB_PREFIX "lib64")
897 else()
898     set(LIB_PREFIX "lib")
899 endif()
900
901 if(BUILD_EGL)
902     add_library(libEGL SHARED ${EGL_LIST})
903     set_target_properties(libEGL PROPERTIES
904         INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}"
905         FOLDER "OpenGL"
906         COMPILE_DEFINITIONS "EGL_EGLEXT_PROTOTYPES; EGLAPI=; NO_SANITIZE_FUNCTION=;"
907         PREFIX ""
908     )
909     set_target_export_map(libEGL ${SOURCE_DIR}/OpenGL/libEGL)
910     target_link_libraries(libEGL ${OS_LIBS})
911     add_custom_command(
912         TARGET libEGL
913         POST_BUILD
914         COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:libEGL>/translator
915         COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:libEGL> $<TARGET_FILE_DIR:libEGL>/translator/${LIB_PREFIX}EGL_translator${CMAKE_SHARED_LIBRARY_SUFFIX}
916     )
917 endif()
918
919 if(BUILD_GL32)
920     add_library(libGL SHARED ${GL32_LIST})
921     set_target_properties(libGL PROPERTIES
922         INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}"
923         FOLDER "OpenGL"
924         COMPILE_DEFINITIONS "GL_GLEXT_PROTOTYPES"
925         PREFIX ""
926     )
927     set_target_export_map(libGL ${SOURCE_DIR}/OpenGL/libGL)
928     target_link_libraries(libGL SwiftShader ${Reactor} GLCompiler ${OS_LIBS})
929 endif()
930
931 if(BUILD_GLESv2)
932     add_library(libGLESv2 SHARED ${GLES2_LIST})
933     set_target_properties(libGLESv2 PROPERTIES
934         INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}"
935         FOLDER "OpenGL"
936         COMPILE_DEFINITIONS "GL_GLEXT_PROTOTYPES; GL_API=; GL_APICALL=; NO_SANITIZE_FUNCTION=;"
937         PREFIX ""
938     )
939     set_target_export_map(libGLESv2 ${SOURCE_DIR}/OpenGL/libGLESv2)
940     target_link_libraries(libGLESv2 SwiftShader ${Reactor} GLCompiler ${OS_LIBS})
941     add_custom_command(
942         TARGET libGLESv2
943         POST_BUILD
944         COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:libGLESv2>/translator
945         COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:libGLESv2> $<TARGET_FILE_DIR:libGLESv2>/translator/${LIB_PREFIX}GLES_V2_translator${CMAKE_SHARED_LIBRARY_SUFFIX}
946     )
947 endif()
948
949 if(BUILD_GLES_CM)
950     add_library(libGLES_CM SHARED ${GLES_CM_LIST})
951     set_target_properties(libGLES_CM PROPERTIES
952         INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}"
953         FOLDER "OpenGL"
954         COMPILE_DEFINITIONS "GL_GLEXT_PROTOTYPES; EGLAPI=; GL_API=; GL_APICALL=;"
955         PREFIX ""
956     )
957     set_target_export_map(libGLES_CM ${SOURCE_DIR}/OpenGL/libGLES_CM)
958     target_link_libraries(libGLES_CM SwiftShader ${Reactor} GLCompiler ${OS_LIBS})
959     add_custom_command(
960         TARGET libGLES_CM
961         POST_BUILD
962         COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:libGLES_CM>/translator
963         COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:libGLES_CM> $<TARGET_FILE_DIR:libGLES_CM>/translator/${LIB_PREFIX}GLES_CM_translator${CMAKE_SHARED_LIBRARY_SUFFIX}
964     )
965 endif()
966
967 ###########################################################
968 # Sample programs
969 ###########################################################
970
971 if(BUILD_SAMPLES)
972     if(WIN32)
973         add_executable(OGLES2HelloAPI ${HELLO2_DIR}/OGLES2HelloAPI_Windows.cpp)
974         set_target_properties(OGLES2HelloAPI PROPERTIES
975             INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/include"
976             COMPILE_DEFINITIONS "GL_GLEXT_PROTOTYPES"
977             FOLDER "Samples"
978         )
979         target_link_libraries(OGLES2HelloAPI libEGL libGLESv2)
980         set_property(TARGET OGLES2HelloAPI APPEND_STRING PROPERTY LINK_FLAGS "/SUBSYSTEM:WINDOWS")
981         set(CMAKE_DEFAULT_STARTUP_PROJECT OGLES2HelloAPI)
982     elseif(LINUX)
983         add_executable(OGLES2HelloAPI ${HELLO2_DIR}/OGLES2HelloAPI_LinuxX11.cpp)
984         set_target_properties(OGLES2HelloAPI PROPERTIES
985             INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/include"
986             COMPILE_DEFINITIONS "GL_GLEXT_PROTOTYPES"
987         )
988         target_link_libraries(OGLES2HelloAPI dl X11 libEGL libGLESv2)   # Explicitly link our "lib*" targets, not the platform provided "EGL" and "GLESv2"
989     elseif(APPLE)
990         add_executable(OGLES2HelloAPI MACOSX_BUNDLE
991             ${HELLO2_DIR}/OGLES2HelloAPI_OSX.mm
992             ${HELLO2_DIR}/Build/OSX/en.lproj/MainMenu.xib
993         )
994         set_target_properties(OGLES2HelloAPI PROPERTIES
995             INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/include"
996             COMPILE_DEFINITIONS "GL_GLEXT_PROTOTYPES"
997             MACOSX_BUNDLE_INFO_PLIST "${HELLO2_DIR}/Build/OSX/Info.plist"
998         )
999         target_link_libraries(OGLES2HelloAPI libEGL libGLESv2 ${OS_LIBS})
1000         set_source_files_properties(${HELLO2_DIR}/Build/OSX/en.lproj/MainMenu.xib PROPERTIES
1001             MACOSX_PACKAGE_LOCATION "Resources"
1002         )
1003     endif()
1004 endif()
1005
1006 if(BUILD_TESTS AND ${REACTOR_BACKEND} STREQUAL "Subzero")
1007     set(SUBZERO_TEST_LIST
1008         ${SOURCE_DIR}/Reactor/Main.cpp
1009         ${CMAKE_SOURCE_DIR}/third_party/googletest/googletest/src/gtest-all.cc
1010     )
1011
1012     set(SUBZERO_TEST_INCLUDE_DIR
1013         ${CMAKE_SOURCE_DIR}/third_party/googletest/googletest/include
1014         ${CMAKE_SOURCE_DIR}/third_party/googletest/googletest/
1015     )
1016
1017     add_executable(SubzeroTest ${SUBZERO_TEST_LIST})
1018     set_target_properties(SubzeroTest PROPERTIES
1019         INCLUDE_DIRECTORIES "${SUBZERO_TEST_INCLUDE_DIR}"
1020         FOLDER "Tests"
1021     )
1022     if(WIN32)
1023         target_link_libraries(SubzeroTest ReactorSubzero)
1024     else()
1025         target_link_libraries(SubzeroTest ReactorSubzero pthread dl)
1026     endif()
1027 endif()