]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
CMake: Add crosscompilation support
authormaier <maier@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 30 Mar 2013 17:10:00 +0000 (17:10 +0000)
committermaier <maier@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 30 Mar 2013 17:10:00 +0000 (17:10 +0000)
git-svn-id: https://svn.dealii.org/trunk@29118 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/cmake/TODO.CMAKE
deal.II/cmake/checks/check_01_compiler_features.cmake
deal.II/cmake/checks/check_01_cxx_features.cmake
deal.II/cmake/macros/macro_expand_instantiations.cmake
deal.II/cmake/scripts/CMakeLists.txt
deal.II/cmake/setup_cached_variables.cmake
deal.II/cmake/setup_deal_ii.cmake
deal.II/cmake/setup_finalize.cmake
deal.II/doc/development/Toolchain.sample [new file with mode: 0644]
deal.II/doc/development/porting.html

index 06979ce6c846275c3f196c7434a8ec830dfb278a..944e639e520e32176a141b00fb7a237cdccf79da 100644 (file)
@@ -1,15 +1,7 @@
-Major:
-
-* Get rid of the last bits of unguarded platform introspection
-
 Some last bits and thoughts:
 
 * A TECPLOT feature has to be written
 
-* Provide a configuration template for cross compiling with CMake,
-
 * Support debug;optimized;general for all FEATURES
 
 * document that we no longer need the two-lib installation of p4est
-
-* same for the Mac part...
index 3dd75856e2aaa9d999ab15469f60008a059a3bc7..d0249fba675c8f8b2f0bca457fcef0fbe7d6e0e2 100644 (file)
@@ -263,18 +263,20 @@ ENDIF()
 #
 # - Matthias Maier, rewritten 2012
 #
-GET_CXX_SOURCE_RETURN_VALUE(
-  "
-  #include <vector>
-  int main () {
-    std::vector<int> v(1);
-    v.reserve (1);
-    v.resize (1);
-    return v.capacity();
-  }
-  "
-  DEAL_II_MIN_VECTOR_CAPACITY
-  DEAL_II_MIN_VECTOR_CAPACITY_RETURN_VALUE)
+IF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION)
+  GET_CXX_SOURCE_RETURN_VALUE(
+    "
+    #include <vector>
+    int main () {
+      std::vector<int> v(1);
+      v.reserve (1);
+      v.resize (1);
+      return v.capacity();
+    }
+    "
+    DEAL_II_MIN_VECTOR_CAPACITY
+    DEAL_II_MIN_VECTOR_CAPACITY_RETURN_VALUE)
+ENDIF()
 
 IF(NOT DEAL_II_MIN_VECTOR_CAPACITY)
   SET(DEAL_II_MIN_VECTOR_CAPACITY 1)
@@ -291,21 +293,23 @@ ENDIF()
 #
 # - Matthias Maier, rewritten 2012
 #
-GET_CXX_SOURCE_RETURN_VALUE(
-  "
-  #include <vector>
-  int main () {
-    std::vector<bool> v(1);
-    v.reserve (1);
-    v.resize (1);
-    return v.capacity();
-  }
-  "
-  DEAL_II_MIN_BOOL_VECTOR_CAPACITY
-  DEAL_II_MIN_BOOL_VECTOR_CAPACITY_RETURN_VALUE)
+IF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION)
+  GET_CXX_SOURCE_RETURN_VALUE(
+    "
+    #include <vector>
+    int main () {
+      std::vector<bool> v(1);
+      v.reserve (1);
+      v.resize (1);
+      return v.capacity();
+    }
+    "
+    DEAL_II_MIN_BOOL_VECTOR_CAPACITY
+    DEAL_II_MIN_BOOL_VECTOR_CAPACITY_RETURN_VALUE)
+ENDIF()
 
 IF(NOT DEAL_II_MIN_BOOL_VECTOR_CAPACITY)
-  SET(DEAL_II_MIN_VECTOR_CAPACITY 1)
+  SET(DEAL_II_MIN_BOOL_VECTOR_CAPACITY 1)
 ELSE()
   SET(DEAL_II_MIN_BOOL_VECTOR_CAPACITY
     ${DEAL_II_MIN_BOOL_VECTOR_CAPACITY_RETURN_VALUE})
index 803fb4abec5338f71f80c870d3ae4bf2723b1ce6..0b4ce417f8b113df0bac011f9ba49e78d045b163 100644 (file)
@@ -108,22 +108,25 @@ IF(DEAL_II_HAVE_CXX11_FLAG)
   # below but it will throw an exception when run. So test
   # that as well.
   #
-  # TODO: Get somehow rid of the platform introspection...
-  #
   # TODO: This test will only succeed on platforms where "-pthread" is
   #       recognized. But this isn't easily fixable:
   #       configure_threads.cmake which will determine and setup threads
   #       has to be called later...
   #
