2 # Last synched with Makefile.am at r134597
4 cmake_policy(SET CMP0010 NEW)
8 function(add_cs_target target sources args depends)
9 separate_arguments(sources)
10 separate_arguments(args)
11 separate_arguments(depends)
14 COMMAND ${MCS} -out:${target} ${args} ${sources}
15 DEPENDS ${sources} ${depends}
17 add_custom_target (${target}-target DEPENDS ${target})
20 function(add_cs_dll target sources args depends)
21 add_cs_target(${target} ${sources} "-target:library ${args}" "${depends}")
24 function(add_cs_exe target sources args depends)
25 add_cs_target(${target} ${sources} "-target:exe ${args}" "${depends}")
28 function(add_il_target target sources args)
29 separate_arguments(sources)
30 separate_arguments(args)
33 COMMAND ${ILASM} -output=${target} ${args} ${sources}
36 add_custom_target (${target}-target DEPENDS ${target})
44 set(monodir ${top_builddir})
46 set(CLASS ${mcs_topdir}/class/lib/net_2_0)
48 set(RUNTIME MONO_PATH=${CLASS} ${top_builddir}/runtime/mono-wrapper)
49 set(RUNTIME_AOTCHECK MONO_PATH=${CLASS}:. ${top_builddir}/runtime/mono-wrapper)
51 set(MCS ${RUNTIME} ${CLASS}/gmcs.exe -unsafe -nowarn:0162)
52 set(ILASM ${RUNTIME} ${CLASS}/ilasm.exe)
170 mini-generic-sharing.c
199 generics-variant-types.il
202 if(MONO_DEBUGGER_SUPPORTED)
204 set(mono_debugger_arch_sources mdb-debug-info64.s)
206 set(mono_debugger_arch_sources mdb-debug-info32.s)
208 enable_language(ASM-ATT)
209 set(mono_debugger_sources debug-debugger.c debug-debugger.h ${mono_debugger_arch_sources})
212 else(MONO_DEBUGGER_SUPPORTED)
213 set(mono_debugger_sources)
214 endif(MONO_DEBUGGER_SUPPORTED)
216 set(regtests basic.exe basic-float.exe basic-long.exe basic-calls.exe objects.exe arrays.exe basic-math.exe exceptions.exe iltests.exe devirtualization.exe generics.exe basic-simd.exe)
219 set(arch_sources ${x86_sources} ${mono_debugger_sources})
220 set(arch_built cpu-x86.h)
221 set(arch_define __i386__)
225 set(arch_sources ${amd64_sources} ${mono_debugger_sources})
226 set(arch_built cpu-amd64.h)
227 set(arch_define __x86_64__)
231 set(arch_sources ${ppc_sources})
232 set(arch_built cpu-ppc.h)
233 set(arch_define __ppc__)
237 set(arch_sources ${ppc_sources})
238 set(arch_built cpu-ppc64.h)
239 set(arch_define __ppc64__)
243 set(arch_sources ${mips_sources})
244 set(arch_built cpu-mips.h)
245 set(arch_define __mips__)
249 # pick up arm_dpimacros.h and arm_fpamacros.h
250 set(ARCH_CFLAGS -I../arch/arm)
251 set(arch_sources ${arm_sources})
252 set(arch_built cpu-arm.h)
253 set(arch_define __arm__)
257 set(arch_sources ${sparc_sources})
258 set(arch_built cpu-sparc.h)
259 set(arch_define __sparc__)
263 set(arch_sources ${sparc_sources})
264 set(arch_built cpu-sparc.h)
265 set(arch_define __sparc__)
269 set(arch_sources ${s390_sources})
270 set(arch_built cpu-s390.h)
271 set(arch_define __s390__)
275 set(arch_sources ${s390x_sources})
276 set(arch_built cpu-s390x.h)
277 set(arch_define __s390__)
281 set(arch_sources ${ia64_sources})
282 set(arch_built cpu-ia64.h)
283 set(arch_define __ia64__)
287 set(arch_sources ${alpha_sources} ${mono_debugger_sources})
288 set(arch_built cpu-alpha.h)
289 set(arch_define __alpha__)
293 # Only support 32-bit targets for now
294 set(arch_sources ${hppa_sources})
295 set(arch_built cpu-hppa.h)
296 set(arch_define __hppa__)
300 set(os_sources ${windows_sources})
303 if(PLATFORM_SIGPOSIX)
304 set(os_sources ${posix_sources})
308 set(os_sources ${darwin_sources} ${posix_sources})
311 #### we don't always use the perl impl because it's an additional
312 #### build dependency for the poor windows users
313 #### ${arch_define} is the preprocessor symbol that enables all the opcodes
314 #### for the specific platform in mini-ops.h
315 ###if CROSS_COMPILING
316 ###GENMDESC_PRG=perl ${srcdir)/genmdesc.pl ${arch_define} ${srcdir)
317 ###else !CROSS_COMPILING
318 set(GENMDESC_PRG ${CMAKE_CURRENT_BINARY_DIR}/genmdesc)
319 ###endif !CROSS_COMPILING
321 function(add_genmdesc_target target source define)
323 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}
324 COMMAND ${GENMDESC_PRG} ${CMAKE_CURRENT_BINARY_DIR}/${target} ${define} ${source}
325 DEPENDS genmdesc ${source}
329 foreach(arch x86 amd64 sparc ia64 alpha hppa mips)
330 add_genmdesc_target(cpu-${arch}.h cpu-${arch}.md ${arch}_desc)
333 add_genmdesc_target(cpu-ppc.h cpu-ppc.md ppcg4)
334 add_genmdesc_target(cpu-ppc64.h cpu-ppc64.md ppc64_cpu_desc)
335 add_genmdesc_target(cpu-arm.h cpu-arm.md arm_cpu_desc)
336 add_genmdesc_target(cpu-s390.h cpu-s390.md s390_cpu_desc)
337 add_genmdesc_target(cpu-s390x.h cpu-s390x.md s390x_cpu_desc)
339 include_directories(../..)
340 include_directories(${GLIB2_INCLUDE_DIRS})
341 include_directories(${LIBGC_INCLUDE_DIRS})
343 link_directories(../../libgc/.libs)
344 set(CMAKE_C_FLAGS "${CFLAGS} ${LIBGC_CFLAGS} ${CPPFLAGS}")
347 add_executable(genmdesc genmdesc.c helpers.c)
348 target_link_libraries(genmdesc monoutils-static monoruntime-static ${GLIB2_LIBRARIES})
352 set(libmono_la_SOURCES ${common_sources} ${llvm_sources} ${arch_sources} ${os_sources})
354 # FIXME: cmake doesn't seem to recognize the ${arch_built} dependency
355 add_library(libmono-static STATIC ${libmono_la_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/${arch_built})
356 target_link_libraries(libmono-static monoruntime-static monoutils-static monogc-static wapi-static ${GLIB2_LIBRARIES} ${LIBS})
357 set_target_properties(libmono-static PROPERTIES OUTPUT_NAME "mono-static")
359 # FIXME: cmake has no support for convenience libraries, so we would end up
360 # creating a lot of shared libraries linking to each other
361 #add_library(libmono SHARED ${libmono_la_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/${arch_built})
362 #set_target_properties(libmono PROPERTIES OUTPUT_NAME "mono")
363 #target_link_libraries(libmono monoruntime monoutils monogc wapi ${GLIB2_LIBRARIES} ${LIBS})
367 # Its a pain to try to pass a complex shell script to add_custom_command (), so
368 # write it to disk instead
369 # " needs to be escaped as \"
370 # \ needs to be escaped as \\
371 set(top_srcdir ../../)
372 file(WRITE create-version.h.sh "
373 if test -d ${top_srcdir}/.git/svn; then svn_info=\"echo \\\"`git log --no-color --first-parent --pretty=format:%b|grep -m1 git-svn-id|sed -e 's,git-svn-id: \\(.*\\)@\\(.*\\) .*,URL: \\1 Revision: \\2,'`\"; fi;
374 if test -d ${srcdir}/.svn; then svn_info='svn info'; fi;
375 if test -n \"$svn_info\"; then
378 branch=`$svn_info | grep URL | sed -e 's,.*source/\\(.*\\)/mono.*,/\\1/mono,'`;
379 version=`$svn_info | grep Revision | sed 's/.*: //'`;
380 echo \"#define FULL_VERSION \\\"$branch r$version\\\"\";
383 echo \"#define FULL_VERSION \\\"tarball\\\"\";
387 # FIXME: dependencies ?
389 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.h
390 COMMAND chmod a+x ./create-version.h.sh
391 COMMAND ./create-version.h.sh
397 # We build this after libmono was built so it contains the date when the final
400 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/buildver.h
402 COMMAND sh -c "X='\"'; echo \"const char *build_date = $X`date`$X;\" > ${CMAKE_CURRENT_BINARY_DIR}/buildver.h"
403 DEPENDS libmono-static
406 set_source_files_properties(main.c PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/buildver.h)
407 set_source_files_properties(main.c PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/buildver.h)
411 add_executable(mono main.c ${CMAKE_CURRENT_BINARY_DIR}/buildver.h)
412 add_dependencies(mono libmono-static)
413 target_link_libraries(mono libmono-static ${GLIB2_LIBRARIES})
417 foreach(test ${test_sources})
418 if (${test} MATCHES ".*\\.cs")
419 string(REPLACE ".cs" ".exe" exe_name ${test})
420 add_cs_exe(${exe_name} ${test} "-r:TestDriver.dll -r:generics-variant-types.dll -r:Mono.Simd.dll" "TestDriver.dll generics-variant-types.dll")
424 set(il_source "iltests.il")
425 set(exe_name "iltests.exe")
428 COMMAND ${ILASM} -output=${exe_name} ${il_source}
431 add_custom_target(${exe_name}-exe DEPENDS ${exe_name})
435 COMMAND echo // DO NOT EDIT: This file has been generated from iltests.il.in > iltests.il
436 COMMAND cpp -Darch=${arch_define} < iltests.il.in | sed "s/^#.*//" >> iltests.il
437 DEPENDS iltests.il.in
441 add_cs_dll("TestDriver.dll" "TestDriver.cs" "-r:System.dll -r:System.dll" "")
443 add_il_target("generics-variant-types.dll" "generics-variant-types.il" "-dll")
447 add_custom_target(rcheck
448 COMMAND ${RUNTIME} --regression ${regtests}
449 DEPENDS mono ${regtests}
452 # FIXME: make runs rcheck, but then says: 'No rule to make target `rcheck', needed by `mono/mini/CMakeFiles/check'
453 #add_custom_target(check
455 add_custom_target(check
456 COMMAND ${RUNTIME} --regression ${regtests}
457 DEPENDS mono ${regtests}
460 add_custom_target(testi
461 COMMAND ${RUNTIME} -v -v --ncompile 1 --compile Test:${mtest} test.exe
462 DEPENDS mono test.exe
465 # ensure the tests are actually correct
466 add_custom_target(checktests
467 COMMAND for i in ${regtests}\; do ${RUNTIME} $$i\; done
471 add_custom_target(aotcheck
472 COMMAND rm -f *.exe.so
473 COMMAND ${RUNTIME} --aot ${regtests} || exit 1
474 COMMAND for i in ${regtests}\; do ${RUNTIME_AOTCHECK} --regression $$i || exit 1\; done
475 COMMAND rm -f *.exe.so
476 DEPENDS mono ${regtests}
479 # This currently only works on amd64/arm
480 add_custom_target(fullaotcheck
481 COMMAND rm -rf fullaot-tmp
482 COMMAND mkdir fullaot-tmp
483 COMMAND cp ${CLASS}/mscorlib.dll ${CLASS}/Mono.Simd.dll ${regtests} generics-variant-types.dll TestDriver.dll fullaot-tmp/
484 COMMAND cp ${regtests} fullaot-tmp/
485 COMMAND MONO_PATH=fullaot-tmp ${top_builddir}/runtime/mono-wrapper --aot=full fullaot-tmp/* || exit 1
486 COMMAND for i in ${regtests}\; do echo $$i\; MONO_PATH=fullaot-tmp ${top_builddir}/runtime/mono-wrapper --full-aot fullaot-tmp/$$i --exclude '!FULLAOT' || exit 1\; done
487 DEPENDS mono ${regtests}
490 add_custom_target(bench
491 COMMAND time env ${RUNTIME} --ncompile ${count} --compile Test:${mtest} test.exe
492 DEPENDS mono test.exe
495 add_custom_target(stat1
496 COMMAND ${RUNTIME} --verbose --statfile stats.pl --regression bench.exe
497 COMMAND perl viewstat.pl stats.pl
498 DEPENDS mono bench.exe
501 add_custom_target(stat2
502 COMMAND ${RUNTIME} --verbose --statfile stats.pl --regression basic.exe
503 COMMAND perl viewstat.pl -e stats.pl
504 DEPENDS mono basic.exe
507 add_custom_target(stat3
508 COMMAND ${RUNTIME} --statfile stats.pl --ncompile 1000 --compile Tests:test_0_many_nested_loops bench.exe
509 COMMAND perl viewstat.pl stats.pl
510 DEPENDS mono bench.exe
513 #### This is needed for automake dependency generation
515 ###libgc_libs=${monodir)/libgc/libmonogc.la
516 ###libgc_static_libs=${monodir)/libgc/libmonogc-static.la
518 ###libgc_libs=${LIBGC_LIBS)
519 ###libgc_static_libs=${LIBGC_STATIC_LIBS)
523 ### -I${top_srcdir} \
524 ### ${LIBGC_CFLAGS) \
526 ### ${PLATFORM_CFLAGS} ${ARCH_CFLAGS)
528 ###AM_CXXFLAGS = ${LLVM_CXXFLAGS} ${GLIB_CFLAGS)
532 #### The mingw math.h has "extern inline" functions that dont appear in libs, so
533 #### optimisation is required to actually inline them
534 ###PLATFORM_CFLAGS = -O
537 #### hack for automake to have the same source file in a library and a bin
538 ###genmdesc_CFLAGS = ${AM_CFLAGS)
540 ###if NO_VERSION_SCRIPT
541 ###monoldflags=${export_ldflags)
542 ###monobinldflags=${export_ldflags)
544 ###monoldflags=-Wl,-version-script=${srcdir)/ldscript ${export_ldflags)
545 ###monobinldflags=-Wl,-version-script=${srcdir)/ldscript.mono ${export_ldflags)
549 ###libmono_la_LDFLAGS=-no-undefined -avoid-version -Wl,--kill-at ${monoldflags)
551 ###libmono_la_LDFLAGS=${monoldflags)
557 ###bin_PROGRAMS = mono monow
559 ###bin_PROGRAMS = mono
562 ###noinst_PROGRAMS = genmdesc
564 ###lib_LTLIBRARIES = libmono.la
565 ###noinst_LTLIBRARIES = libmono-static.la
568 ###if DTRACE_G_REQUIRED
569 ###LIBMONO_DTRACE_OBJECT = .libs/mono-dtrace.${OBJEXT)
571 ###MONO_DTRACE_OBJECT = mono-dtrace.${OBJEXT)
573 ###MONO_DTRACE_OBJECT =
576 ###MONO_DTRACE_OBJECT =
577 ###LIBMONO_DTRACE_OBJECT =
581 #### Link libmono into mono statically
582 #### This leads to higher performance, especially with TLS
583 ###MONO_LIB=libmono-static.la
585 ###MONO_LIB=libmono.la
593 ### ${MONO_DTRACE_OBJECT)
596 ### ${static_flags} -export-dynamic ${monobinldflags)
598 ###if DTRACE_G_REQUIRED
600 ###mono-dtrace.${OBJEXT): ${top_srcdir)/data/mono.d mini.lo ${monodir)/mono/metadata/libmonoruntime-static.la
601 ### DTRACE="${DTRACE)" DTRACEFLAGS="${DTRACEFLAGS)" AR="${AR)" ${SHELL} ${top_srcdir)/data/dtrace-prelink.sh \
602 ### $@ ${top_srcdir)/data/mono.d ${monodir)/mono/metadata/libmonoruntime-static.la mini.lo
604 ###.libs/mono-dtrace.${OBJEXT): ${top_srcdir)/data/mono.d mini.lo ${monodir)/mono/metadata/libmonoruntime.la
605 ### DTRACE="${DTRACE)" DTRACEFLAGS="${DTRACEFLAGS)" AR="${AR)" ${SHELL} ${top_srcdir)/data/dtrace-prelink.sh \
606 ### --pic $@ ${top_srcdir)/data/mono.d ${monodir)/mono/metadata/libmonoruntime.la mini.lo
610 #### Create monow.exe, linked for the 'windows' subsystem
612 ###monow_LDADD = ${mono_LDADD)
613 ###monow_LDFLAGS = ${mono_LDFLAGS} -mwindows
614 ###monow_SOURCES = ${mono_SOURCES)
617 #### Don't link this against libmonoruntime to speed up rebuilds
618 ###genmdesc_LDADD = \
619 ### ${monodir)/mono/utils/libmonoutils.la ${monodir)/mono/metadata/opcodes.lo -lm \
623 #### Disabled for now to fix the windows build
626 #### mini-llvm-cpp.cpp
629 ###libmono_static_la_LIBADD = ${static_libs} ${MONO_DTRACE_OBJECT)
631 ###libmonoincludedir = ${includedir)/mono-${API_VER)/mono/jit
633 ###libmonoinclude_HEADERS = jit.h
635 ###libmono_la_LIBADD = \
636 ### ${libs} ${LIBMONO_DTRACE_OBJECT)
639 ### rm -f mono a.out gmon.out *.o buildver.h test.exe
641 ###pkgconfigdir = ${libdir)/pkgconfig
644 ###BUILT_SOURCES = version.h ${arch_built)
646 ###BUILT_SOURCES = version.h
649 ###CLEANFILES= ${BUILT_SOURCES} *.exe *.dll
650 ###EXTRA_DIST = TestDriver.cs ldscript ldscript.mono \
652 ### ${test_sources} \
653 ### ${x86_sources} cpu-x86.md \
654 ### ${amd64_sources} cpu-amd64.md \
655 ### ${ppc_sources} cpu-ppc.md cpu-ppc64.md \
656 ### ${arm_sources} cpu-arm.md \
657 ### ${mips_sources} cpu-mips.md \
658 ### ${sparc_sources} cpu-sparc.md \
659 ### ${s390_sources} cpu-s390.md \
660 ### ${s390x_sources} cpu-s390x.md \
661 ### ${ia64_sources} cpu-ia64.md \
662 ### ${alpha_sources} cpu-alpha.md \
663 ### ${hppa_sources} cpu-hppa.md \
664 ### ${windows_sources) \
665 ### ${darwin_sources) \