Permalink
Browse files

Make FindiMesh.cmake properly multipass.

This module now only links the interface library unless the explicit
linking of recursive dependencies is needed.

Signed-off-by: Jed Brown <jed@59A2.org>
  • Loading branch information...
1 parent 3b828b1 commit d8732ca164c9c1e0a5640e2a7b1313eafd1681e2 @jedbrown committed Nov 8, 2008
Showing with 94 additions and 84 deletions.
  1. +1 −1 FindFFTW.cmake
  2. +1 −1 FindGSL.cmake
  3. +1 −1 FindPackageMultipass.cmake
  4. +90 −80 FindiMesh.cmake
  5. +1 −1 ResolveCompilerPaths.cmake
View
@@ -14,7 +14,7 @@ find_path (FFTW_INCLUDES fftw3.h)
find_library (FFTW_LIBRARIES NAMES fftw3)
-# handle the QUIETLY and REQUIRED arguments and set FFTW_FOUND to TRUE if
+# handle the QUIETLY and REQUIRED arguments and set FFTW_FOUND to TRUE if
# all listed variables are TRUE
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (FFTW DEFAULT_MSG FFTW_LIBRARIES FFTW_INCLUDES)
View
@@ -15,7 +15,7 @@ find_path (GSL_INCLUDES gsl/gsl_math.h)
find_library (GSL_LIBRARIES NAMES gsl)
-# handle the QUIETLY and REQUIRED arguments and set GSL_FOUND to TRUE if
+# handle the QUIETLY and REQUIRED arguments and set GSL_FOUND to TRUE if
# all listed variables are TRUE
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (GSL DEFAULT_MSG GSL_LIBRARIES GSL_INCLUDES)
@@ -20,7 +20,7 @@
# if (NOT foo_current)
# # Make temporary files, run programs, etc, to determine FOO_INCLUDES and FOO_LIBRARIES
# endif (NOT foo_current)
-#
+#
# MULTIPASS_C_SOURCE_RUNS (Name INCLUDES LIBRARIES SOURCE RUNS)
# Always runs the given test, use this when you need to re-run tests
# because parent variables have made old cache entries stale.
View
@@ -2,7 +2,7 @@
# Once done this will define
#
# IMESH_FOUND - system has iMesh
-# IMESH_INCLUDE_DIRS - The iMesh include directory
+# IMESH_INCLUDES - The iMesh include directory
# IMESH_LIBRARIES - Link these to use iMesh
#
# Setting this changes the behavior of the search
@@ -15,98 +15,108 @@
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
+
+find_path (IMESH_DIR
+ NAMES lib/iMesh-Defs.inc lib64/iMesh-Defs.inc include/iMesh.h
+ HINTS ENV IMESH_DIR)
+
+include (FindPackageMultipass)
+# If the user changes IMESH_DIR, relocate IMESH_DEFS_FILE
+if (PACKAGE_MULTIPASS_IMESH_DIR)
+ if (IMESH_DIR STREQUAL "${PACKAGE_MULTIPASS_IMESH_DIR}")
+ # Do nothing
+ else (IMESH_DIR STREQUAL "${PACKAGE_MULTIPASS_IMESH_DIR}")
+ set (IMESH_DEFS_FILE "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
+ endif (IMESH_DIR STREQUAL "${PACKAGE_MULTIPASS_IMESH_DIR}")
+endif (PACKAGE_MULTIPASS_IMESH_DIR)
+
find_file (IMESH_DEFS_FILE iMesh-Defs.inc
- PATHS /usr /usr/local
- HINTS ENV IMESH_DIR
+ HINTS ${IMESH_DIR}
PATH_SUFFIXES lib lib64)
-set (IMESH_CONFIG_CURRENT TRUE)
-if (NOT "${IMESH_DEFS_FILE}" STREQUAL "${IMESH_DEFS_FILE_PRIVATE}")
- set (IMESH_CONFIG_CURRENT FALSE)
-endif (NOT "${IMESH_DEFS_FILE}" STREQUAL "${IMESH_DEFS_FILE_PRIVATE}")
-
-if (IMESH_CONFIG_CURRENT AND IMESH_INCLUDE_DIRS AND IMESH_LIBRARIES)
- # Do nothing: all variables are in cache
-elseif (IMESH_DEFS_FILE)
- set (IMESH_DEFS_FILE_PRIVATE ${IMESH_DEFS_FILE} CACHE INTERNAL "Saved value" FORCE)
+# If IMESH_DEFS_FILE has changed, wipe dependents
+find_package_multipass (iMesh imesh_config_current
+ STATES DIR DEFS_FILE
+ DEPENDENTS INCLUDES LIBRARIES)
+if (NOT imesh_config_current)
# A temporary makefile to probe the iMesh configuration
- set (IMESH_CONFIG_MAKEFILE ${PROJECT_BINARY_DIR}/Makefile.imesh)
-
- file (WRITE ${IMESH_CONFIG_MAKEFILE}
+ set (imesh_config_makefile "${PROJECT_BINARY_DIR}/Makefile.imesh")
+ file (WRITE ${imesh_config_makefile}
"## This file was autogenerated by FindiMesh.cmake
include ${IMESH_DEFS_FILE}
-show_includes :
- -@echo \${IMESH_INCLUDES}
-show_incdir :
- -@echo \${IMESH_INCLUDEDIR}
-show_libs :
- -@echo \${IMESH_LIBS}
-")
-
- exec_program(${CMAKE_MAKE_PROGRAM}
- ARGS -f ${IMESH_CONFIG_MAKEFILE} show_includes
- OUTPUT_VARIABLE IMESH_INCLUDES_LINE
- RETURN_VALUE IMESH_RETURN)
+show :
+ -@echo -n \${\${VARIABLE}}")
+ macro (IMESH_GET_VARIABLE name var)
+ set (${var} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
+ execute_process (COMMAND ${CMAKE_MAKE_PROGRAM} -f ${imesh_config_makefile} show VARIABLE=${name}
+ OUTPUT_VARIABLE ${var}
+ RESULT_VARIABLE imesh_return)
+ endmacro (IMESH_GET_VARIABLE)
+ imesh_get_variable (IMESH_INCLUDEDIR imesh_includedir)
+ imesh_get_variable (IMESH_LIBDIR imesh_libdir)
+ imesh_get_variable (IMESH_LIBS imesh_libs_extra)
+ #file (REMOVE ${imesh_config_makefile})
- exec_program(${CMAKE_MAKE_PROGRAM}
- ARGS -f ${IMESH_CONFIG_MAKEFILE} show_libs
- OUTPUT_VARIABLE IMESH_LIBS_LINE
- RETURN_VALUE IMESH_RETURN)
+ # Confirm that iMesh.h is really there
+ find_path (imesh_includes_tmp iMesh.h HINTS ${imesh_includedir} NO_DEFAULT_PATH)
+ set (imesh_includes ${imesh_includes_tmp})
+ set (imesh_includes_tmp "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
+ find_path (imesh_includes_tmp iMeshP.h HINTS ${imesh_includedir} NO_DEFAULT_PATH)
+ if (imesh_includes_tmp)
+ set (IMESH_HAS_PARALLEL "YES")
+ else (imesh_includes_tmp)
+ set (IMESH_HAS_PARALLEL "NO")
+ endif (imesh_includes_tmp)
+ set (imesh_includes_tmp "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
- file (REMOVE ${IMESH_CONFIG_MAKEFILE})
+ set (IMESH_LIBRARY "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
+ find_library (IMESH_LIBRARY iMesh HINTS "${imesh_libdir}" NO_DEFAULT_PATH)
+ mark_as_advanced (IMESH_LIBRARY)
- # collect the includes and strip
- string (REGEX MATCHALL "-I([^\" ]+|\"[^\"]+\")" IMESH_ALL_INCLUDE_DIRS "${IMESH_INCLUDES_LINE}")
- set (IMESH_INCLUDE_DIRS_WORK)
- foreach (IPATH ${IMESH_ALL_INCLUDE_DIRS})
- string (REGEX REPLACE "^-I" "" IPATH ${IPATH})
- string (REGEX REPLACE "//" "/" IPATH ${IPATH})
- list (APPEND IMESH_INCLUDE_DIRS_WORK ${IPATH})
- endforeach (IPATH)
- list (REMOVE_DUPLICATES IMESH_INCLUDE_DIRS_WORK)
+ include (ResolveCompilerPaths)
- # scan tokens, find library with current library directories
- string (REGEX MATCHALL "(-L|-Wl,|-l)([^\" ]+|\"[^\"]+\")" IMESH_ALL_LINK_TOKENS "${IMESH_LIBS_LINE}")
- set (IMESH_LINK_PATHS)
- set (IMESH_LINK_FLAGS_WORK)
- set (IMESH_LIBRARIES_FOUND)
- set (IMESH_LIBRARIES_MISSING)
- foreach (TOKEN ${IMESH_ALL_LINK_TOKENS})
- if (TOKEN MATCHES "-L([^\" ]+|\"[^\"]+\")") # If it's a library path, prepend it to the list
- string (REGEX REPLACE "^-L" "" TOKEN ${TOKEN})
- string (REGEX REPLACE "//" "/" TOKEN ${TOKEN})
- list (INSERT IMESH_LINK_PATHS 0 ${TOKEN})
- elseif (TOKEN MATCHES "-Wl,([^\" ]+|\"[^\"]+\")") # If it's a link flag, put it in the flags list
- if (IMESH_LINK_FLAGS_WORK)
- set (IMESH_LINK_FLAGS_WORK "${IMESH_LINK_FLAGS_WORK} ${TOKEN}")
- else (IMESH_LINK_FLAGS_WORK)
- set (IMESH_LINK_FLAGS_WORK ${TOKEN})
- endif (IMESH_LINK_FLAGS_WORK)
- elseif (TOKEN MATCHES "-l([^\" ]+|\"[^\"]+\")") # If it's a library, get the absolute path by searching in IMESH_LINK_PATHS
- string (REGEX REPLACE "^-l" "" TOKEN ${TOKEN})
- set (IMESH_LIB "IMESH_LIB-NOTFOUND" CACHE FILEPATH "Cleared" FORCE)
- find_library (IMESH_LIB ${TOKEN} HINTS ${IMESH_LINK_PATHS})
- if (IMESH_LIB)
- list (APPEND IMESH_LIBRARIES_FOUND ${IMESH_LIB})
- else (IMESH_LIB)
- list (APPEND IMESH_LIBRARIES_MISSING ${IMESH_LIB})
- message (SEND_ERROR "Unable to find iMesh library ${TOKEN}")
- endif (IMESH_LIB)
- endif (TOKEN MATCHES "-L([^\" ]+|\"[^\"]+\")")
- endforeach (TOKEN)
- set (IMESH_LIB "IMESH_LIB-NOTFOUND" CACHE INTERNAL "Scratch variable for PETSc detection" FORCE)
- list (REMOVE_DUPLICATES IMESH_LIBRARIES_FOUND)
+ include (CheckCSourceRuns)
+ macro (IMESH_TEST_RUNS libraries runs)
+ multipass_c_source_runs (iMesh "${imesh_includes}" "${libraries}" "
+/* iMesh test program */
+#include \"iMesh.h\"
+#define CHK(err) if (err) return 1
+int main(int argc,char *argv[]) {
+ int ierr;
+ iMesh_Instance mesh;
+ iMesh_newMesh(\"\",&mesh,&ierr,0);CHK(ierr);
+ iMesh_dtor(mesh,&ierr);CHK(ierr);
+ return 0;
+}
+" ${runs})
+ if (${${runs}})
+ set (IMESH_EXECUTABLE_RUNS "YES" CACHE BOOL
+ "Can the system successfully run a iMesh executable? This variable can be manually set to \"YES\" to force CMake to accept a given iMesh configuration, but this will almost always result in a broken build. If you change IMESH_DIR, IMESH_DEFS_FILE, or IMESH_CURRENT you would have to reset this variable." FORCE)
+ endif (${${runs}})
+ endmacro (IMESH_TEST_RUNS)
- set (IMESH_INCLUDE_DIRS ${IMESH_INCLUDE_DIRS_WORK} CACHE STRING "iMesh include path" FORCE)
- set (IMESH_LIBRARIES ${IMESH_LIBRARIES_FOUND} CACHE STRING "iMesh libraries" FORCE)
-endif (IMESH_CONFIG_CURRENT AND IMESH_INCLUDE_DIRS AND IMESH_LIBRARIES)
+ imesh_test_runs ("${IMESH_LIBRARY}" imesh_works_minimal)
+ if (imesh_works_minimal)
+ message (STATUS "iMesh executable works when only linking to the interface libs, this probably means you have shared libs.")
+ set (imesh_libraries_needed "${IMESH_LIBRARY}")
+ else (imesh_works_minimal)
+ include (ResolveCompilerPaths)
+ resolve_libraries (imesh_libraries_needed "${imesh_libs_extra}")
+ imesh_test_runs ("${imesh_libraries_needed}" imesh_works_extra)
+ if (imesh_works_extra)
+ message (STATUS "iMesh executable requires linking to extra libs, this probably means it's statically linked.")
+ else (imesh_works_extra)
+ message (STATUS "iMesh could not be used, maybe the install is broken.")
+ endif (imesh_works_extra)
+ endif (imesh_works_minimal)
-set (IMESH_DEFS_FILE ${IMESH_DEFS_FILE} CACHE FILEPATH "iMesh makefile include")
+ set (IMESH_INCLUDES "${imesh_includes}" CACHE STRING "iMesh include path" FORCE)
+ set (IMESH_LIBRARIES "${imesh_libraries_needed}" CACHE STRING "iMesh libraries" FORCE)
+ mark_as_advanced (IMESH_INCLUDES IMESH_LIBRARIES IMESH_EXECUTABLE_RUNS)
+endif (NOT imesh_config_current)
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (iMesh
- "iMesh could not be found. Be sure to set IMESH_DEFS_FILE or have IMESH_DIR in your environment."
- IMESH_INCLUDE_DIRS IMESH_LIBRARIES)
-
-mark_as_advanced (IMESH_INCLUDE_DIRS IMESH_LIBRARIES)
+ "iMesh could not be found. Be sure to set IMESH_DIR or IMESH_DEFS_FILE or the environment variable IMESH_DIR."
+ IMESH_INCLUDES IMESH_LIBRARIES IMESH_EXECUTABLE_RUNS)
@@ -63,7 +63,7 @@ macro (RESOLVE_LIBRARIES LIBS LINK_LINE)
list (APPEND _libs_found ${_lib})
else (_lib)
message (STATUS "Unable to find library ${token}")
- endif (_lib)
+ endif (_lib)
endif (token MATCHES "-L([^\" ]+|\"[^\"]+\")")
endforeach (token)
set (_lib "NOTFOUND" CACHE INTERNAL "Scratch variable" FORCE)

0 comments on commit d8732ca

Please sign in to comment.