Permalink
Browse files

Refactor 799735f to avoid duplicity. Patch from Tim Gallagher.

  • Loading branch information...
1 parent 381c836 commit b00107242471e7397a306224d1decf6b2bcc7b46 @jedbrown committed Dec 2, 2011
Showing with 45 additions and 75 deletions.
  1. +26 −51 FindPETSc.cmake
  2. +19 −24 FindPackageMultipass.cmake
View
@@ -196,66 +196,41 @@ show :
message (STATUS "Recognized PETSc install with single library for all packages")
endif ()
- # Check to see if we are doing a C source test
- if(${PETSC_LANGUAGE_BINDINGS} STREQUAL "C")
- include (CheckCSourceRuns)
- macro (PETSC_TEST_RUNS includes libraries runs)
- if (PETSC_VERSION VERSION_GREATER 3.1)
- set (_PETSC_TSDestroy "TSDestroy(&ts)")
- else ()
- set (_PETSC_TSDestroy "TSDestroy(ts)")
- endif ()
- multipass_c_source_runs ("${includes}" "${libraries}" "
+ include(Check${PETSC_LANGUAGE_BINDINGS}SourceRuns)
+ macro (PETSC_TEST_RUNS includes libraries runs)
+ if(${PETSC_LANGUAGE_BINDINGS} STREQUAL "C")
+ set(_PETSC_ERR_FUNC "CHKERRQ(ierr)")
+ elseif(${PETSC_LANGUAGE_BINDINGS} STREQUAL "CXX")
+ set(_PETSC_ERR_FUNC "CHKERRXX(ierr)")
+ endif()
+ if (PETSC_VERSION VERSION_GREATER 3.1)
+ set (_PETSC_TSDestroy "TSDestroy(&ts)")
+ else ()
+ set (_PETSC_TSDestroy "TSDestroy(ts)")
+ endif ()
+
+ set(_PETSC_TEST_SOURCE "
static const char help[] = \"PETSc test program.\";
#include <petscts.h>
int main(int argc,char *argv[]) {
PetscErrorCode ierr;
TS ts;
- ierr = PetscInitialize(&argc,&argv,0,help);CHKERRQ(ierr);
- ierr = TSCreate(PETSC_COMM_WORLD,&ts);CHKERRQ(ierr);
- ierr = TSSetFromOptions(ts);CHKERRQ(ierr);
- ierr = ${_PETSC_TSDestroy};CHKERRQ(ierr);
- ierr = PetscFinalize();CHKERRQ(ierr);
+ ierr = PetscInitialize(&argc,&argv,0,help);${_PETSC_ERR_FUNC};
+ ierr = TSCreate(PETSC_COMM_WORLD,&ts);${_PETSC_ERR_FUNC};
+ ierr = TSSetFromOptions(ts);${_PETSC_ERR_FUNC};
+ ierr = ${_PETSC_TSDestroy};${_PETSC_ERR_FUNC};
+ ierr = PetscFinalize();${_PETSC_ERR_FUNC};
return 0;
}
-" ${runs})
- if (${${runs}})
- set (PETSC_EXECUTABLE_RUNS "YES" CACHE BOOL
- "Can the system successfully run a PETSc executable? This variable can be manually set to \"YES\" to force CMake to accept a given PETSc configuration, but this will almost always result in a broken build. If you change PETSC_DIR, PETSC_ARCH, or PETSC_CURRENT you would have to reset this variable." FORCE)
- endif (${${runs}})
- endmacro (PETSC_TEST_RUNS)
- endif()
-
- if(${PETSC_LANGUAGE_BINDINGS} STREQUAL "CXX")
- include (CheckCXXSourceRuns)
- macro (PETSC_TEST_RUNS includes libraries runs)
- if (PETSC_VERSION VERSION_GREATER 3.1)
- set (_PETSC_TSDestroy "TSDestroy(&ts)")
- else ()
- set (_PETSC_TSDestroy "TSDestroy(ts)")
- endif ()
- multipass_cxx_source_runs ("${includes}" "${libraries}" "
-static const char help[] = \"PETSc test program.\";
-#include <petscts.h>
-int main(int argc,char *argv[]) {
- PetscErrorCode ierr;
- TS ts;
+")
+ multipass_source_runs ("${includes}" "${libraries}" "${_PETSC_TEST_SOURCE}" ${runs} "${PETSC_LANGUAGE_BINDINGS}")
+ if (${${runs}})
+ set (PETSC_EXECUTABLE_RUNS "YES" CACHE BOOL
+ "Can the system successfully run a PETSc executable? This variable can be manually set to \"YES\" to force CMake to accept a given PETSc configuration, but this will almost always result in a broken build. If you change PETSC_DIR, PETSC_ARCH, or PETSC_CURRENT you would have to reset this variable." FORCE)
+ endif (${${runs}})
+ endmacro (PETSC_TEST_RUNS)
- ierr = PetscInitialize(&argc,&argv,0,help);CHKERRXX(ierr);
- ierr = TSCreate(PETSC_COMM_WORLD,&ts);CHKERRXX(ierr);
- ierr = TSSetFromOptions(ts);CHKERRXX(ierr);
- ierr = ${_PETSC_TSDestroy};CHKERRXX(ierr);
- ierr = PetscFinalize();CHKERRXX(ierr);
- return 0;
-}
-" ${runs})
- if (${${runs}})
- set (PETSC_EXECUTABLE_RUNS "ON" CACHE BOOL
- "Can the system successfully run a PETSc executable? This variable can be manually set to \"ON\" to force CMake to accept a given PETSc configuration, but this will almost always result in a broken build. If you change PETSC_DIR, PETSC_ARCH, or PETSC_CURRENT you would have to reset this variable." FORCE)
- endif (${${runs}})
- endmacro (PETSC_TEST_RUNS)
- endif()
find_path (PETSC_INCLUDE_DIR petscts.h HINTS "${PETSC_DIR}" PATH_SUFFIXES include NO_DEFAULT_PATH)
find_path (PETSC_INCLUDE_CONF petscconf.h HINTS "${PETSC_DIR}" PATH_SUFFIXES "${PETSC_ARCH}/include" "bmake/${PETSC_ARCH}" NO_DEFAULT_PATH)
View
@@ -21,7 +21,14 @@
# # Make temporary files, run programs, etc, to determine FOO_INCLUDES and FOO_LIBRARIES
# endif (NOT foo_current)
#
+# MULTIPASS_SOURCE_RUNS (Name INCLUDES LIBRARIES SOURCE RUNS LANGUAGE)
+# Always runs the given test, use this when you need to re-run tests
+# because parent variables have made old cache entries stale. The LANGUAGE
+# variable is either C or CXX indicating which compiler the test should
+# use.
# MULTIPASS_C_SOURCE_RUNS (Name INCLUDES LIBRARIES SOURCE RUNS)
+# DEPRECATED! This is only included for backwards compatability. Use
+# the more general MULTIPASS_SOURCE_RUNS instead.
# Always runs the given test, use this when you need to re-run tests
# because parent variables have made old cache entries stale.
@@ -70,9 +77,9 @@ macro (FIND_PACKAGE_MULTIPASS _name _current)
endmacro (FIND_PACKAGE_MULTIPASS)
-macro (MULTIPASS_C_SOURCE_RUNS includes libraries source runs)
- include (CheckCSourceRuns)
- # This is a ridiculous hack. CHECK_C_SOURCE_* thinks that if the
+macro (MULTIPASS_SOURCE_RUNS includes libraries source runs language)
+ include (Check${language}SourceRuns)
+ # This is a ridiculous hack. CHECK_${language}_SOURCE_* thinks that if the
# *name* of the return variable doesn't change, then the test does
# not need to be re-run. We keep an internal count which we
# increment to guarantee that every test name is unique. If we've
@@ -86,26 +93,14 @@ macro (MULTIPASS_C_SOURCE_RUNS includes libraries source runs)
set (testname MULTIPASS_TEST_${MULTIPASS_TEST_COUNT}_${runs})
set (CMAKE_REQUIRED_INCLUDES ${includes})
set (CMAKE_REQUIRED_LIBRARIES ${libraries})
- check_c_source_runs ("${source}" ${testname})
+ if(${language} STREQUAL "C")
+ check_c_source_runs ("${source}" ${testname})
+ elseif(${language} STREQUAL "CXX")
+ check_cxx_source_runs ("${source}" ${testname})
+ endif()
set (${runs} "${${testname}}")
-endmacro (MULTIPASS_C_SOURCE_RUNS)
+endmacro (MULTIPASS_SOURCE_RUNS)
-macro (MULTIPASS_CXX_SOURCE_RUNS includes libraries source runs)
- include (CheckCXXSourceRuns)
- # This is a ridiculous hack. CHECK_CXX_SOURCE_* thinks that if the
- # *name* of the return variable doesn't change, then the test does
- # not need to be re-run. We keep an internal count which we
- # increment to guarantee that every test name is unique. If we've
- # gotten here, then the configuration has changed enough that the
- # test *needs* to be rerun.
- if (NOT MULTIPASS_TEST_COUNT)
- set (MULTIPASS_TEST_COUNT 00)
- endif (NOT MULTIPASS_TEST_COUNT)
- math (EXPR _tmp "${MULTIPASS_TEST_COUNT} + 1") # Why can't I add to a cache variable?
- set (MULTIPASS_TEST_COUNT ${_tmp} CACHE INTERNAL "Unique test ID")
- set (testname MULTIPASS_TEST_${MULTIPASS_TEST_COUNT}_${runs})
- set (CMAKE_REQUIRED_INCLUDES ${includes})
- set (CMAKE_REQUIRED_LIBRARIES ${libraries})
- check_cxx_source_runs ("${source}" ${testname})
- set (${runs} "${${testname}}")
-endmacro (MULTIPASS_CXX_SOURCE_RUNS)
+macro (MULTIPASS_C_SOURCE_RUNS includes libraries source runs)
+ multipass_source_runs("${includes}" "${libraries}" "${source}" ${runs} "C")
+endmacro (MULTIPASS_C_SOURCE_RUNS)

0 comments on commit b001072

Please sign in to comment.