16b1a3ef2SMatthias Brauncmake_minimum_required(VERSION 2.8.12)
26b1a3ef2SMatthias Braunif(POLICY CMP0042)
36b1a3ef2SMatthias Braun	cmake_policy(SET CMP0042 NEW)
46b1a3ef2SMatthias Braunendif()
56b1a3ef2SMatthias Braunif(POLICY CMP0063)
66b1a3ef2SMatthias Braun	cmake_policy(SET CMP0063 OLD)
76b1a3ef2SMatthias Braunendif()
86b1a3ef2SMatthias Braun
96b1a3ef2SMatthias Braunproject(libfirm C)
10a37a0e59SMatthias Braunset(libfirm_VERSION "1.22.1")
112bf4d37aSMatthias Braunset(PROJECT_DESCRIPTION "library implementing the intermediate representation Firm")
122bf4d37aSMatthias Braun
132bf4d37aSMatthias Braunset(CMAKE_C_VISIBILITY_PRESET hidden)
142bf4d37aSMatthias Braun
152bf4d37aSMatthias Braunset(SOURCES
162bf4d37aSMatthias Braun	ir/adt/array.c
172bf4d37aSMatthias Braun	ir/adt/bipartite.c
182bf4d37aSMatthias Braun	ir/adt/bitset.c
192bf4d37aSMatthias Braun	ir/adt/cpset.c
20466fabd0SSebastian Buchwald	ir/adt/deq.c
212bf4d37aSMatthias Braun	ir/adt/gaussjordan.c
222bf4d37aSMatthias Braun	ir/adt/gaussseidel.c
232bf4d37aSMatthias Braun	ir/adt/hungarian.c
242bf4d37aSMatthias Braun	ir/adt/pmap.c
252bf4d37aSMatthias Braun	ir/adt/pqueue.c
262bf4d37aSMatthias Braun	ir/adt/pset.c
272bf4d37aSMatthias Braun	ir/adt/pset_new.c
282bf4d37aSMatthias Braun	ir/adt/set.c
292bf4d37aSMatthias Braun	ir/adt/xmalloc.c
302bf4d37aSMatthias Braun	ir/ana/analyze_irg_args.c
312bf4d37aSMatthias Braun	ir/ana/callgraph.c
322bf4d37aSMatthias Braun	ir/ana/cdep.c
332bf4d37aSMatthias Braun	ir/ana/cgana.c
342bf4d37aSMatthias Braun	ir/ana/constbits.c
352bf4d37aSMatthias Braun	ir/ana/dca.c
362bf4d37aSMatthias Braun	ir/ana/dfs.c
372bf4d37aSMatthias Braun	ir/ana/domfront.c
382bf4d37aSMatthias Braun	ir/ana/execfreq.c
392bf4d37aSMatthias Braun	ir/ana/heights.c
402bf4d37aSMatthias Braun	ir/ana/irbackedge.c
412bf4d37aSMatthias Braun	ir/ana/ircfscc.c
422bf4d37aSMatthias Braun	ir/ana/irconsconfirm.c
432bf4d37aSMatthias Braun	ir/ana/irdom.c
442bf4d37aSMatthias Braun	ir/ana/irlivechk.c
452bf4d37aSMatthias Braun	ir/ana/irloop.c
462bf4d37aSMatthias Braun	ir/ana/irmemory.c
472bf4d37aSMatthias Braun	ir/ana/irouts.c
482bf4d37aSMatthias Braun	ir/ana/vrp.c
492c39abe4SMoritz Baumann	ir/be/be2addr.c
502bf4d37aSMatthias Braun	ir/be/bearch.c
512bf4d37aSMatthias Braun	ir/be/beasm.c
522bf4d37aSMatthias Braun	ir/be/beblocksched.c
532bf4d37aSMatthias Braun	ir/be/bechordal.c
542bf4d37aSMatthias Braun	ir/be/bechordal_common.c
552bf4d37aSMatthias Braun	ir/be/bechordal_main.c
562bf4d37aSMatthias Braun	ir/be/becopyheur4.c
572bf4d37aSMatthias Braun	ir/be/becopyilp.c
582bf4d37aSMatthias Braun	ir/be/becopyilp2.c
592bf4d37aSMatthias Braun	ir/be/becopyopt.c
602bf4d37aSMatthias Braun	ir/be/bediagnostic.c
612bf4d37aSMatthias Braun	ir/be/bedump.c
622bf4d37aSMatthias Braun	ir/be/bedwarf.c
632c39abe4SMoritz Baumann	ir/be/beemithlp.c
642bf4d37aSMatthias Braun	ir/be/beemitter.c
652bf4d37aSMatthias Braun	ir/be/beflags.c
662bf4d37aSMatthias Braun	ir/be/begnuas.c
672bf4d37aSMatthias Braun	ir/be/beifg.c
682bf4d37aSMatthias Braun	ir/be/beinfo.c
692bf4d37aSMatthias Braun	ir/be/beinsn.c
702bf4d37aSMatthias Braun	ir/be/beirg.c
7162592dcbSMatthias Braun	ir/be/bejit.c
722bf4d37aSMatthias Braun	ir/be/belistsched.c
732bf4d37aSMatthias Braun	ir/be/belive.c
742bf4d37aSMatthias Braun	ir/be/beloopana.c
752bf4d37aSMatthias Braun	ir/be/belower.c
762bf4d37aSMatthias Braun	ir/be/bemain.c
772bf4d37aSMatthias Braun	ir/be/bemodule.c
782bf4d37aSMatthias Braun	ir/be/benode.c
792bf4d37aSMatthias Braun	ir/be/bepbqpcoloring.c
802bf4d37aSMatthias Braun	ir/be/bepeephole.c
812bf4d37aSMatthias Braun	ir/be/beprefalloc.c
822bf4d37aSMatthias Braun	ir/be/bera.c
832bf4d37aSMatthias Braun	ir/be/besched.c
842bf4d37aSMatthias Braun	ir/be/beschednormal.c
852bf4d37aSMatthias Braun	ir/be/beschedrand.c
862bf4d37aSMatthias Braun	ir/be/beschedtrivial.c
872bf4d37aSMatthias Braun	ir/be/bespill.c
882bf4d37aSMatthias Braun	ir/be/bespillbelady.c
892bf4d37aSMatthias Braun	ir/be/bespilldaemel.c
902bf4d37aSMatthias Braun	ir/be/bespillslots.c
912bf4d37aSMatthias Braun	ir/be/bespillutil.c
922bf4d37aSMatthias Braun	ir/be/bessaconstr.c
932bf4d37aSMatthias Braun	ir/be/bessadestr.c
942bf4d37aSMatthias Braun	ir/be/bestack.c
952bf4d37aSMatthias Braun	ir/be/bestat.c
962bf4d37aSMatthias Braun	ir/be/bestate.c
972bf4d37aSMatthias Braun	ir/be/betranshlp.c
982bf4d37aSMatthias Braun	ir/be/beuses.c
992bf4d37aSMatthias Braun	ir/be/beutil.c
100a020b3f3SMatthias Braun	ir/be/bevarargs.c
1012bf4d37aSMatthias Braun	ir/be/beverify.c
1022bf4d37aSMatthias Braun	ir/common/debug.c
1032bf4d37aSMatthias Braun	ir/common/debugger.c
1042bf4d37aSMatthias Braun	ir/common/firm.c
1052bf4d37aSMatthias Braun	ir/common/firm_common.c
1062bf4d37aSMatthias Braun	ir/common/panic.c
1072bf4d37aSMatthias Braun	ir/common/timing.c
1082bf4d37aSMatthias Braun	ir/ident/ident.c
1092bf4d37aSMatthias Braun	ir/ir/dbginfo.c
1102bf4d37aSMatthias Braun	ir/ir/irarch.c
1112bf4d37aSMatthias Braun	ir/ir/irargs.c
1122bf4d37aSMatthias Braun	ir/ir/ircons.c
1132bf4d37aSMatthias Braun	ir/ir/irdump.c
1142bf4d37aSMatthias Braun	ir/ir/irdumptxt.c
1152bf4d37aSMatthias Braun	ir/ir/iredges.c
1162bf4d37aSMatthias Braun	ir/ir/irflag.c
1172bf4d37aSMatthias Braun	ir/ir/irgmod.c
1182bf4d37aSMatthias Braun	ir/ir/irgraph.c
1192bf4d37aSMatthias Braun	ir/ir/irgwalk.c
1202bf4d37aSMatthias Braun	ir/ir/irgwalk_blk.c
1212bf4d37aSMatthias Braun	ir/ir/irhooks.c
1222bf4d37aSMatthias Braun	ir/ir/irio.c
1232bf4d37aSMatthias Braun	ir/ir/irmode.c
1242bf4d37aSMatthias Braun	ir/ir/irnode.c
1252bf4d37aSMatthias Braun	ir/ir/irnodehashmap.c
1262bf4d37aSMatthias Braun	ir/ir/irnodeset.c
1272bf4d37aSMatthias Braun	ir/ir/irop.c
1282bf4d37aSMatthias Braun	ir/ir/irprintf.c
1292bf4d37aSMatthias Braun	ir/ir/irprofile.c
1302bf4d37aSMatthias Braun	ir/ir/irprog.c
1312bf4d37aSMatthias Braun	ir/ir/irssacons.c
132a020b3f3SMatthias Braun	ir/ir/irtools.c
1332bf4d37aSMatthias Braun	ir/ir/irverify.c
1342bf4d37aSMatthias Braun	ir/ir/valueset.c
1352bf4d37aSMatthias Braun	ir/kaps/brute_force.c
1362bf4d37aSMatthias Braun	ir/kaps/bucket.c
1372bf4d37aSMatthias Braun	ir/kaps/heuristical.c
1382bf4d37aSMatthias Braun	ir/kaps/heuristical_co.c
1392bf4d37aSMatthias Braun	ir/kaps/heuristical_co_ld.c
1402bf4d37aSMatthias Braun	ir/kaps/html_dumper.c
1412bf4d37aSMatthias Braun	ir/kaps/kaps.c
1422bf4d37aSMatthias Braun	ir/kaps/matrix.c
1432bf4d37aSMatthias Braun	ir/kaps/optimal.c
1442bf4d37aSMatthias Braun	ir/kaps/pbqp_edge.c
1452bf4d37aSMatthias Braun	ir/kaps/pbqp_node.c
1462bf4d37aSMatthias Braun	ir/kaps/vector.c
1472bf4d37aSMatthias Braun	ir/libcore/lc_appendable.c
1482bf4d37aSMatthias Braun	ir/libcore/lc_opts.c
1492bf4d37aSMatthias Braun	ir/libcore/lc_opts_enum.c
1502bf4d37aSMatthias Braun	ir/libcore/lc_printf.c
1512bf4d37aSMatthias Braun	ir/lower/lower_alloc.c
1522bf4d37aSMatthias Braun	ir/lower/lower_builtins.c
1532bf4d37aSMatthias Braun	ir/lower/lower_calls.c
1542bf4d37aSMatthias Braun	ir/lower/lower_copyb.c
1552bf4d37aSMatthias Braun	ir/lower/lower_dw.c
1562bf4d37aSMatthias Braun	ir/lower/lower_hl.c
1572bf4d37aSMatthias Braun	ir/lower/lower_intrinsics.c
1582bf4d37aSMatthias Braun	ir/lower/lower_mode_b.c
1592bf4d37aSMatthias Braun	ir/lower/lower_mux.c
1602bf4d37aSMatthias Braun	ir/lower/lower_softfloat.c
1612bf4d37aSMatthias Braun	ir/lower/lower_switch.c
1622bf4d37aSMatthias Braun	ir/lpp/lpp.c
1632bf4d37aSMatthias Braun	ir/lpp/lpp_cplex.c
1642bf4d37aSMatthias Braun	ir/lpp/lpp_gurobi.c
1652bf4d37aSMatthias Braun	ir/lpp/lpp_solvers.c
1662bf4d37aSMatthias Braun	ir/lpp/mps.c
1672bf4d37aSMatthias Braun	ir/lpp/sp_matrix.c
1682bf4d37aSMatthias Braun	ir/obstack/obstack.c
1692bf4d37aSMatthias Braun	ir/obstack/obstack_printf.c
1702bf4d37aSMatthias Braun	ir/opt/boolopt.c
1712bf4d37aSMatthias Braun	ir/opt/cfopt.c
1722bf4d37aSMatthias Braun	ir/opt/code_placement.c
1732bf4d37aSMatthias Braun	ir/opt/combo.c
1742bf4d37aSMatthias Braun	ir/opt/convopt.c
1752bf4d37aSMatthias Braun	ir/opt/critical_edges.c
1762bf4d37aSMatthias Braun	ir/opt/dead_code_elimination.c
1772bf4d37aSMatthias Braun	ir/opt/funccall.c
1782bf4d37aSMatthias Braun	ir/opt/garbage_collect.c
1792bf4d37aSMatthias Braun	ir/opt/gvn_pre.c
1802bf4d37aSMatthias Braun	ir/opt/ifconv.c
181a020b3f3SMatthias Braun	ir/opt/instrument.c
1822bf4d37aSMatthias Braun	ir/opt/ircgopt.c
183a020b3f3SMatthias Braun	ir/opt/ircomplib.c
184a020b3f3SMatthias Braun	ir/opt/irgopt.c
185a020b3f3SMatthias Braun	ir/opt/iropt.c
1862bf4d37aSMatthias Braun	ir/opt/jumpthreading.c
1872bf4d37aSMatthias Braun	ir/opt/ldstopt.c
1882bf4d37aSMatthias Braun	ir/opt/loop.c
1892bf4d37aSMatthias Braun	ir/opt/occult_const.c
1902bf4d37aSMatthias Braun	ir/opt/opt_blocks.c
1912bf4d37aSMatthias Braun	ir/opt/opt_confirms.c
1922bf4d37aSMatthias Braun	ir/opt/opt_frame.c
1932bf4d37aSMatthias Braun	ir/opt/opt_inline.c
1942bf4d37aSMatthias Braun	ir/opt/opt_ldst.c
1952bf4d37aSMatthias Braun	ir/opt/opt_osr.c
1962bf4d37aSMatthias Braun	ir/opt/parallelize_mem.c
1972bf4d37aSMatthias Braun	ir/opt/proc_cloning.c
1982bf4d37aSMatthias Braun	ir/opt/reassoc.c
1992bf4d37aSMatthias Braun	ir/opt/return.c
200a020b3f3SMatthias Braun	ir/opt/rm_bads.c
201a020b3f3SMatthias Braun	ir/opt/rm_tuples.c
2022bf4d37aSMatthias Braun	ir/opt/scalar_replace.c
2032bf4d37aSMatthias Braun	ir/opt/tailrec.c
204a020b3f3SMatthias Braun	ir/opt/unreachable.c
2052bf4d37aSMatthias Braun	ir/stat/stat_timing.c
2062bf4d37aSMatthias Braun	ir/stat/statev.c
2072bf4d37aSMatthias Braun	ir/tr/entity.c
2082bf4d37aSMatthias Braun	ir/tr/tr_inheritance.c
2092bf4d37aSMatthias Braun	ir/tr/trverify.c
2102bf4d37aSMatthias Braun	ir/tr/type.c
2112bf4d37aSMatthias Braun	ir/tr/typewalk.c
2122bf4d37aSMatthias Braun	ir/tv/fltcalc.c
2132bf4d37aSMatthias Braun	ir/tv/strcalc.c
2142bf4d37aSMatthias Braun	ir/tv/tv.c
2152bf4d37aSMatthias Braun)
2162bf4d37aSMatthias Brauninclude_directories(
2172bf4d37aSMatthias Braun	include
2182bf4d37aSMatthias Braun	include/libfirm
2192bf4d37aSMatthias Braun	include/libfirm/adt
2202bf4d37aSMatthias Braun	ir/adt
2212bf4d37aSMatthias Braun	ir/ana
2222bf4d37aSMatthias Braun	ir/be
2232bf4d37aSMatthias Braun	ir/common
2242bf4d37aSMatthias Braun	ir/debug
2252bf4d37aSMatthias Braun	ir/ident
2262bf4d37aSMatthias Braun	ir/ir
2272bf4d37aSMatthias Braun	ir/kaps
2282bf4d37aSMatthias Braun	ir/libcore
2292bf4d37aSMatthias Braun	ir/lower
2302bf4d37aSMatthias Braun	ir/lpp
2312bf4d37aSMatthias Braun	ir/lower
2322bf4d37aSMatthias Braun	ir/obstack
2332bf4d37aSMatthias Braun	ir/opt
2342bf4d37aSMatthias Braun	ir/stat
2352bf4d37aSMatthias Braun	ir/tr
2362bf4d37aSMatthias Braun	ir/tv
2372bf4d37aSMatthias Braun)
2382bf4d37aSMatthias Braun
2390d4b421eSMoritz Baumannset(TESTS
2400d4b421eSMoritz Baumann	unittests/deq
2410d4b421eSMoritz Baumann	unittests/globalmap
2420d4b421eSMoritz Baumann	unittests/nan_payload
2430d4b421eSMoritz Baumann	unittests/rbitset
2440d4b421eSMoritz Baumann	unittests/sc_val_from_bits
2450d4b421eSMoritz Baumann	unittests/snprintf
2460d4b421eSMoritz Baumann	unittests/strcalc
2470d4b421eSMoritz Baumann	unittests/tarval_calc
2480d4b421eSMoritz Baumann	unittests/tarval_float
2490d4b421eSMoritz Baumann	unittests/tarval_floatops
2500d4b421eSMoritz Baumann	unittests/tarval_from_to
2510d4b421eSMoritz Baumann	unittests/tarval_is_long
2520d4b421eSMoritz Baumann)
2530d4b421eSMoritz Baumann
2542bf4d37aSMatthias Braun# Codegenerators
2552bf4d37aSMatthias Braunset(GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/gen")
2562bf4d37aSMatthias Braunset(GEN_IR_DIR "${PROJECT_SOURCE_DIR}/scripts")
2572bf4d37aSMatthias Braunset(IR_SPEC "${PROJECT_SOURCE_DIR}/scripts/ir_spec.py")
2582bf4d37aSMatthias Braunset(GEN_TEMPLATEDIR "${PROJECT_SOURCE_DIR}/scripts/templates")
2592bf4d37aSMatthias Braun
2606e196911SMatthias Braunset(Python_ADDITIONAL_VERSIONS 2.7 3.0 3.1 3.2 3.3 3.4)
2616e196911SMatthias Brauninclude(FindPythonInterp)
2626e196911SMatthias Braunif(NOT PYTHONINTERP_FOUND)
2636e196911SMatthias Braun	message(FATAL_ERROR "Unable to find python interpreter")
2646e196911SMatthias Braunendif()
2656e196911SMatthias Brauninclude(FindPerl)
2666e196911SMatthias Braunif(NOT PERL_FOUND)
2676e196911SMatthias Braun	message(FATAL_ERROR "Unable to find perl interpreter")
2686e196911SMatthias Braunendif()
2696e196911SMatthias Braun
2702bf4d37aSMatthias Braunfunction(gen_ir target)
271ce080a0fSMatthias Braun	get_filename_component(basename ${target} NAME)
272ce080a0fSMatthias Braun	get_filename_component(target_dir ${target} DIRECTORY)
2732bf4d37aSMatthias Braun	add_custom_command (
2742bf4d37aSMatthias Braun		OUTPUT ${target}
275ce080a0fSMatthias Braun		COMMAND ${CMAKE_COMMAND} -E make_directory ${target_dir}
2766e196911SMatthias Braun		COMMAND ${PYTHON_EXECUTABLE} ${GEN_IR_DIR}/gen_ir.py ${IR_SPEC} ${GEN_TEMPLATEDIR}/${basename} > ${target}
2772bf4d37aSMatthias Braun		DEPENDS ${GEN_IR_DIR}/gen_ir.py ${GEN_IR_DIR}/jinjautil.py ${GEN_IR_DIR}/irops.py ${IR_SPEC}
2782bf4d37aSMatthias Braun	)
2792bf4d37aSMatthias Braun	list(APPEND SOURCES ${target})
2802bf4d37aSMatthias Braun	set(SOURCES ${SOURCES} PARENT_SCOPE)
2812bf4d37aSMatthias Braunendfunction()
2822bf4d37aSMatthias Braun
2832bf4d37aSMatthias Braunfunction(begen generator target spec)
284ce080a0fSMatthias Braun	get_filename_component(target_dir ${target} DIRECTORY)
2852bf4d37aSMatthias Braun	set(GENERATOR ${PROJECT_SOURCE_DIR}/ir/be/scripts/${generator})
2862bf4d37aSMatthias Braun	add_custom_command(
2872bf4d37aSMatthias Braun		OUTPUT ${target}
288ce080a0fSMatthias Braun		COMMAND ${CMAKE_COMMAND} -E make_directory ${target_dir}
289ce080a0fSMatthias Braun		COMMAND ${PERL_EXECUTABLE} ${GENERATOR} ${spec} ${target_dir}
2902bf4d37aSMatthias Braun		DEPENDS ${GENERATOR} ${spec}
2912bf4d37aSMatthias Braun	)
2922bf4d37aSMatthias Braun	list(APPEND SOURCES ${target})
2932bf4d37aSMatthias Braun	set(SOURCES ${SOURCES} PARENT_SCOPE)
2942bf4d37aSMatthias Braunendfunction()
2952bf4d37aSMatthias Braun
2962bf4d37aSMatthias Braunfunction(add_backend name)
2972bf4d37aSMatthias Braun	list(APPEND SOURCES ${ARGN})
2982bf4d37aSMatthias Braun	set(SPEC ${PROJECT_SOURCE_DIR}/ir/be/${name}/${name}_spec.pl)
2992bf4d37aSMatthias Braun	begen(generate_emitter.pl
3002bf4d37aSMatthias Braun		${GEN_DIR}/ir/be/${name}/gen_${name}_emitter.c
3012bf4d37aSMatthias Braun		${SPEC})
3022bf4d37aSMatthias Braun	begen(generate_regalloc_if.pl
3032bf4d37aSMatthias Braun		${GEN_DIR}/ir/be/${name}/gen_${name}_regalloc_if.c
3042bf4d37aSMatthias Braun		${SPEC})
3052bf4d37aSMatthias Braun	begen(generate_new_opcodes.pl
30604580e62SMatthias Braun		${GEN_DIR}/ir/be/${name}/gen_${name}_new_nodes.c
3072bf4d37aSMatthias Braun		${SPEC})
3082bf4d37aSMatthias Braun	set(SOURCES ${SOURCES} PARENT_SCOPE)
3092bf4d37aSMatthias Braun	include_directories(
3102bf4d37aSMatthias Braun		${PROJECT_SOURCE_DIR}/ir/be/${name}
3112bf4d37aSMatthias Braun		${GEN_DIR}/ir/be/${name}
3122bf4d37aSMatthias Braun	)
3132bf4d37aSMatthias Braunendfunction()
3142bf4d37aSMatthias Braun
3152bf4d37aSMatthias Braunforeach(file
3162bf4d37aSMatthias Braun	include/libfirm/nodes.h
3172bf4d37aSMatthias Braun	ir/ir/gen_irnode.h
318d139b0b0SMatthias Braun	ir/ir/gen_proj_names.h
319ca1a30a4SMatthias Braun	ir/ir/gen_irio.c
3202bf4d37aSMatthias Braun	ir/ir/gen_irnode.c)
3212bf4d37aSMatthias Braun	gen_ir(${GEN_DIR}/${file})
3222bf4d37aSMatthias Braunendforeach(file)
3232bf4d37aSMatthias Brauninclude_directories(
3242bf4d37aSMatthias Braun	${GEN_DIR}/include/libfirm
3252bf4d37aSMatthias Braun	${GEN_DIR}/ir/ir
3262bf4d37aSMatthias Braun)
3272bf4d37aSMatthias Braun
3282bf4d37aSMatthias Braunadd_backend(ia32
3292bf4d37aSMatthias Braun	ir/be/ia32/ia32_architecture.c
33062592dcbSMatthias Braun	ir/be/ia32/ia32_bearch.c
3312bf4d37aSMatthias Braun	ir/be/ia32/ia32_cconv.c
3322bf4d37aSMatthias Braun	ir/be/ia32/ia32_emitter.c
33362592dcbSMatthias Braun	ir/be/ia32/ia32_encode.c
3342bf4d37aSMatthias Braun	ir/be/ia32/ia32_finish.c
3352bf4d37aSMatthias Braun	ir/be/ia32/ia32_fpu.c
3362bf4d37aSMatthias Braun	ir/be/ia32/ia32_intrinsics.c
3372bf4d37aSMatthias Braun	ir/be/ia32/ia32_new_nodes.c
3382bf4d37aSMatthias Braun	ir/be/ia32/ia32_optimize.c
3392bf4d37aSMatthias Braun	ir/be/ia32/ia32_pic.c
3402bf4d37aSMatthias Braun	ir/be/ia32/ia32_transform.c
3412bf4d37aSMatthias Braun	ir/be/ia32/x86_address_mode.c
3422bf4d37aSMatthias Braun	ir/be/ia32/x86_asm.c
3432bf4d37aSMatthias Braun	ir/be/ia32/x86_cconv.c
34462592dcbSMatthias Braun	ir/be/ia32/x86_node.c
34523e0fe1eSMatthias Braun	ir/be/ia32/x86_x87.c
3462bf4d37aSMatthias Braun)
3472bf4d37aSMatthias Braunadd_backend(arm
34862592dcbSMatthias Braun	ir/be/arm/arm_bearch.c
3492bf4d37aSMatthias Braun	ir/be/arm/arm_cconv.c
3502bf4d37aSMatthias Braun	ir/be/arm/arm_emitter.c
3512bf4d37aSMatthias Braun	ir/be/arm/arm_finish.c
3522bf4d37aSMatthias Braun	ir/be/arm/arm_lower64.c
3532bf4d37aSMatthias Braun	ir/be/arm/arm_new_nodes.c
3542bf4d37aSMatthias Braun	ir/be/arm/arm_optimize.c
3552bf4d37aSMatthias Braun	ir/be/arm/arm_transform.c
3562bf4d37aSMatthias Braun)
3572bf4d37aSMatthias Braunadd_backend(sparc
35862592dcbSMatthias Braun	ir/be/sparc/sparc_bearch.c
3592bf4d37aSMatthias Braun	ir/be/sparc/sparc_cconv.c
3602bf4d37aSMatthias Braun	ir/be/sparc/sparc_emitter.c
3612bf4d37aSMatthias Braun	ir/be/sparc/sparc_finish.c
3622bf4d37aSMatthias Braun	ir/be/sparc/sparc_lower64.c
3632bf4d37aSMatthias Braun	ir/be/sparc/sparc_new_nodes.c
3642bf4d37aSMatthias Braun	ir/be/sparc/sparc_stackframe.c
3652bf4d37aSMatthias Braun	ir/be/sparc/sparc_transform.c
3662bf4d37aSMatthias Braun)
3672bf4d37aSMatthias Braunadd_backend(amd64
36862592dcbSMatthias Braun	ir/be/amd64/amd64_bearch.c
3692bf4d37aSMatthias Braun	ir/be/amd64/amd64_cconv.c
3702bf4d37aSMatthias Braun	ir/be/amd64/amd64_emitter.c
3712bf4d37aSMatthias Braun	ir/be/amd64/amd64_finish.c
3722bf4d37aSMatthias Braun	ir/be/amd64/amd64_new_nodes.c
3732c39abe4SMoritz Baumann	ir/be/amd64/amd64_optimize.c
374c7c17713SMatthias Braun	ir/be/amd64/amd64_pic.c
3752bf4d37aSMatthias Braun	ir/be/amd64/amd64_transform.c
376c7c17713SMatthias Braun	ir/be/amd64/amd64_varargs.c
37797df3ae6SMatthias Braun	ir/be/amd64/amd64_x87.c
3782bf4d37aSMatthias Braun)
3792bf4d37aSMatthias Braunadd_backend(TEMPLATE
38062592dcbSMatthias Braun	ir/be/TEMPLATE/TEMPLATE_bearch.c
3812bf4d37aSMatthias Braun	ir/be/TEMPLATE/TEMPLATE_emitter.c
3822bf4d37aSMatthias Braun	ir/be/TEMPLATE/TEMPLATE_new_nodes.c
3832bf4d37aSMatthias Braun	ir/be/TEMPLATE/TEMPLATE_transform.c
3842bf4d37aSMatthias Braun)
3852bf4d37aSMatthias Braun
3866b1a3ef2SMatthias Braun# Produce revision.h
3876b1a3ef2SMatthias Brauninclude_directories(${CMAKE_CURRENT_BINARY_DIR})
3886b1a3ef2SMatthias Braunif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/HEAD)
3896b1a3ef2SMatthias Braun	set(REVISIONH "${CMAKE_CURRENT_BINARY_DIR}/firm_revision.h")
3906b1a3ef2SMatthias Braun	set(REVGEN echo '\#define libfirm_VERSION_REVISION \"'`git describe --abbrev=40 --always --dirty --match ''`'\"')
3916b1a3ef2SMatthias Braun	add_custom_command(
3926b1a3ef2SMatthias Braun		OUTPUT ${REVISIONH}
3936b1a3ef2SMatthias Braun		DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/.git/HEAD
3946b1a3ef2SMatthias Braun		COMMAND ${REVGEN} | cmp -s - "${REVISIONH}" 2> /dev/null || ${REVGEN} > "${REVISIONH}"
3956b1a3ef2SMatthias Braun		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
3966b1a3ef2SMatthias Braun	)
3976b1a3ef2SMatthias Braun	SET_SOURCE_FILES_PROPERTIES(ir/common/firm.c PROPERTIES OBJECT_DEPENDS ${REVISIONH})
3986b1a3ef2SMatthias Braun	add_definitions(-DHAVE_FIRM_REVISION_H)
3996b1a3ef2SMatthias Braunendif()
4002bf4d37aSMatthias Braun
4012bf4d37aSMatthias Braun# Enable C99
4022bf4d37aSMatthias Braunif(CMAKE_VERSION VERSION_LESS "3.1")
4032bf4d37aSMatthias Braun	if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
404b921e546SMatthias Braun		set(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
4052bf4d37aSMatthias Braun	endif()
4062bf4d37aSMatthias Braunelse()
4072bf4d37aSMatthias Braun	set(CMAKE_C_STANDARD 99)
4082bf4d37aSMatthias Braunendif()
4092bf4d37aSMatthias Braun# Indicate that we build a shared library
4102bf4d37aSMatthias Braunadd_definitions(-DFIRM_BUILD -DFIRM_DLL)
4112bf4d37aSMatthias Braun
4126b1a3ef2SMatthias Braun# Build library
4136b1a3ef2SMatthias Braunset(BUILD_SHARED_LIBS Off CACHE BOOL "whether to build shared libraries")
4146b1a3ef2SMatthias Braunadd_library(firm ${SOURCES})
4156b1a3ef2SMatthias Braunif(UNIX)
4166b1a3ef2SMatthias Braun	target_link_libraries(firm LINK_PUBLIC m)
4175a89d4b8SMoritz Baumannelseif(WIN32)
4185a89d4b8SMoritz Baumann	target_link_libraries(firm LINK_PUBLIC gnurx winmm)
4196b1a3ef2SMatthias Braunendif()
4206b1a3ef2SMatthias Braun
4210d4b421eSMoritz Baumannenable_testing()
4220d4b421eSMoritz Baumannadd_custom_target(
4230d4b421eSMoritz Baumann		check
4240d4b421eSMoritz Baumann		${CMAKE_CTEST_COMMAND} -C $<CONFIG>
4250d4b421eSMoritz Baumann		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
4260d4b421eSMoritz Baumann)
4270d4b421eSMoritz Baumannforeach(test ${TESTS})
4280d4b421eSMoritz Baumann	# Replace `/` with a `.` so cmake accepts the target name
4290d4b421eSMoritz Baumann	string(REPLACE "/" "." test-id ${test})
4300d4b421eSMoritz Baumann	add_executable(${test-id} ${test}.c)
4310d4b421eSMoritz Baumann	target_link_libraries(${test-id} LINK_PRIVATE firm)
4320d4b421eSMoritz Baumann	add_test(test-${test-id} ${test-id})
4330d4b421eSMoritz Baumann	add_dependencies(check ${test-id})
4340d4b421eSMoritz Baumannendforeach(test)
4350d4b421eSMoritz Baumann
4362bf4d37aSMatthias Braun# Create install target
4372bf4d37aSMatthias Braunset(INSTALL_HEADERS
4382bf4d37aSMatthias Braun	include/libfirm/adt/array.h
4392bf4d37aSMatthias Braun	include/libfirm/adt/bipartite.h
4402bf4d37aSMatthias Braun	include/libfirm/adt/funcattr.h
4412bf4d37aSMatthias Braun	include/libfirm/adt/gaussjordan.h
4422bf4d37aSMatthias Braun	include/libfirm/adt/gaussseidel.h
4432bf4d37aSMatthias Braun	include/libfirm/adt/hashptr.h
4442bf4d37aSMatthias Braun	include/libfirm/adt/hungarian.h
4452bf4d37aSMatthias Braun	include/libfirm/adt/list.h
4462bf4d37aSMatthias Braun	include/libfirm/adt/obst.h
4472bf4d37aSMatthias Braun	include/libfirm/adt/obstack.h
4482bf4d37aSMatthias Braun	include/libfirm/adt/pmap.h
4492bf4d37aSMatthias Braun	include/libfirm/adt/pqueue.h
4502bf4d37aSMatthias Braun	include/libfirm/adt/pset.h
4512bf4d37aSMatthias Braun	include/libfirm/adt/set.h
4522bf4d37aSMatthias Braun	include/libfirm/adt/unionfind.h
4532bf4d37aSMatthias Braun	include/libfirm/adt/xmalloc.h
4542bf4d37aSMatthias Braun	include/libfirm/analyze_irg_args.h
4552bf4d37aSMatthias Braun	include/libfirm/be.h
4562bf4d37aSMatthias Braun	include/libfirm/begin.h
4572bf4d37aSMatthias Braun	include/libfirm/callgraph.h
4582bf4d37aSMatthias Braun	include/libfirm/cdep.h
4592bf4d37aSMatthias Braun	include/libfirm/cgana.h
4602bf4d37aSMatthias Braun	include/libfirm/dbginfo.h
4612bf4d37aSMatthias Braun	include/libfirm/end.h
4622bf4d37aSMatthias Braun	include/libfirm/execfreq.h
4632bf4d37aSMatthias Braun	include/libfirm/firm.h
4642bf4d37aSMatthias Braun	include/libfirm/firm_common.h
4652bf4d37aSMatthias Braun	include/libfirm/firm_types.h
4662bf4d37aSMatthias Braun	include/libfirm/heights.h
4672bf4d37aSMatthias Braun	include/libfirm/ident.h
4682bf4d37aSMatthias Braun	include/libfirm/irarch.h
4692bf4d37aSMatthias Braun	include/libfirm/ircgopt.h
4702bf4d37aSMatthias Braun	include/libfirm/ircons.h
4712bf4d37aSMatthias Braun	include/libfirm/irconsconfirm.h
4722bf4d37aSMatthias Braun	include/libfirm/irdom.h
4732bf4d37aSMatthias Braun	include/libfirm/irdump.h
4742bf4d37aSMatthias Braun	include/libfirm/iredgekinds.h
4752bf4d37aSMatthias Braun	include/libfirm/iredges.h
4762bf4d37aSMatthias Braun	include/libfirm/irflag.h
4772bf4d37aSMatthias Braun	include/libfirm/irgmod.h
4782bf4d37aSMatthias Braun	include/libfirm/irgopt.h
4792bf4d37aSMatthias Braun	include/libfirm/irgraph.h
4802bf4d37aSMatthias Braun	include/libfirm/irgwalk.h
4812bf4d37aSMatthias Braun	include/libfirm/irio.h
4822bf4d37aSMatthias Braun	include/libfirm/irloop.h
4832bf4d37aSMatthias Braun	include/libfirm/irmemory.h
4842bf4d37aSMatthias Braun	include/libfirm/irmode.h
4852bf4d37aSMatthias Braun	include/libfirm/irnode.h
4862bf4d37aSMatthias Braun	include/libfirm/irop.h
4872bf4d37aSMatthias Braun	include/libfirm/iropt.h
4882bf4d37aSMatthias Braun	include/libfirm/iroptimize.h
4892bf4d37aSMatthias Braun	include/libfirm/irouts.h
4902bf4d37aSMatthias Braun	include/libfirm/irprintf.h
4912bf4d37aSMatthias Braun	include/libfirm/irprog.h
4922bf4d37aSMatthias Braun	include/libfirm/irverify.h
4932bf4d37aSMatthias Braun	include/libfirm/lowering.h
4942bf4d37aSMatthias Braun	include/libfirm/statev.h
4952bf4d37aSMatthias Braun	include/libfirm/timing.h
4962bf4d37aSMatthias Braun	include/libfirm/tv.h
4972bf4d37aSMatthias Braun	include/libfirm/typerep.h
4982bf4d37aSMatthias Braun	include/libfirm/vrp.h
4992bf4d37aSMatthias Braun)
5002bf4d37aSMatthias Braun
5012bf4d37aSMatthias Brauninstall(TARGETS firm
5020158e2f8SMatthias Braun	EXPORT libfirmTargets
5036b1a3ef2SMatthias Braun	DESTINATION lib
5042bf4d37aSMatthias Braun)
5052bf4d37aSMatthias Braunforeach(header ${INSTALL_HEADERS})
5062bf4d37aSMatthias Braun	get_filename_component(DIR ${header} DIRECTORY)
5072bf4d37aSMatthias Braun	install(FILES ${header} DESTINATION ${DIR})
5082bf4d37aSMatthias Braunendforeach(header)
5092bf4d37aSMatthias Brauninstall(FILES ${CMAKE_CURRENT_BINARY_DIR}/gen/include/libfirm/nodes.h DESTINATION include/libfirm)
5102bf4d37aSMatthias Braun
5110158e2f8SMatthias Braun# Generate cmake Config file
5120158e2f8SMatthias Brauninclude(CMakePackageConfigHelpers)
5130158e2f8SMatthias Braunset(libfirm_INCLUDE_DIRS include)
5140158e2f8SMatthias Braunset(ConfigPackageLocation lib/cmake/libfirm)
5150158e2f8SMatthias Braunconfigure_package_config_file(support/libfirmConfig.cmake.in
5160158e2f8SMatthias Braun	${CMAKE_CURRENT_BINARY_DIR}/libfirmConfig.cmake
5170158e2f8SMatthias Braun	INSTALL_DESTINATION ${ConfigPackageLocation}
5180158e2f8SMatthias Braun	PATH_VARS libfirm_INCLUDE_DIRS
5190158e2f8SMatthias Braun)
5200158e2f8SMatthias Braunwrite_basic_package_version_file(
5210158e2f8SMatthias Braun	${CMAKE_CURRENT_BINARY_DIR}/libfirmConfigVersion.cmake
5220158e2f8SMatthias Braun	VERSION ${libfirm_VERSION}
5230158e2f8SMatthias Braun	COMPATIBILITY ExactVersion
5240158e2f8SMatthias Braun)
5250158e2f8SMatthias Brauninstall(FILES ${CMAKE_CURRENT_BINARY_DIR}/libfirmConfig.cmake
5260158e2f8SMatthias Braun              ${CMAKE_CURRENT_BINARY_DIR}/libfirmConfigVersion.cmake
5270158e2f8SMatthias Braun        DESTINATION ${ConfigPackageLocation}
5280158e2f8SMatthias Braun)
5290158e2f8SMatthias Brauninstall(EXPORT libfirmTargets
5300158e2f8SMatthias Braun	FILE libfirmTargets.cmake
5310158e2f8SMatthias Braun	NAMESPACE libfirm::
5320158e2f8SMatthias Braun	DESTINATION ${ConfigPackageLocation}
5332bf4d37aSMatthias Braun)
5342bf4d37aSMatthias Braun
5352bf4d37aSMatthias Braun# Generate pkg-config for external projects
5360158e2f8SMatthias Braunconfigure_file(${CMAKE_CURRENT_SOURCE_DIR}/support/libfirm.pc.in
5370158e2f8SMatthias Braun	${CMAKE_CURRENT_BINARY_DIR}/libfirm.pc
5380158e2f8SMatthias Braun	@ONLY
5390158e2f8SMatthias Braun)
5400158e2f8SMatthias Brauninstall(FILES "${CMAKE_CURRENT_BINARY_DIR}/libfirm.pc"
5410158e2f8SMatthias Braun	DESTINATION lib/pkgconfig
5422bf4d37aSMatthias Braun)
543