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 # Since cmake has no support for convenience libraries, we have to link the
360 # final libmono.a ourselves, similarly to how libtool does it
361 add_custom_target(libmono.a
362 COMMAND rm -rf .libs/tmp libmono.a
363 COMMAND mkdir -p .libs/tmp/{1,2,3,4,5}
364 COMMAND cd .libs/tmp/1 && ar x ../../../../metadata/libmonoruntime-static.a
365 COMMAND cd .libs/tmp/2 && ar x ../../../../utils/libmonoutils-static.a
366 COMMAND cd .libs/tmp/3 && ar x ../../../../io-layer/libwapi-static.a
367 COMMAND cd .libs/tmp/3 && ar x ../../../../mini/libmono-static.a
368 COMMAND cd .libs/tmp/4 && ar x ../../../../../libgc/libmonogc-static.a
369 COMMAND ar r libmono.a `find .libs/tmp/ -name '*.o'`
372 # FIXME: cmake has no support for convenience libraries, so we would end up
373 # creating a lot of shared libraries linking to each other
374 #add_library(libmono SHARED ${libmono_la_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/${arch_built})
375 #set_target_properties(libmono PROPERTIES OUTPUT_NAME "mono")
376 #target_link_libraries(libmono monoruntime monoutils monogc wapi ${GLIB2_LIBRARIES} ${LIBS})
380 # Its a pain to try to pass a complex shell script to add_custom_command (), so
381 # write it to disk instead
382 # " needs to be escaped as \"
383 # \ needs to be escaped as \\
384 set(top_srcdir ../../)
385 file(WRITE create-version.h.sh "
386 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;
387 if test -d ${srcdir}/.svn; then svn_info='svn info'; fi;
388 if test -n \"$svn_info\"; then
391 branch=`$svn_info | grep URL | sed -e 's,.*source/\\(.*\\)/mono.*,/\\1/mono,'`;
392 version=`$svn_info | grep Revision | sed 's/.*: //'`;
393 echo \"#define FULL_VERSION \\\"$branch r$version\\\"\";
396 echo \"#define FULL_VERSION \\\"tarball\\\"\";
400 # FIXME: dependencies ?
402 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.h
403 COMMAND chmod a+x ./create-version.h.sh
404 COMMAND ./create-version.h.sh
410 # We build this after libmono was built so it contains the date when the final
413 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/buildver.h
415 COMMAND sh -c "X='\"'; echo \"const char *build_date = $X`date`$X;\" > ${CMAKE_CURRENT_BINARY_DIR}/buildver.h"
416 DEPENDS libmono-static
419 set_source_files_properties(main.c PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/buildver.h)
420 set_source_files_properties(main.c PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/buildver.h)
424 add_executable(mono main.c ${CMAKE_CURRENT_BINARY_DIR}/buildver.h)
425 add_dependencies(mono libmono-static)
426 target_link_libraries(mono libmono-static ${GLIB2_LIBRARIES})
430 RUNTIME DESTINATION bin)
432 # FIXME: Can't specify a dependency on libmono.a, and we don't want to build
433 # libmono.a until needed
435 FILES libmono.a DESTINATION lib)
439 foreach(test ${test_sources})
440 if (${test} MATCHES ".*\\.cs")
441 string(REPLACE ".cs" ".exe" exe_name ${test})
442 add_cs_exe(${exe_name} ${test} "-r:TestDriver.dll -r:generics-variant-types.dll -r:Mono.Simd.dll" "TestDriver.dll generics-variant-types.dll")
446 set(il_source "iltests.il")
447 set(exe_name "iltests.exe")
450 COMMAND ${ILASM} -output=${exe_name} ${il_source}
453 add_custom_target(${exe_name}-exe DEPENDS ${exe_name})
457 COMMAND echo // DO NOT EDIT: This file has been generated from iltests.il.in > iltests.il
458 COMMAND cpp -Darch=${arch_define} < iltests.il.in | sed "s/^#.*//" >> iltests.il
459 DEPENDS iltests.il.in
463 add_cs_dll("TestDriver.dll" "TestDriver.cs" "-r:System.dll -r:System.dll" "")
465 add_il_target("generics-variant-types.dll" "generics-variant-types.il" "-dll")
469 add_custom_target(rcheck
470 COMMAND ${RUNTIME} --regression ${regtests}
471 DEPENDS mono ${regtests}
474 # FIXME: make runs rcheck, but then says: 'No rule to make target `rcheck', needed by `mono/mini/CMakeFiles/check'
475 #add_custom_target(check
477 add_custom_target(check
478 COMMAND ${RUNTIME} --regression ${regtests}
479 DEPENDS mono ${regtests}
482 add_custom_target(testi
483 COMMAND ${RUNTIME} -v -v --ncompile 1 --compile Test:${mtest} test.exe
484 DEPENDS mono test.exe
487 # ensure the tests are actually correct
488 add_custom_target(checktests
489 COMMAND for i in ${regtests}\; do ${RUNTIME} $$i\; done
493 add_custom_target(aotcheck
494 COMMAND rm -f *.exe.so
495 COMMAND ${RUNTIME} --aot ${regtests} || exit 1
496 COMMAND for i in ${regtests}\; do ${RUNTIME_AOTCHECK} --regression $$i || exit 1\; done
497 COMMAND rm -f *.exe.so
498 DEPENDS mono ${regtests}
501 # This currently only works on amd64/arm
502 add_custom_target(fullaotcheck
503 COMMAND rm -rf fullaot-tmp
504 COMMAND mkdir fullaot-tmp
505 COMMAND cp ${CLASS}/mscorlib.dll ${CLASS}/Mono.Simd.dll ${regtests} generics-variant-types.dll TestDriver.dll fullaot-tmp/
506 COMMAND cp ${regtests} fullaot-tmp/
507 COMMAND MONO_PATH=fullaot-tmp ${top_builddir}/runtime/mono-wrapper --aot=full fullaot-tmp/* || exit 1
508 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
509 DEPENDS mono ${regtests}
512 add_custom_target(bench
513 COMMAND time env ${RUNTIME} --ncompile ${count} --compile Test:${mtest} test.exe
514 DEPENDS mono test.exe
517 add_custom_target(stat1
518 COMMAND ${RUNTIME} --verbose --statfile stats.pl --regression bench.exe
519 COMMAND perl viewstat.pl stats.pl
520 DEPENDS mono bench.exe
523 add_custom_target(stat2
524 COMMAND ${RUNTIME} --verbose --statfile stats.pl --regression basic.exe
525 COMMAND perl viewstat.pl -e stats.pl
526 DEPENDS mono basic.exe
529 add_custom_target(stat3
530 COMMAND ${RUNTIME} --statfile stats.pl --ncompile 1000 --compile Tests:test_0_many_nested_loops bench.exe
531 COMMAND perl viewstat.pl stats.pl
532 DEPENDS mono bench.exe
535 #### This is needed for automake dependency generation
537 ###libgc_libs=${monodir)/libgc/libmonogc.la
538 ###libgc_static_libs=${monodir)/libgc/libmonogc-static.la
540 ###libgc_libs=${LIBGC_LIBS)
541 ###libgc_static_libs=${LIBGC_STATIC_LIBS)
545 ### -I${top_srcdir} \
546 ### ${LIBGC_CFLAGS) \
548 ### ${PLATFORM_CFLAGS} ${ARCH_CFLAGS)
550 ###AM_CXXFLAGS = ${LLVM_CXXFLAGS} ${GLIB_CFLAGS)
554 #### The mingw math.h has "extern inline" functions that dont appear in libs, so
555 #### optimisation is required to actually inline them
556 ###PLATFORM_CFLAGS = -O
559 #### hack for automake to have the same source file in a library and a bin
560 ###genmdesc_CFLAGS = ${AM_CFLAGS)
562 ###if NO_VERSION_SCRIPT
563 ###monoldflags=${export_ldflags)
564 ###monobinldflags=${export_ldflags)
566 ###monoldflags=-Wl,-version-script=${srcdir)/ldscript ${export_ldflags)
567 ###monobinldflags=-Wl,-version-script=${srcdir)/ldscript.mono ${export_ldflags)
571 ###libmono_la_LDFLAGS=-no-undefined -avoid-version -Wl,--kill-at ${monoldflags)
573 ###libmono_la_LDFLAGS=${monoldflags)
579 ###bin_PROGRAMS = mono monow
581 ###bin_PROGRAMS = mono
584 ###noinst_PROGRAMS = genmdesc
586 ###lib_LTLIBRARIES = libmono.la
587 ###noinst_LTLIBRARIES = libmono-static.la
590 ###if DTRACE_G_REQUIRED
591 ###LIBMONO_DTRACE_OBJECT = .libs/mono-dtrace.${OBJEXT)
593 ###MONO_DTRACE_OBJECT = mono-dtrace.${OBJEXT)
595 ###MONO_DTRACE_OBJECT =
598 ###MONO_DTRACE_OBJECT =
599 ###LIBMONO_DTRACE_OBJECT =
603 #### Link libmono into mono statically
604 #### This leads to higher performance, especially with TLS
605 ###MONO_LIB=libmono-static.la
607 ###MONO_LIB=libmono.la
615 ### ${MONO_DTRACE_OBJECT)
618 ### ${static_flags} -export-dynamic ${monobinldflags)
620 ###if DTRACE_G_REQUIRED
622 ###mono-dtrace.${OBJEXT): ${top_srcdir)/data/mono.d mini.lo ${monodir)/mono/metadata/libmonoruntime-static.la
623 ### DTRACE="${DTRACE)" DTRACEFLAGS="${DTRACEFLAGS)" AR="${AR)" ${SHELL} ${top_srcdir)/data/dtrace-prelink.sh \
624 ### $@ ${top_srcdir)/data/mono.d ${monodir)/mono/metadata/libmonoruntime-static.la mini.lo
626 ###.libs/mono-dtrace.${OBJEXT): ${top_srcdir)/data/mono.d mini.lo ${monodir)/mono/metadata/libmonoruntime.la
627 ### DTRACE="${DTRACE)" DTRACEFLAGS="${DTRACEFLAGS)" AR="${AR)" ${SHELL} ${top_srcdir)/data/dtrace-prelink.sh \
628 ### --pic $@ ${top_srcdir)/data/mono.d ${monodir)/mono/metadata/libmonoruntime.la mini.lo
632 #### Create monow.exe, linked for the 'windows' subsystem
634 ###monow_LDADD = ${mono_LDADD)
635 ###monow_LDFLAGS = ${mono_LDFLAGS} -mwindows
636 ###monow_SOURCES = ${mono_SOURCES)
639 #### Don't link this against libmonoruntime to speed up rebuilds
640 ###genmdesc_LDADD = \
641 ### ${monodir)/mono/utils/libmonoutils.la ${monodir)/mono/metadata/opcodes.lo -lm \
645 #### Disabled for now to fix the windows build
648 #### mini-llvm-cpp.cpp
651 ###libmono_static_la_LIBADD = ${static_libs} ${MONO_DTRACE_OBJECT)
653 ###libmonoincludedir = ${includedir)/mono-${API_VER)/mono/jit
655 ###libmonoinclude_HEADERS = jit.h
657 ###libmono_la_LIBADD = \
658 ### ${libs} ${LIBMONO_DTRACE_OBJECT)
661 ### rm -f mono a.out gmon.out *.o buildver.h test.exe
663 ###pkgconfigdir = ${libdir)/pkgconfig
666 ###BUILT_SOURCES = version.h ${arch_built)
668 ###BUILT_SOURCES = version.h
671 ###CLEANFILES= ${BUILT_SOURCES} *.exe *.dll
672 ###EXTRA_DIST = TestDriver.cs ldscript ldscript.mono \
674 ### ${test_sources} \
675 ### ${x86_sources} cpu-x86.md \
676 ### ${amd64_sources} cpu-amd64.md \
677 ### ${ppc_sources} cpu-ppc.md cpu-ppc64.md \
678 ### ${arm_sources} cpu-arm.md \
679 ### ${mips_sources} cpu-mips.md \
680 ### ${sparc_sources} cpu-sparc.md \
681 ### ${s390_sources} cpu-s390.md \
682 ### ${s390x_sources} cpu-s390x.md \
683 ### ${ia64_sources} cpu-ia64.md \
684 ### ${alpha_sources} cpu-alpha.md \
685 ### ${hppa_sources} cpu-hppa.md \
686 ### ${windows_sources) \
687 ### ${darwin_sources) \