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