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-info32-darwin.s)
206 set(mono_debugger_arch_sources mdb-debug-info64.s)
208 set(mono_debugger_arch_sources mdb-debug-info32.s)
210 enable_language(ASM-ATT)
211 set(mono_debugger_sources debug-debugger.c debug-debugger.h ${mono_debugger_arch_sources})
214 else(MONO_DEBUGGER_SUPPORTED)
215 set(mono_debugger_sources)
216 endif(MONO_DEBUGGER_SUPPORTED)
218 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)
221 set(arch_sources ${x86_sources} ${mono_debugger_sources})
222 set(arch_built cpu-x86.h)
223 set(arch_define __i386__)
227 set(arch_sources ${amd64_sources} ${mono_debugger_sources})
228 set(arch_built cpu-amd64.h)
229 set(arch_define __x86_64__)
233 set(arch_sources ${ppc_sources})
234 set(arch_built cpu-ppc.h)
235 set(arch_define __ppc__)
239 set(arch_sources ${ppc_sources})
240 set(arch_built cpu-ppc64.h)
241 set(arch_define __ppc64__)
245 set(arch_sources ${mips_sources})
246 set(arch_built cpu-mips.h)
247 set(arch_define __mips__)
251 # pick up arm_dpimacros.h and arm_fpamacros.h
252 set(ARCH_CFLAGS -I../arch/arm)
253 set(arch_sources ${arm_sources})
254 set(arch_built cpu-arm.h)
255 set(arch_define __arm__)
259 set(arch_sources ${sparc_sources})
260 set(arch_built cpu-sparc.h)
261 set(arch_define __sparc__)
265 set(arch_sources ${sparc_sources})
266 set(arch_built cpu-sparc.h)
267 set(arch_define __sparc__)
271 set(arch_sources ${s390_sources})
272 set(arch_built cpu-s390.h)
273 set(arch_define __s390__)
277 set(arch_sources ${s390x_sources})
278 set(arch_built cpu-s390x.h)
279 set(arch_define __s390__)
283 set(arch_sources ${ia64_sources})
284 set(arch_built cpu-ia64.h)
285 set(arch_define __ia64__)
289 set(arch_sources ${alpha_sources} ${mono_debugger_sources})
290 set(arch_built cpu-alpha.h)
291 set(arch_define __alpha__)
295 # Only support 32-bit targets for now
296 set(arch_sources ${hppa_sources})
297 set(arch_built cpu-hppa.h)
298 set(arch_define __hppa__)
302 set(os_sources ${windows_sources})
303 set(monobin_platform_ldflags)
306 if(PLATFORM_SIGPOSIX)
307 set(os_sources ${posix_sources})
308 set(monobin_platform_ldflags)
312 set(os_sources ${darwin_sources} ${posix_sources})
313 set(monobin_platform_ldflags "-sectcreate __TEXT __info_plist ${top_srcdir}/mono/mini/Info.plist")
316 #### we don't always use the perl impl because it's an additional
317 #### build dependency for the poor windows users
318 #### ${arch_define} is the preprocessor symbol that enables all the opcodes
319 #### for the specific platform in mini-ops.h
320 ###if CROSS_COMPILING
321 ###GENMDESC_PRG=perl ${srcdir)/genmdesc.pl ${arch_define} ${srcdir)
322 ###else !CROSS_COMPILING
323 set(GENMDESC_PRG ${CMAKE_CURRENT_BINARY_DIR}/genmdesc)
324 ###endif !CROSS_COMPILING
326 function(add_genmdesc_target target source define)
328 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}
329 COMMAND ${GENMDESC_PRG} ${CMAKE_CURRENT_BINARY_DIR}/${target} ${define} ${source}
330 DEPENDS genmdesc ${source}
334 foreach(arch x86 amd64 sparc ia64 alpha hppa mips)
335 add_genmdesc_target(cpu-${arch}.h cpu-${arch}.md ${arch}_desc)
338 add_genmdesc_target(cpu-ppc.h cpu-ppc.md ppcg4)
339 add_genmdesc_target(cpu-ppc64.h cpu-ppc64.md ppc64_cpu_desc)
340 add_genmdesc_target(cpu-arm.h cpu-arm.md arm_cpu_desc)
341 add_genmdesc_target(cpu-s390.h cpu-s390.md s390_cpu_desc)
342 add_genmdesc_target(cpu-s390x.h cpu-s390x.md s390x_cpu_desc)
344 include_directories(../..)
345 include_directories(${GLIB2_INCLUDE_DIRS})
346 include_directories(${LIBGC_INCLUDE_DIRS})
348 link_directories(../../libgc/.libs)
349 set(CMAKE_C_FLAGS "${CFLAGS} ${LIBGC_CFLAGS} ${CPPFLAGS}")
352 add_executable(genmdesc genmdesc.c helpers.c)
353 target_link_libraries(genmdesc monoutils-static monoruntime-static ${GLIB2_LIBRARIES})
357 set(libmono_la_SOURCES ${common_sources} ${llvm_sources} ${arch_sources} ${os_sources})
359 # FIXME: cmake doesn't seem to recognize the ${arch_built} dependency
360 add_library(libmono-static STATIC ${libmono_la_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/${arch_built})
361 target_link_libraries(libmono-static monoruntime-static monoutils-static monogc-static wapi-static ${GLIB2_LIBRARIES} ${LIBS})
362 set_target_properties(libmono-static PROPERTIES OUTPUT_NAME "mono-static")
364 # Since cmake has no support for convenience libraries, we have to link the
365 # final libmono.a ourselves, similarly to how libtool does it
366 add_custom_target(libmono.a
367 COMMAND rm -rf .libs/tmp libmono.a
368 COMMAND mkdir -p .libs/tmp/{1,2,3,4,5}
369 COMMAND cd .libs/tmp/1 && ar x ../../../../metadata/libmonoruntime-static.a
370 COMMAND cd .libs/tmp/2 && ar x ../../../../utils/libmonoutils-static.a
371 COMMAND cd .libs/tmp/3 && ar x ../../../../io-layer/libwapi-static.a
372 COMMAND cd .libs/tmp/3 && ar x ../../../../mini/libmono-static.a
373 COMMAND cd .libs/tmp/4 && ar x ../../../../../libgc/libmonogc-static.a
374 COMMAND ar r libmono.a `find .libs/tmp/ -name '*.o'`
377 # FIXME: cmake has no support for convenience libraries, so we would end up
378 # creating a lot of shared libraries linking to each other
379 #add_library(libmono SHARED ${libmono_la_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/${arch_built})
380 #set_target_properties(libmono PROPERTIES OUTPUT_NAME "mono")
381 #target_link_libraries(libmono monoruntime monoutils monogc wapi ${GLIB2_LIBRARIES} ${LIBS})
385 # Its a pain to try to pass a complex shell script to add_custom_command (), so
386 # write it to disk instead
387 # " needs to be escaped as \"
388 # \ needs to be escaped as \\
389 set(top_srcdir ../../)
390 file(WRITE create-version.h.sh "
391 if test -d ${top_srcdir}/.git/svn; then svn_info=\"git log --no-color --first-parent -n1 --grep=git-svn-id: --pretty=format:%b | sed -n -e 's,git-svn-id: \\(.*\\)@\\(.*\\) .*,URL: \\1 Revision: \\2,p'\"; fi;
392 if test -d ${srcdir}/.svn; then svn_info='svn info'; fi;
393 if test -n \"$svn_info\"; then
396 branch=`eval $$svn_info | sed -n -e '/URL/ s,.*source/\\(.*\\)/mono.*,/\\1/mono,p'`;
397 version=`eval $$svn_info | sed -n -e '/Revision/ s/.*: //p'`;
398 echo \"#define FULL_VERSION \\\"$branch r$version\\\"\";
401 echo \"#define FULL_VERSION \\\"tarball\\\"\";
405 # FIXME: dependencies ?
407 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.h
408 COMMAND chmod a+x ./create-version.h.sh
409 COMMAND ./create-version.h.sh
415 # We build this after libmono was built so it contains the date when the final
418 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/buildver.h
420 COMMAND sh -c "X='\"'; echo \"const char *build_date = $X`date`$X;\" > ${CMAKE_CURRENT_BINARY_DIR}/buildver.h"
421 DEPENDS libmono-static
424 set_source_files_properties(main.c PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/buildver.h)
425 set_source_files_properties(main.c PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/buildver.h)
429 add_executable(mono main.c ${CMAKE_CURRENT_BINARY_DIR}/buildver.h)
430 add_dependencies(mono libmono-static)
431 target_link_libraries(mono libmono-static ${GLIB2_LIBRARIES})
435 RUNTIME DESTINATION bin)
437 # FIXME: Can't specify a dependency on libmono.a, and we don't want to build
438 # libmono.a until needed
440 FILES libmono.a DESTINATION lib)
444 foreach(test ${test_sources})
445 if (${test} MATCHES ".*\\.cs")
446 string(REPLACE ".cs" ".exe" exe_name ${test})
447 add_cs_exe(${exe_name} ${test} "-r:TestDriver.dll -r:generics-variant-types.dll -r:Mono.Simd.dll" "TestDriver.dll generics-variant-types.dll")
451 set(il_source "iltests.il")
452 set(exe_name "iltests.exe")
455 COMMAND ${ILASM} -output=${exe_name} ${il_source}
458 add_custom_target(${exe_name}-exe DEPENDS ${exe_name})
462 COMMAND echo // DO NOT EDIT: This file has been generated from iltests.il.in > iltests.il
463 COMMAND cpp -Darch=${arch_define} < iltests.il.in | sed "s/^#.*//" >> iltests.il
464 DEPENDS iltests.il.in
468 add_cs_dll("TestDriver.dll" "TestDriver.cs" "-r:System.dll -r:System.dll" "")
470 add_il_target("generics-variant-types.dll" "generics-variant-types.il" "-dll")
474 add_custom_target(rcheck
475 COMMAND ${RUNTIME} --regression ${regtests}
476 DEPENDS mono ${regtests}
479 # FIXME: make runs rcheck, but then says: 'No rule to make target `rcheck', needed by `mono/mini/CMakeFiles/check'
480 #add_custom_target(check
482 add_custom_target(check
483 COMMAND ${RUNTIME} --regression ${regtests}
484 DEPENDS mono ${regtests}
487 add_custom_target(testi
488 COMMAND ${RUNTIME} -v -v --ncompile 1 --compile Test:${mtest} test.exe
489 DEPENDS mono test.exe
492 # ensure the tests are actually correct
493 add_custom_target(checktests
494 COMMAND for i in ${regtests}\; do ${RUNTIME} $$i\; done
498 add_custom_target(aotcheck
499 COMMAND rm -f *.exe.so
500 COMMAND ${RUNTIME} --aot ${regtests} || exit 1
501 COMMAND for i in ${regtests}\; do ${RUNTIME_AOTCHECK} --regression $$i || exit 1\; done
502 COMMAND rm -f *.exe.so
503 DEPENDS mono ${regtests}
506 # This currently only works on amd64/arm
507 add_custom_target(fullaotcheck
508 COMMAND rm -rf fullaot-tmp
509 COMMAND mkdir fullaot-tmp
510 COMMAND cp ${CLASS}/mscorlib.dll ${CLASS}/System.Core.dll ${CLASS}/System.dll ${CLASS}/Mono.Posix.dll ${CLASS}/System.Configuration.dll ${CLASS}/System.Security.dll ${CLASS}/System.Xml.dll ${CLASS}/Mono.Security.dll ${CLASS}/Mono.Simd.dll ${regtests} generics-variant-types.dll TestDriver.dll fullaot-tmp/
511 COMMAND cp ${regtests} fullaot-tmp/
512 COMMAND MONO_PATH=fullaot-tmp ${top_builddir}/runtime/mono-wrapper --aot=full fullaot-tmp/* || exit 1
513 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
514 DEPENDS mono ${regtests}
517 add_custom_target(bench
518 COMMAND time env ${RUNTIME} --ncompile ${count} --compile Test:${mtest} test.exe
519 DEPENDS mono test.exe
522 add_custom_target(stat1
523 COMMAND ${RUNTIME} --verbose --statfile stats.pl --regression bench.exe
524 COMMAND perl viewstat.pl stats.pl
525 DEPENDS mono bench.exe
528 add_custom_target(stat2
529 COMMAND ${RUNTIME} --verbose --statfile stats.pl --regression basic.exe
530 COMMAND perl viewstat.pl -e stats.pl
531 DEPENDS mono basic.exe
534 add_custom_target(stat3
535 COMMAND ${RUNTIME} --statfile stats.pl --ncompile 1000 --compile Tests:test_0_many_nested_loops bench.exe
536 COMMAND perl viewstat.pl stats.pl
537 DEPENDS mono bench.exe
540 #### This is needed for automake dependency generation
542 ###libgc_libs=${monodir)/libgc/libmonogc.la
543 ###libgc_static_libs=${monodir)/libgc/libmonogc-static.la
545 ###libgc_libs=${LIBGC_LIBS)
546 ###libgc_static_libs=${LIBGC_STATIC_LIBS)
550 ### -I${top_srcdir} \
551 ### ${LIBGC_CFLAGS) \
553 ### ${PLATFORM_CFLAGS} ${ARCH_CFLAGS)
555 ###AM_CXXFLAGS = ${LLVM_CXXFLAGS} ${GLIB_CFLAGS)
559 #### The mingw math.h has "extern inline" functions that dont appear in libs, so
560 #### optimisation is required to actually inline them
561 ###PLATFORM_CFLAGS = -O
564 #### hack for automake to have the same source file in a library and a bin
565 ###genmdesc_CFLAGS = ${AM_CFLAGS)
567 ###if NO_VERSION_SCRIPT
568 ###monoldflags=${export_ldflags)
569 ###monobinldflags=${export_ldflags)
571 ###monoldflags=-Wl,-version-script=${srcdir)/ldscript ${export_ldflags)
572 ###monobinldflags=-Wl,-version-script=${srcdir)/ldscript.mono ${export_ldflags)
576 ###libmono_la_LDFLAGS=-no-undefined -avoid-version -Wl,--kill-at ${monoldflags)
578 ###libmono_la_LDFLAGS=${monoldflags)
584 ###bin_PROGRAMS = mono monow
586 ###bin_PROGRAMS = mono
589 ###noinst_PROGRAMS = genmdesc
591 ###lib_LTLIBRARIES = libmono.la
592 ###noinst_LTLIBRARIES = libmono-static.la
595 ###if DTRACE_G_REQUIRED
596 ###LIBMONO_DTRACE_OBJECT = .libs/mono-dtrace.${OBJEXT)
598 ###MONO_DTRACE_OBJECT = mono-dtrace.${OBJEXT)
600 ###MONO_DTRACE_OBJECT =
603 ###MONO_DTRACE_OBJECT =
604 ###LIBMONO_DTRACE_OBJECT =
608 #### Link libmono into mono statically
609 #### This leads to higher performance, especially with TLS
610 ###MONO_LIB=libmono-static.la
612 ###MONO_LIB=libmono.la
620 ### ${MONO_DTRACE_OBJECT) \
624 ### ${static_flags} -export-dynamic ${monobinldflags) ${monobin_platform_ldflags}
626 ###if DTRACE_G_REQUIRED
628 ###mono-dtrace.${OBJEXT): ${top_srcdir)/data/mono.d mini.lo ${monodir)/mono/metadata/libmonoruntime-static.la
629 ### DTRACE="${DTRACE)" DTRACEFLAGS="${DTRACEFLAGS)" AR="${AR)" ${SHELL} ${top_srcdir)/data/dtrace-prelink.sh \
630 ### $@ ${top_srcdir)/data/mono.d ${monodir)/mono/metadata/libmonoruntime-static.la mini.lo
632 ###.libs/mono-dtrace.${OBJEXT): ${top_srcdir)/data/mono.d mini.lo ${monodir)/mono/metadata/libmonoruntime.la
633 ### DTRACE="${DTRACE)" DTRACEFLAGS="${DTRACEFLAGS)" AR="${AR)" ${SHELL} ${top_srcdir)/data/dtrace-prelink.sh \
634 ### --pic $@ ${top_srcdir)/data/mono.d ${monodir)/mono/metadata/libmonoruntime.la mini.lo
638 #### Create monow.exe, linked for the 'windows' subsystem
640 ###monow_LDADD = ${mono_LDADD)
641 ###monow_LDFLAGS = ${mono_LDFLAGS} -mwindows
642 ###monow_SOURCES = ${mono_SOURCES)
645 #### Don't link this against libmonoruntime to speed up rebuilds
646 ###genmdesc_LDADD = \
647 ### ${monodir)/mono/utils/libmonoutils.la ${monodir)/mono/metadata/opcodes.lo -lm \
651 #### Disabled for now to fix the windows build
654 #### mini-llvm-cpp.cpp
657 ###libmono_static_la_LIBADD = ${static_libs} ${MONO_DTRACE_OBJECT)
659 ###libmonoincludedir = ${includedir)/mono-${API_VER)/mono/jit
661 ###libmonoinclude_HEADERS = jit.h
663 ###libmono_la_LIBADD = \
664 ### ${libs} ${LIBMONO_DTRACE_OBJECT)
667 ### rm -f mono a.out gmon.out *.o buildver.h test.exe
669 ###pkgconfigdir = ${libdir)/pkgconfig
672 ###BUILT_SOURCES = version.h ${arch_built)
674 ###BUILT_SOURCES = version.h
677 ###CLEANFILES= ${BUILT_SOURCES} *.exe *.dll
678 ###EXTRA_DIST = TestDriver.cs ldscript ldscript.mono \
680 ### ${test_sources} \
681 ### ${x86_sources} cpu-x86.md \
682 ### ${amd64_sources} cpu-amd64.md \
683 ### ${ppc_sources} cpu-ppc.md cpu-ppc64.md \
684 ### ${arm_sources} cpu-arm.md \
685 ### ${mips_sources} cpu-mips.md \
686 ### ${sparc_sources} cpu-sparc.md \
687 ### ${s390_sources} cpu-s390.md \
688 ### ${s390x_sources} cpu-s390x.md \
689 ### ${ia64_sources} cpu-ia64.md \
690 ### ${alpha_sources} cpu-alpha.md \
691 ### ${hppa_sources} cpu-hppa.md \
692 ### ${windows_sources) \
693 ### ${darwin_sources) Info.plist \