-  PUSH_TEST_FLAG("-pthread")
-  CHECK_CXX_SOURCE_RUNS(
-    "
-    #include <thread>
-    void f(int){}
-    int main(){ std::thread t(f,1); t.join(); return 0; }
-    "
-    DEAL_II_HAVE_CXX11_THREAD)
-  POP_TEST_FLAG()
+  IF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION)
+    PUSH_TEST_FLAG("-pthread")
+    CHECK_CXX_SOURCE_RUNS(
+      "
+      #include <thread>
+      void f(int){}
+      int main(){ std::thread t(f,1); t.join(); return 0; }
+      "
+      DEAL_II_HAVE_CXX11_THREAD)
+    POP_TEST_FLAG()
+  ELSE()
+    # Just export it ;-)
+    SET_IF_EMPTY(DEAL_II_HAVE_CXX11_THREAD TRUE)
+  ENDIF()
 
   CHECK_CXX_SOURCE_COMPILES(
     "
index 7b849838345c8fb072e9c73b6149ad4b8c831b4d..f083500249dc8e0732739548fcc7cf0c6973e378 100644 (file)
 #
 
 MACRO(EXPAND_INSTANTIATIONS _target _inst_in_files)
+
+  IF(CMAKE_CROSSCOMPILING)
+    SET(_ei_exec native-expand_instantiations)
+  ELSE()
+    SET(_ei_exec expand_instantiations)
+  ENDIF()
+
   FOREACH (_inst_in_file ${_inst_in_files})
     STRING(REGEX REPLACE "\\.in$" "" _inst_file "${_inst_in_file}" )
 
     ADD_CUSTOM_COMMAND(
       OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_inst_file}
-      DEPENDS expand_instantiations
+      DEPENDS ${_ei_exec}
               ${CMAKE_BINARY_DIR}/cmake/config/template-arguments
               ${CMAKE_CURRENT_SOURCE_DIR}/${_inst_in_file}
-      COMMAND expand_instantiations
+      COMMAND ${_ei_exec}
       ARGS ${CMAKE_BINARY_DIR}/cmake/config/template-arguments
            < ${CMAKE_CURRENT_SOURCE_DIR}/${_inst_in_file}
            > ${CMAKE_CURRENT_BINARY_DIR}/${_inst_file}
index 8f924f22de0580d5a94ccc368d8ecbd53e17cd96..abe3af8740d9f5705942c1e9f1bcff3f6bf7a487 100644 (file)
 #####
 
 ADD_EXECUTABLE(expand_instantiations expand_instantiations.cc)
+IF(NOT CMAKE_CROSSCOMPILING)
+  #
+  # Export expand_instantiations for use in cross compilation:
+  #
+  EXPORT(TARGETS expand_instantiations
+    FILE ${CMAKE_CURRENT_BINARY_DIR}/importExecutables.cmake
+    NAMESPACE native- # Prefix a namespace
+    )
+ENDIF()
 
 IF(DEAL_II_COMPONENT_COMPAT_FILES)
   #
@@ -40,12 +49,13 @@ IF(DEAL_II_COMPONENT_COMPAT_FILES)
     ${CMAKE_CURRENT_BINARY_DIR}/report_features.cc
     )
   TARGET_LINK_LIBRARIES(report_features ${DEAL_II_EXTERNAL_LIBRARIES})
-  ADD_CUSTOM_TARGET(run_report_features COMMAND report_features)
+  IF(NOT CMAKE_CROSSCOMPILING)
+    ADD_CUSTOM_TARGET(run_report_features COMMAND report_features)
+  ENDIF()
 
   INSTALL(TARGETS make_dependencies report_features expand_instantiations
-    RUNTIME
+    EXPORT ${DEAL_II_PROJECT_CONFIG_NAME}Targets
     DESTINATION ${DEAL_II_COMMON_RELDIR}/scripts
     COMPONENT compat_files
     )
 ENDIF()
-
index 77785e96d6158c928826e576b024e98e0efdbe3d..d22cedd0ef353670b7c39915616210103844bbec 100644 (file)
@@ -107,8 +107,9 @@ ENDIF()
 #                                                                         #
 ###########################################################################
 
-SET(DEAL_II_ALLOW_PLATFORM_INTROSPECTION ON CACHE BOOL
+OPTION(DEAL_II_ALLOW_PLATFORM_INTROSPECTION
   "Allow platform introspection for CPU command set, SSE and AVX"
+  ON
   )
 MARK_AS_ADVANCED(DEAL_II_ALLOW_PLATFORM_INTROSPECTION)
 
index 5644fa08bc37fb9ffe2ece25773e1ae3f5f7acb6..6a9c9a0f6a1abc7588526398518c79fc71479711 100644 (file)
@@ -127,6 +127,12 @@ IF(CMAKE_BUILD_TYPE MATCHES "Release")
 ENDIF()
 
 
+###########################################################################
+#                                                                         #
+#  Cleanup and Includes that have to happen after the call to PROJECT():  #
+#                                                                         #
+###########################################################################
+
 #
 # Cleanup some files used for storing the names of all object targets that
 # will be bundled to the deal.II library.
@@ -140,3 +146,21 @@ FOREACH(_build ${DEAL_II_BUILD_TYPES})
     )
 ENDFOREACH()
 
