From 90291779c5e0b2db6cca320118b85429cf1d4fc4 Mon Sep 17 00:00:00 2001 From: maier Date: Sat, 30 Mar 2013 17:10:00 +0000 Subject: [PATCH] CMake: Add crosscompilation support git-svn-id: https://svn.dealii.org/trunk@29118 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/cmake/TODO.CMAKE | 8 --- .../checks/check_01_compiler_features.cmake | 54 ++++++++++--------- .../cmake/checks/check_01_cxx_features.cmake | 25 +++++---- .../macros/macro_expand_instantiations.cmake | 11 +++- deal.II/cmake/scripts/CMakeLists.txt | 16 ++++-- deal.II/cmake/setup_cached_variables.cmake | 3 +- deal.II/cmake/setup_deal_ii.cmake | 24 +++++++++ deal.II/cmake/setup_finalize.cmake | 12 +++-- deal.II/doc/development/Toolchain.sample | 10 ++++ deal.II/doc/development/porting.html | 34 +++++++++--- 10 files changed, 136 insertions(+), 61 deletions(-) create mode 100644 deal.II/doc/development/Toolchain.sample diff --git a/deal.II/cmake/TODO.CMAKE b/deal.II/cmake/TODO.CMAKE index 06979ce6c8..944e639e52 100644 --- a/deal.II/cmake/TODO.CMAKE +++ b/deal.II/cmake/TODO.CMAKE @@ -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... diff --git a/deal.II/cmake/checks/check_01_compiler_features.cmake b/deal.II/cmake/checks/check_01_compiler_features.cmake index 3dd75856e2..d0249fba67 100644 --- a/deal.II/cmake/checks/check_01_compiler_features.cmake +++ b/deal.II/cmake/checks/check_01_compiler_features.cmake @@ -263,18 +263,20 @@ ENDIF() # # - Matthias Maier, rewritten 2012 # -GET_CXX_SOURCE_RETURN_VALUE( - " - #include - int main () { - std::vector 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 + int main () { + std::vector 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 - int main () { - std::vector 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 + int main () { + std::vector 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}) diff --git a/deal.II/cmake/checks/check_01_cxx_features.cmake b/deal.II/cmake/checks/check_01_cxx_features.cmake index 803fb4abec..0b4ce417f8 100644 --- a/deal.II/cmake/checks/check_01_cxx_features.cmake +++ b/deal.II/cmake/checks/check_01_cxx_features.cmake @@ -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 - 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 + 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( " diff --git a/deal.II/cmake/macros/macro_expand_instantiations.cmake b/deal.II/cmake/macros/macro_expand_instantiations.cmake index 7b84983834..f083500249 100644 --- a/deal.II/cmake/macros/macro_expand_instantiations.cmake +++ b/deal.II/cmake/macros/macro_expand_instantiations.cmake @@ -32,15 +32,22 @@ # 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} diff --git a/deal.II/cmake/scripts/CMakeLists.txt b/deal.II/cmake/scripts/CMakeLists.txt index 8f924f22de..abe3af8740 100644 --- a/deal.II/cmake/scripts/CMakeLists.txt +++ b/deal.II/cmake/scripts/CMakeLists.txt @@ -13,6 +13,15 @@ ##### 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() - diff --git a/deal.II/cmake/setup_cached_variables.cmake b/deal.II/cmake/setup_cached_variables.cmake index 77785e96d6..d22cedd0ef 100644 --- a/deal.II/cmake/setup_cached_variables.cmake +++ b/deal.II/cmake/setup_cached_variables.cmake @@ -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) diff --git a/deal.II/cmake/setup_deal_ii.cmake b/deal.II/cmake/setup_deal_ii.cmake index 5644fa08bc..6a9c9a0f6a 100644 --- a/deal.II/cmake/setup_deal_ii.cmake +++ b/deal.II/cmake/setup_deal_ii.cmake @@ -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() diff --git a/deal.II/cmake/setup_finalize.cmake b/deal.II/cmake/setup_finalize.cmake index 1773ed5f82..129da7a40b 100644 --- a/deal.II/cmake/setup_finalize.cmake +++ b/deal.II/cmake/setup_finalize.cmake @@ -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 index 0000000000..2788d1962b --- /dev/null +++ b/deal.II/doc/development/Toolchain.sample @@ -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) diff --git a/deal.II/doc/development/porting.html b/deal.II/doc/development/porting.html index 273bd0bee2..ee4d340d90 100644 --- a/deal.II/doc/development/porting.html +++ b/deal.II/doc/development/porting.html @@ -122,23 +122,41 @@

- +

-
+

+ You have to set up a native deal.II build directory first and run + make expand_instantiations 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 toolchain file next. An example toolchain + file can be found here. With that + invoke cmake e.g. with: +

+    cmake -DCMAKE_TOOLCHAIN_FILE=<...>/Toolchain.sample
+          -DDEAL_II_NATIVE=<...>/native/build/dir
+
+          -DDEAL_II_FORCE_BUNDLED_BOOST=ON
+          -DDEAL_II_ALLOW_AUTODETECTION=OFF
+          ../deal.II
+      
+ where DEAL_II_NATIVE points to the toolchain file and + DEAL_II_NATIVE to the native build directory (which + expand_instantiations will be picked from). The remaining + configuration can be adjusted at will, see the documentation. +

+
The deal.II Group
-- 2.39.5