From: maier Date: Tue, 16 Jul 2013 09:30:56 +0000 (+0000) Subject: CMake: Make a working C compiler optional. Do not require to have a strict X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9265f9a299bb02ddb9e8a0e3a09761f430b13bb2;p=dealii-svn.git CMake: Make a working C compiler optional. Do not require to have a strict matching between C compiler and CXX compiler any more git-svn-id: https://svn.dealii.org/trunk@30005 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/CMakeLists.txt b/deal.II/CMakeLists.txt index e193114c9a..7f7a4e9543 100644 --- a/deal.II/CMakeLists.txt +++ b/deal.II/CMakeLists.txt @@ -66,7 +66,8 @@ INCLUDE(setup_cached_variables) # # Now, set the project and set up the rest: # -PROJECT(deal.II CXX C) +PROJECT(deal.II CXX) +ENABLE_LANGUAGE(C OPTIONAL) INCLUDE(setup_deal_ii) INCLUDE(setup_compiler_flags) diff --git a/deal.II/cmake/checks/check_01_cpu_features.cmake b/deal.II/cmake/checks/check_01_cpu_features.cmake index 81ac8f6a2e..7eb1d358d9 100644 --- a/deal.II/cmake/checks/check_01_cpu_features.cmake +++ b/deal.II/cmake/checks/check_01_cpu_features.cmake @@ -37,8 +37,14 @@ # # Determine the Endianess of the platform: # -INCLUDE(TestBigEndian) -TEST_BIG_ENDIAN(DEAL_II_WORDS_BIGENDIAN) +IF(CMAKE_C_COMPILER_WORKS) + INCLUDE(TestBigEndian) + TEST_BIG_ENDIAN(DEAL_II_WORDS_BIGENDIAN) +ELSE() + MESSAGE(STATUS + "No suitable C compiler was found! Assuming little endian platform." + ) +ENDIF() IF(DEAL_II_ALLOW_PLATFORM_INTROSPECTION) diff --git a/deal.II/cmake/configure/configure_1_lapack.cmake b/deal.II/cmake/configure/configure_1_lapack.cmake index ad3fb4fde6..7e614ac738 100644 --- a/deal.II/cmake/configure/configure_1_lapack.cmake +++ b/deal.II/cmake/configure/configure_1_lapack.cmake @@ -101,10 +101,19 @@ MACRO(CHECK_FOR_LAPACK_FUNCTIONS) # ENABLE_IF_SUPPORTED(CMAKE_REQUIRED_FLAGS "-pthread") - FOREACH(_func ${DEAL_II_LAPACK_FUNCTIONS}) - STRING(TOUPPER ${_func} _func_uppercase) - CHECK_FUNCTION_EXISTS(${_func} HAVE_${_func_uppercase}) - ENDFOREACH() + IF(CMAKE_C_COMPILER_WORKS) + FOREACH(_func ${DEAL_II_LAPACK_FUNCTIONS}) + STRING(TOUPPER ${_func} _func_uppercase) + CHECK_FUNCTION_EXISTS(${_func} HAVE_${_func_uppercase}) + ENDFOREACH() + ELSE() + MESSAGE(STATUS + "No suitable C compiler was found! Skipping LAPACK symbol check." + ) + FOREACH(_func ${DEAL_II_LAPACK_FUNCTIONS}) + SET_IF_EMPTY(HAVE_${_func_uppercase} TRUE) + ENDFOREACH() + ENDIF() SET(CMAKE_REQUIRED_LIBRARIES) STRIP_FLAG(CMAKE_REQUIRED_FLAGS "${LAPACK_LINKER_FLAGS}") diff --git a/deal.II/cmake/configure/configure_1_mpi.cmake b/deal.II/cmake/configure/configure_1_mpi.cmake index 479b363af5..fc88e1e1fb 100644 --- a/deal.II/cmake/configure/configure_1_mpi.cmake +++ b/deal.II/cmake/configure/configure_1_mpi.cmake @@ -18,7 +18,7 @@ MACRO(FEATURE_MPI_FIND_EXTERNAL var) # - # Enable Fortran support so that MPI_Fortran_LIBRARIES is set up. + # Enable C and Fortran support so that MPI_Fortran_LIBRARIES is set up. # IF(NOT CMAKE_Fortran_COMPILER_WORKS) ENABLE_LANGUAGE(Fortran OPTIONAL) @@ -38,8 +38,22 @@ MACRO(FEATURE_MPI_FIND_EXTERNAL var) # directly. # SET_IF_EMPTY(MPI_CXX_COMPILER ${CMAKE_CXX_COMPILER}) - SET_IF_EMPTY(MPI_C_COMPILER ${CMAKE_C_COMPILER}) # for good measure - SET_IF_EMPTY(MPI_Fortran_COMPILER ${CMAKE_Fortran_COMPILER}) # for good measure + IF(CMAKE_C_COMPILER_WORKS) + SET_IF_EMPTY(MPI_C_COMPILER ${CMAKE_C_COMPILER}) # for good measure + ELSE() + MESSAGE(STATUS + "No suitable C compiler was found! MPI C interface can not be " + "autodetected" + ) + ENDIF() + IF(CMAKE_Fortran_COMPILER_WORKS) + SET_IF_EMPTY(MPI_Fortran_COMPILER ${CMAKE_Fortran_COMPILER}) # for good measure + ELSE() + MESSAGE(STATUS + "No suitable Fortran compiler was found! MPI Fortran interface can " + "not be autodetected" + ) + ENDIF() FIND_PACKAGE(MPI) IF(NOT MPI_CXX_FOUND) diff --git a/deal.II/cmake/configure/configure_1_threads.cmake b/deal.II/cmake/configure/configure_1_threads.cmake index ad4afe3b72..5161e6ee59 100644 --- a/deal.II/cmake/configure/configure_1_threads.cmake +++ b/deal.II/cmake/configure/configure_1_threads.cmake @@ -25,16 +25,37 @@ # MACRO(SETUP_THREADING) # - # Switch the library preference back to prefer dynamic libraries if - # DEAL_II_PREFER_STATIC_LIBS=TRUE but DEAL_II_STATIC_EXECUTABLE=FALSE. In - # this case system libraries should be linked dynamically. + # Unfortunately the FindThreads macro needs a working C compiler # - SWITCH_LIBRARY_PREFERENCE() - FIND_PACKAGE(Threads) - SWITCH_LIBRARY_PREFERENCE() + IF(CMAKE_C_COMPILER_WORKS) + # + # Switch the library preference back to prefer dynamic libraries if + # DEAL_II_PREFER_STATIC_LIBS=TRUE but DEAL_II_STATIC_EXECUTABLE=FALSE. In + # this case system libraries should be linked dynamically. + # + SWITCH_LIBRARY_PREFERENCE() + FIND_PACKAGE(Threads) + SWITCH_LIBRARY_PREFERENCE() + + ELSE() + + # + # We have no way to query for thread support. Just assume that it is + # provided by Pthreads... + # + MESSAGE(STATUS + "No suitable C compiler was found! Assuming threading is provided by Pthreads." + ) + SET_IF_EMPTY(Threads_FOUND TRUE) + SET_IF_EMPTY(CMAKE_THREAD_LIBS_INIT "-lpthread") + SET_IF_EMPTY(CMAKE_USE_PTHREADS_INIT TRUE) + ENDIF() IF(NOT Threads_FOUND) - # TODO: + # + # TODO: This is a dead end. Threading might be setup with internal TBB + # so we have no way of returning unsuccessfully... + # MESSAGE(FATAL_ERROR "\nInternal configuration error: No Threading support found\n\n" ) diff --git a/deal.II/cmake/setup_cached_variables.cmake b/deal.II/cmake/setup_cached_variables.cmake index 8b6a6d4465..87250ab326 100644 --- a/deal.II/cmake/setup_cached_variables.cmake +++ b/deal.II/cmake/setup_cached_variables.cmake @@ -230,6 +230,10 @@ FOREACH(_flag CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO + CMAKE_Fortran_FLAGS_RELEASE + CMAKE_Fortran_FLAGS_DEBUG + CMAKE_Fortran_FLAGS_MINSIZEREL + CMAKE_Fortran_FLAGS_RELWITHDEBINFO CMAKE_SHARED_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS_DEBUG CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL @@ -244,7 +248,6 @@ ENDFOREACH() # Set cached compiler flags to an empty string: # SET(DEAL_II_USED_FLAGS - CMAKE_C_FLAGS CMAKE_CXX_FLAGS DEAL_II_CXX_FLAGS_DEBUG DEAL_II_CXX_FLAGS_RELEASE @@ -278,13 +281,11 @@ ENDFOREACH() # -# Finally, read in CFLAGS, CXXFLAGS and LDFLAGS from environment and -# prepend them to the saved variables: +# Finally, read in CXXFLAGS and LDFLAGS from environment and prepend them +# to the saved variables: # -SET(CMAKE_C_FLAGS_SAVED "$ENV{CFLAGS} ${CMAKE_C_FLAGS_SAVED}") SET(CMAKE_CXX_FLAGS_SAVED "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_SAVED}") SET(DEAL_II_LINKER_FLAGS_SAVED "$ENV{LDFLAGS} ${DEAL_II_LINKER_FLAGS_SAVED}") -UNSET(ENV{CFLAGS}) UNSET(ENV{CXXFLAGS}) UNSET(ENV{LDFLAGS}) diff --git a/deal.II/cmake/setup_compiler_flags.cmake b/deal.II/cmake/setup_compiler_flags.cmake index f3df43df99..f2f26ee312 100644 --- a/deal.II/cmake/setup_compiler_flags.cmake +++ b/deal.II/cmake/setup_compiler_flags.cmake @@ -61,29 +61,11 @@ ########################################################################### # -# Check the user provided C and CXX flags: +# Check the user provided CXX flags: +# +# +# Omit to test for a sane C and Fortran toolchain for now.. # - -IF(NOT "${CMAKE_C_FLAGS_SAVED}" STREQUAL "${DEAL_II_C_FLAGS_SAVED}") - UNSET(DEAL_II_HAVE_USABLE_C_FLAGS CACHE) -ENDIF() -SET(DEAL_II_C_FLAGS_SAVED "${CMAKE_C_FLAGS_SAVED}" CACHE INTERNAL "" FORCE) - -SET(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS_SAVED}") -CHECK_C_SOURCE_COMPILES( - "int main(){ return 0; }" - DEAL_II_HAVE_USABLE_C_FLAGS) -SET(CMAKE_REQUIRED_FLAGS "") - -IF(NOT DEAL_II_HAVE_USABLE_C_FLAGS) - UNSET(DEAL_II_HAVE_USABLE_C_FLAGS CACHE) - MESSAGE(FATAL_ERROR "\n" - "Configuration error: Cannot compile with the specified C flags: " - "${CMAKE_C_FLAGS_SAVED}\n" - ) -ENDIF() - - IF(NOT "${CMAKE_CXX_FLAGS_SAVED}" STREQUAL "${DEAL_II_CXX_FLAGS_SAVED}") UNSET(DEAL_II_HAVE_USABLE_CXX_FLAGS CACHE) ENDIF() @@ -104,20 +86,6 @@ IF(NOT DEAL_II_HAVE_USABLE_CXX_FLAGS) ENDIF() -# -# CMAKE_C_COMPILER and CMAKE_CXX_COMPILER have to be of the same brand. -# -IF(NOT ( "${CMAKE_C_COMPILER_ID}" STREQUAL "${CMAKE_CXX_COMPILER_ID}" AND - "${CMAKE_C_COMPILER_VERSION}" STREQUAL "${CMAKE_CXX_COMPILER_VERSION}" ) ) - MESSAGE(FATAL_ERROR "\n" - "Configuration error: The specified C and CXX compiler have to be of the " - "same family, but cmake found:\n" - "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}\n" - "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}\n" - ) -ENDIF() - - ########################################################################### # # # Compiler setup: # diff --git a/deal.II/cmake/setup_external_macros.cmake b/deal.II/cmake/setup_external_macros.cmake index f5c3a150a1..6adfecc7ab 100644 --- a/deal.II/cmake/setup_external_macros.cmake +++ b/deal.II/cmake/setup_external_macros.cmake @@ -18,7 +18,6 @@ INCLUDE(CheckCXXCompilerFlag) INCLUDE(CheckCXXSourceCompiles) -INCLUDE(CheckCSourceCompiles) INCLUDE(CheckCXXSourceRuns) INCLUDE(CheckCXXSymbolExists) INCLUDE(CheckIncludeFileCXX)