+
+#
+# Cross compilation stuff:
+#
+IF(CMAKE_CROSSCOMPILING)
+  #
+  # Disable platform introspection when cross compiling
+  #
+  SET(DEAL_II_ALLOW_PLATFORM_INTROSPECTION OFF CACHE BOOL "" FORCE)
+
+  #
+  # Import native expand_instantiations for use in cross compilation:
+  #
+  SET(DEAL_II_NATIVE "DEAL_II_NATIVE-NOTFOUND" CACHE FILEPATH
+    "A pointer to a native deal.Ii build directory"
+    )
+  INCLUDE(${DEAL_II_NATIVE}/cmake/scripts//importExecutables.cmake)
+ENDIF()
index 1773ed5f82f616cf8f9fe491a8fbcb40039ff4b6..129da7a40b262ac868d4731fd2702133634378dd 100644 (file)
@@ -80,17 +80,23 @@ _both(
 "###
 #
 #  ${DEAL_II_PACKAGE_NAME} configuration:
-#
 #        CMAKE_BUILD_TYPE:       ${CMAKE_BUILD_TYPE}
 #        BUILD_SHARED_LIBS:      ${BUILD_SHARED_LIBS}
 #        CMAKE_INSTALL_PREFIX:   ${CMAKE_INSTALL_PREFIX}
 #        CMAKE_SOURCE_DIR:       ${CMAKE_SOURCE_DIR} (Version ${DEAL_II_PACKAGE_VERSION})
 #        CMAKE_BINARY_DIR:       ${CMAKE_BINARY_DIR}
-#        CMAKE_CXX_COMPILER:     ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} on platform ${CMAKE_SYSTEM_NAME}
+#        CMAKE_CXX_COMPILER:     ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} on platform ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_PROCESSOR}
 #                                ${CMAKE_CXX_COMPILER}
-#
 "
   )
+IF(CMAKE_CROSSCOMPILING)
+  _both(
+    "#        CROSSCOMPILING!\n"
+    "#        DEAL_II_NATIVE:         ${DEAL_II_NATIVE}\n"
+    )
+ENDIF()
+
+_both("#\n")
 
 _detailed(
 "#  Compiler flags used for this build:
diff --git a/deal.II/doc/development/Toolchain.sample b/deal.II/doc/development/Toolchain.sample
new file mode 100644 (file)
index 0000000..2788d19
--- /dev/null
@@ -0,0 +1,10 @@
+SET(CMAKE_SYSTEM_NAME Linux)
+SET(CMAKE_SYSTEM_PROCESSOR "x86")
+
+SET(CMAKE_C_COMPILER "/usr/bin/gcc")
+SET(CMAKE_CXX_COMPILER "/usr/bin/g++")
+
+SET(CMAKE_FIND_ROOT_PATH "/")
+SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
index 273bd0bee258316143f8bfd04ded7b0d5d7199c5..ee4d340d9018b8cd43c70c365521ce6eadc034b8 100644 (file)
       </ul>
     </p>
 
-    <!--
     <h2>Cross compiling</h2>
 
     <p>
       It is possible to use <a href="http://www.cmake.org/"
       target="_top">CMake</a> to cross compile
-      <acronym>deal.II</acronym> for a foreign platform.  It is best
-      to start cross compiling with minimal external dependencies
-      (<code>-DDEAL_II_ALLOW_AUTODETECTION=OFF</code>, see the
-      <a href="cmake.html">deal.II CMake documentation</a>).
-      Further information on that topic can be found in the <a
+      <acronym>deal.II</acronym> for a foreign platform.
+      Further information on that topic can be found at the <a
       href="http://www.cmake.org/Wiki/CMake_Cross_Compiling">CMake
       wiki</a>.
-    -->
+    </p>
 
-    <hr>
+    <p>
+      You have to set up a native deal.II build directory first and run
+      <code>make expand_instantiations</code> in it. The executable is
+      needed for the build system (and obviously the cross compiled version
+      cannot be used). Assuming you have a working cross compilation
+      toolchain, set up a <i>toolchain file</i> next. An example toolchain
+      file can be found <a href="Toolchain.sample">here</a>. With that
+      invoke <code>cmake</code> e.g. with:
+      <pre>
+    cmake -DCMAKE_TOOLCHAIN_FILE=&lt;...&gt;/Toolchain.sample
+          -DDEAL_II_NATIVE=&lt;...&gt;/native/build/dir
+
+          -DDEAL_II_FORCE_BUNDLED_BOOST=ON
+          -DDEAL_II_ALLOW_AUTODETECTION=OFF
+          ../deal.II
+      </pre>
+      where <code>DEAL_II_NATIVE</code> points to the toolchain file and
+      <code>DEAL_II_NATIVE</code> to the native build directory (which
+      <code>expand_instantiations</code> will be picked from). The remaining
+      configuration can be adjusted at will, see <a
+        href="cmake.html">the documentation</a>.
+    </p>
 
+    <hr>
     <address>
       <a href="../mail.html" target="body">The deal.II Group</a>
     </address>

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.