2009-07-13 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / CMakeLists.txt
index a22d33d2f5a21a261cefd1eda3c4c7c582b4579e..83319a16445c77e745dfae4aaa0640a974203aad 100644 (file)
@@ -5,6 +5,7 @@ cmake_minimum_required(VERSION 2.6.4)
 # - It would be nice to have a per-target VERBOSE setting
 # - or a way to change the setting name to 'V' and the output to CC <src>
 #   to be similar to the current build output
+# - Add a cache to the manual checks
 
 # We use lowercase commands as advocated by the kde cmake coding style
 
@@ -134,10 +135,9 @@ endfunction()
 # need to be ported to cmake
 # The svn revision of the configure.in used is r132691
 
-ac_define_unquoted(VERSION 2.5 "Version number of package")
-###
-###set(API_VER 1.0)
-###AC_SUBST(API_VER)
+set(VERSION 2.5)
+ac_define_unquoted(VERSION ${VERSION} "Version number of package")
+set(API_VER 1.0)
 ###
 ###AC_PROG_LN_S
 ###
@@ -498,19 +498,22 @@ check_c_source_compiles("
 void main () {}
 " GCC)
 
-ac_msg_checking("for isinf")
-set(compiles)
-check_c_source_compiles("
+if(NOT HAVE_ISINF)
+  ac_msg_checking("for isinf")
+  set(compiles)
+  check_c_source_compiles("
 #include <math.h>
 void main () {
 int f = isinf (1);
 }
 " compiles)
-if(compiles)
-  ac_msg_result(yes)
-  ac_define(HAVE_ISINF 1 "isinf available")
-else()
-  ac_msg_result(no)
+  if(compiles)
+       ac_msg_result(yes)
+       ac_define(HAVE_ISINF 1 "isinf available")
+       set(HAVE_ISINF 1 CACHE BOOL "Have the isinf function")
+  else()
+       ac_msg_result(no)
+  endif()
 endif()
 
 # not 64 bit clean in cross-compile
@@ -544,6 +547,7 @@ set(CFLAGS "${CFLAGS} -g ${WARN}")
 
 set(srcdir ${CMAKE_SOURCE_DIR})
 set(top_srcdir ${CMAKE_SOURCE_DIR})
+set(abs_top_srcdir ${top_srcdir})
 
 # FIXME:
 set(top_builddir ${CMAKE_BINARY_DIR})
@@ -559,12 +563,16 @@ endif()
 # A sanity check to catch cases where the package was unpacked
 # with an ancient tar program (Solaris)
 #
-ac_msg_checking("integrity of package")
-if(EXISTS ${srcdir}/${mcsdir}/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapTypeMapper.cs)
-  ac_msg_result(ok)
-else()
-  set(errorm "Your mono distribution is incomplete;  if unpacking from a tar file, make sure you use GNU tar;  see http://www.mono-project.com/IncompletePackage for more details")
-  ac_msg_error(${errorm})
+set(solaris-tar-check yes CACHE BOOL "Enable/disable solaris tar check")
+
+if(solaris-tar-check)
+  ac_msg_checking("integrity of package")
+  if(EXISTS ${srcdir}/${mcsdir}/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapTypeMapper.cs)
+       ac_msg_result(ok)
+  else()
+       set(errorm "Your mono distribution is incomplete;  if unpacking from a tar file, make sure you use GNU tar;  see http://www.mono-project.com/IncompletePackage for more details")
+       ac_msg_error(${errorm})
+  endif()
 endif()
 
 set(mcs_topdir ${top_srcdir}/${mcsdir})
@@ -732,6 +740,7 @@ set(with_static_mono ${static_mono})
 if(with_static_mono)
   set(STATIC_MONO yes)
 endif()
+set(enable_mcs_build yes)
 ###AC_ARG_ENABLE(mcs-build, [  --disable-mcs-build disable the build of the mcs directory], set(try_mcs_build $enableval, enable_mcs_build=yes))
 ###
 ###set(xen_opt,   [  --with-set(xen_opt yes,no          Enable Xen-specific behaviour (defaults to yes)],[],[with_xen_opt=yes]))
@@ -2098,6 +2107,32 @@ if(host MATCHES "(x86_64-.*-.*)|(amd64-.*-.*)")
   set(arch_target amd64)
   set(JIT_SUPPORTED yes)
   set(jit_wanted true)
+elseif(host MATCHES "arm.*-linux.*")
+  set(TARGET ARM)
+  set(arch_target arm)
+  set(ACCESS_UNALIGNED no)
+  set(JIT_SUPPORTED yes)
+  set(jit_wanted true)
+elseif(host MATCHES "mips.*")
+  set(TARGET MIPS)
+  set(arch_target mips)
+  set(ACCESS_UNALIGNED no)
+  set(JIT_SUPPORTED yes)
+  set(jit_wanted true)
+###            ac_msg_checking(for mips n32)
+###            AC_TRY_COMPILE([], [
+###            void main () {
+###            #if _MIPS_SIM != _ABIN32
+###            #error Not mips n32
+###            #endif
+###            }
+###            ],[
+###            ac_msg_result(yes)
+###            set(sizeof_register 8)
+###            ],[
+###            ac_msg_result(no)
+###            ])
+###            ;;
 else()
   message(FATAL_ERROR "Host ${host} not yet supported by the cmake build.")
 endif()
@@ -2116,27 +2151,6 @@ endif()
 #              set(TARGET MIPS;)
 #              set(ACCESS_UNALIGNED "no")
 #              ;;
-###    mips*)
-###            set(TARGET MIPS;)
-###            set(arch_target mips;)
-###            set(ACCESS_UNALIGNED "no")
-###            set(JIT_SUPPORTED yes)
-###            set(jit_wanted true)
-
-###            ac_msg_checking(for mips n32)
-###            AC_TRY_COMPILE([], [
-###            void main () {
-###            #if _MIPS_SIM != _ABIN32
-###            #error Not mips n32
-###            #endif
-###            }
-###            ],[
-###            ac_msg_result(yes)
-###            set(sizeof_register 8)
-###            ],[
-###            ac_msg_result(no)
-###            ])
-###            ;;
 ###    i*86-*-*)
 ###            set(TARGET X86;)
 ###            set(arch_target x86;)
@@ -2257,13 +2271,6 @@ endif()
 ###            set(CPPFLAGS "$CPPFLAGS -DARM_FPU_NONE=1")
 ###            set(jit_wanted true)
 ###            ;;
-###    arm*-linux*)
-###            set(TARGET ARM;)
-###            set(arch_target arm;)
-###            set(ACCESS_UNALIGNED "no")
-###            set(JIT_SUPPORTED yes)
-###            set(jit_wanted true)
-###            ;;
 ###    s390-*-linux*)
 ###            set(TARGET S390;)
 ###            ac_define(MONO_ARCH_REGPARMS,1,[Architecture uses registers for Parameters])
@@ -2420,7 +2427,7 @@ if (with_tls STREQUAL "__thread")
   ac_define(HAVE_KW_THREAD 1 "Have __thread keyword")
   ac_define(USE_COMPILER_TLS 1 "Use __thread for TLS access")
 # Pass the information to libgc
-###    set(CPPFLAGS "$CPPFLAGS -DUSE_COMPILER_TLS")
+set(CPPFLAGS "${CPPFLAGS} -DUSE_COMPILER_TLS")
 ###    ac_msg_checking(if the tls_model attribute is supported)
 ###    AC_TRY_COMPILE([static __thread int foo __attribute__((tls_model("initial-exec")));], [
 ###            ], [
@@ -2432,20 +2439,38 @@ if (with_tls STREQUAL "__thread")
 ###fi
 
 endif()
-###if test ${TARGET} = ARM && test x$cross_compiling = xno && test x$enable_mcs_build != xno; then
+
 # ******************************************
 # *** Check to see what FPU is available ***
 # ******************************************
-###    ac_msg_checking(which FPU to use)
-
-###    AC_TRY_COMPILE([], [
-###            __asm__ ("ldfd f0, [r0]");
-###            ], set(fpu FPA, fpu=NONE))
-
-###    ac_msg_result($fpu)
-###    set(CPPFLAGS "$CPPFLAGS -DARM_FPU_$fpu=1")
-###    unset fpu
-###fi
+# FIXME: Don't do this if cross-compiling
+if(${TARGET} STREQUAL "ARM")
+  ac_msg_checking("which FPU to use")
+  set(CMAKE_REQUIRED_FLAGS "-mfloat-abi=softfp -mfpu=vfp")
+  set(compiles_fpu_vfp)
+  check_c_source_compiles("
+void main () {
+               __asm__ (\"faddd   d7, d6, d7\");
+}
+" compiles_fpu_vfp)
+  set(compiles_fpu_fpa)
+  set(cmake_required_flags)
+  check_c_source_compiles("
+void main () {
+               __asm__ (\"ldfd f0, [r0]\");
+}
+" compiles_fpu_fpa)
+  if(compiles_fpu_vfp)
+       set(fpu VFP)
+  elseif(compiles_fpu_fpa)
+       set(fpu FPA)
+  else()
+       set(fpu NONE)
+  endif()
+  ac_msg_result(${fpu})
+  set(CPPFLAGS "${CPPFLAGS} -DARM_FPU_${fpu}=1")
+  set(fpu)
+endif()
 
 if(${TARGET} STREQUAL "unknown")
        set(CPPFLAGS ${CPPFLAGS} -DNO_PORT)
@@ -2453,7 +2478,7 @@ if(${TARGET} STREQUAL "unknown")
 endif()
 
 if(NOT ACCESS_UNALIGNED)
-  set(CPPFLAGS ${CPPFLAGS} -DNO_UNALIGNED_ACCESS)
+  set(CPPFLAGS "${CPPFLAGS} -DNO_UNALIGNED_ACCESS")
 endif()
 
 ###case "x$gc" in
@@ -2514,7 +2539,11 @@ endif()
 ###AC_SUBST(OPROFILE_CFLAGS)
 ###AC_SUBST(OPROFILE_LIBS)
 
-###set(libmono_ldflags "$libmono_ldflags $LIBS")
+set(libs_list)
+foreach(lib ${LIBS})
+  set(libs_list "${libs_list} ${lib}")
+endforeach()
+set(libmono_ldflags "${libmono_ldflags} ${libs_list}")
 
 if(PREVIEW)
   set(INSTALL_2_0 yes)
@@ -2650,6 +2679,37 @@ execute_process (COMMAND chmod a+x runtime/mono-wrapper runtime/monodis-wrapper)
 ###   AC_CONFIG_COMMANDS([quiet-libtool], [sed -e 's/$echo "copying selected/$show "copying selected/g' < libtool > libtool.tmp && mv libtool.tmp libtool && chmod a+x libtool; sed -e 's/$ECHO "copying selected/# "copying selected/g' < libtool > libtool.tmp && mv libtool.tmp libtool && chmod a+x libtool])
 ###fi
 
+if("${prefix}" STREQUAL "")
+  set(prefix /usr/local)
+endif()
+if("${exec_prefix}" STREQUAL "")
+  set(exec_prefix "\${prefix}")
+  set(exec_prefix_full "${prefix}")
+else()
+  set(exec_prefix_full "${exec_prefix}")
+endif()
+
+# FIXME: Make these overridable
+set(bindir "\${exec_prefix}/bin")
+set(bindir_full "${exec_prefix_full}/bin")
+set(sbindir "\${exec_prefix}/sbin")
+set(libexecdir "\${exec_prefix}/libexec")
+set(datarootdir "\${prefix}/share")
+set(datadir "\${datarootdir}")
+set(sysconfdir "\${prefix}/etc")
+set(sharedstatedir "\${prefix}/com")
+set(localstatedir "\${prefix}/var")
+set(includedir "\${prefix}/include")
+set(oldincludedir "/usr/include")
+set(docdir "\${datarootdir}/doc/\${PACKAGE}")
+set(infodir "\${datarootdir}/info")
+set(htmldir "\${docdir}")
+set(dvidir "\${docdir}")
+set(pdfdir "\${docdir}")
+set(psdir "\${docdir}")
+set(libdir "\${exec_prefix}/lib")
+set(localedir "\${datarootdir}/locale")
+set(mandir "\${datarootdir}/man")
 
 autoheader("config.h" autoheader_vars)
 
@@ -2659,13 +2719,40 @@ foreach(dir ${SUBDIRS})
   add_subdirectory(${dir})
 endforeach()
 
+# Implementation of AC_OUTPUT for cmake
+function(ac_output outputs)
+  foreach (output ${ARGV})
+       configure_file ("${output}.in" "${output}" @ONLY)
+  endforeach()
+endfunction()
+
+ac_output(
+mono-uninstalled.pc
+scripts/mono-find-provides
+scripts/mono-find-requires
+mono/tests/tests-config
+data/mint.pc
+data/mono.pc
+data/mono-cairo.pc
+data/mono-nunit.pc
+data/mono-options.pc
+data/mono-lineeditor.pc
+data/monodoc.pc
+data/mono.web.pc
+data/dotnet.pc
+data/dotnet35.pc
+data/wcf.pc
+data/cecil.pc
+data/system.web.extensions_1.0.pc
+data/system.web.extensions.design_1.0.pc
+data/system.web.mvc.pc
+data/config
+)
+
 ###AC_OUTPUT([
 ###mono-uninstalled.pc
 ###scripts/mono-find-provides
 ###scripts/mono-find-requires
-###mono/Makefile
-###mono/utils/Makefile
-###mono/metadata/Makefile
 ###mono/dis/Makefile
 ###mono/cil/Makefile
 ###mono/arch/Makefile
@@ -2692,8 +2779,6 @@ endforeach()
 ###mono/tests/cas/threads/Makefile
 ###mono/benchmark/Makefile
 ###mono/monograph/Makefile
-###mono/io-layer/Makefile
-###mono/mini/Makefile
 ###mono/profiler/Makefile
 ###ikvm-native/Makefile
 ###scripts/Makefile
@@ -2738,56 +2823,51 @@ endforeach()
 ###   sed -e "s,-mno-cygwin,,g" libtool > libtool.new; mv libtool.new libtool; chmod 755 libtool
 ###fi
 
-###(
-###  case $prefix in
-###  NONE) set(prefix $ac_default_prefix ;;)
-###  esac
-###  case $exec_prefix in
-###  NONE) set(exec_prefix '${prefix}' ;;)
-###  esac
-
-###  test -w $srcdir/$mcsdir/build || chmod +w $srcdir/$mcsdir/build
-
-###  #
-###  # If we are cross compiling, we don't build in the mcs/ tree.  Let us not clobber
-###  # any existing config.make.  This allows people to share the same source tree
-###  # with different build directories, one native and one cross
-###  #
-###  if test x$cross_compiling = xno && test x$enable_mcs_build != xno; then
-###    echo "set(prefix $prefix" > $srcdir/$mcsdir/build/config.make)
-###    echo "set(exec_prefix $exec_prefix" >> $srcdir/$mcsdir/build/config.make)
-###    echo "set(sysconfdir $sysconfdir" >> $srcdir/$mcsdir/build/config.make)
-###    echo 'set(mono_libdir ${exec_prefix}/lib' >> $srcdir/$mcsdir/build/config.make)
-###    echo 'MCS_FLAGS = $(PLATFORM_DEBUG_FLAGS)' >> $srcdir/$mcsdir/build/config.make
-###    echo 'IL_FLAGS = /debug' >> $srcdir/$mcsdir/build/config.make
-###    echo "RUNTIME = $mono_build_root/runtime/mono-wrapper" >> $srcdir/$mcsdir/build/config.make
-###    echo "ILDISASM = $mono_build_root/runtime/monodis-wrapper" >> $srcdir/$mcsdir/build/config.make
+# FIXME:
+set(mcs_INSTALL ${mono_build_root}/install-sh)
+
 ###    case $INSTALL in
 ###    [[\\/$]]* | ?:[[\\/]]* ) set(mcs_INSTALL $INSTALL ;;)
 ###    *) set(mcs_INSTALL $mono_build_root/$INSTALL ;;)
 ###    esac
 
-###    echo "INSTALL = $mcs_INSTALL" >> $srcdir/$mcsdir/build/config.make
+# Compute a 4 part version number into myver from ${mono_version}
+string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\1.\\2.\\3.\\4" myver "${mono_version}.0.0.0")
 
-###    export VERSION
-###    [set(myver $($AWK 'BEGIN {)
-###      split (ENVIRON["VERSION"] ".0.0.0", vsplit, ".")
-###      if(length(vsplit [1]) > 4) {
-###        split (substr(ENVIRON["VERSION"], 0, 4) "." substr(ENVIRON["VERSION"], 5) ".0.0", vsplit, ".")
-###      }
-###      print vsplit [1] "." vsplit [2] "." vsplit [3] "." vsplit [4]
-###    }')]
+set(config.make ${srcdir}/${mcsdir}/build/config.make)
+#
+# If we are cross compiling, we don't build in the mcs/ tree.  Let us not clobber
+# any existing config.make.  This allows people to share the same source tree
+# with different build directories, one native and one cross
+#
+if(NOT cross_compiling)
+  set(not_cross_compiling yes)
+endif()
+if(not_cross_compiling AND enable_mcs_build)
+  file(WRITE ${config.make} "prefix=${prefix}
+exec_prefix=${exec_prefix}
+sysconfdir=${sysconfdir}
+mono_libdir=\${exec_prefix}/lib
+MCS_FLAGS=$(PLATFORM_DEBUG_FLAGS)
+IL_FLAGS=/debug
+RUNTIME=${mono_build_root}/runtime/mono-wrapper
+ILDISASM=${mono_build_root}/runtime/monodis-wrapper
+INSTALL=${mcs_INSTALL}
+MONO_VERSION=${myver}
+")
+endif()
 
-###    echo "MONO_VERSION = $myver" >> $srcdir/$mcsdir/build/config.make
-###  fi
+if(platform_darwin)
+  file(APPEND ${config.make} "PLATFORM=darwin\n")
+endif()
 
-###  if test x$platform_darwin = xyes; then
-###    echo "PLATFORM = darwin" >> $srcdir/$mcsdir/build/config.make
-###  fi
+if (${TARGET} STREQUAL "AMD64" AND ${platform_win32} STREQUAL "no" AND AOT_SUPPORTED)
+  file(APPEND ${config.make} "ENABLE_AOT=1\n")
+endif()
 
-###  if test x$TARGET = xAMD64 -a x$platform_win32 = xno -a "x$AOT_SUPPORTED" = "xyes"; then
-###     echo "ENABLE_AOT = 1" >> $srcdir/$mcsdir/build/config.make
-###  fi
+if (DISABLE_MCS_DOCS)
+  file(APPEND ${config.make} "DISABLE_MCS_DOCS=yes\n")
+endif()
 
 ###  # if we have an olive folder, override the default settings
 ###  if test -d $olivedir; then
@@ -2807,11 +2887,6 @@ endforeach()
 ###    fi
 ###  fi
 
-###  if test x$DISABLE_MCS_DOCS = xyes; then
-###    echo "DISABLE_MCS_DOCS = yes" >> $srcdir/$mcsdir/build/config.make
-###  fi
-###)
-
 if(NOT libgdiplus_loc)
   set(libgdiplus_msg "assumed to be installed")
 else()