summaryrefslogtreecommitdiffstats
path: root/Modules/FindSWIG.cmake
diff options
context:
space:
mode:
authorSeth R Johnson <johnsonsr@ornl.gov>2021-05-02 14:01:31 (GMT)
committerSeth R Johnson <johnsonsr@ornl.gov>2021-05-02 14:05:44 (GMT)
commitff6f7b232fbe36d8cb237ca2508ca01632d9d9d2 (patch)
treed21baab346dcf57a5841bc3133f50e31912a1a72 /Modules/FindSWIG.cmake
parent4f88cb1675cf2fe50459eb4cc321a0d4b36c6c33 (diff)
downloadCMake-ff6f7b232fbe36d8cb237ca2508ca01632d9d9d2.zip
CMake-ff6f7b232fbe36d8cb237ca2508ca01632d9d9d2.tar.gz
CMake-ff6f7b232fbe36d8cb237ca2508ca01632d9d9d2.tar.bz2
FindSWIG: reduce calls to SWIG exe, and clean up variables
If all SWIG cache variables (EXECUTABLE, DIR, VERSION) are set, there should be no need to invoke the SWIG exe on a reconfigure. This changeset reduces the number of calls to the SWIG executable, and additonially prevents temporary `SWIG_xxx` values from propagating outside the `find_package` call. I also refactored the conditionals to be less nested (and thus more predictable), including changing theh definition of SWIG_USE_FILE to reflect that it's if and only if SWIG_FOUND is trure.
Diffstat (limited to 'Modules/FindSWIG.cmake')
-rw-r--r--Modules/FindSWIG.cmake92
1 files changed, 54 insertions, 38 deletions
diff --git a/Modules/FindSWIG.cmake b/Modules/FindSWIG.cmake
index 4c7ad89..73aec89 100644
--- a/Modules/FindSWIG.cmake
+++ b/Modules/FindSWIG.cmake
@@ -87,56 +87,68 @@ if (NOT _SWIG_NAMES)
endif()
find_program(SWIG_EXECUTABLE NAMES ${_SWIG_NAMES} swig)
+unset(_SWIG_NAMES)
-if(SWIG_EXECUTABLE)
+if(SWIG_EXECUTABLE AND NOT SWIG_DIR)
+ # Find default value for SWIG library directory
execute_process(COMMAND ${SWIG_EXECUTABLE} -swiglib
- OUTPUT_VARIABLE SWIG_swiglib_output
- ERROR_VARIABLE SWIG_swiglib_error
- RESULT_VARIABLE SWIG_swiglib_result)
+ OUTPUT_VARIABLE _swig_output
+ ERROR_VARIABLE _swig_error
+ RESULT_VARIABLE _swig_result)
- if(SWIG_swiglib_result)
+ if(_swig_result)
+ set(_msg "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${_swig_error}")
if(SWIG_FIND_REQUIRED)
- message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
+ message(SEND_ERROR "${_msg}")
else()
- message(STATUS "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
+ message(STATUS "${_msg}")
endif()
+ unset(_msg)
else()
- string(REGEX REPLACE "[\n\r]+" ";" SWIG_swiglib_output ${SWIG_swiglib_output})
- find_path(SWIG_DIR swig.swg PATHS ${SWIG_swiglib_output} NO_CMAKE_FIND_ROOT_PATH)
- if(SWIG_DIR)
- set(SWIG_USE_FILE ${CMAKE_CURRENT_LIST_DIR}/UseSWIG.cmake)
- execute_process(COMMAND ${SWIG_EXECUTABLE} -version
- OUTPUT_VARIABLE SWIG_version_output
- ERROR_VARIABLE SWIG_version_output
- RESULT_VARIABLE SWIG_version_result)
- if(SWIG_version_result)
- message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -version\" failed with output:\n${SWIG_version_output}")
- else()
- string(REGEX REPLACE ".*SWIG Version[^0-9.]*\([0-9.]+\).*" "\\1"
- SWIG_version_output "${SWIG_version_output}")
- set(SWIG_VERSION ${SWIG_version_output} CACHE STRING "Swig version" FORCE)
- endif()
- endif()
+ string(REGEX REPLACE "[\n\r]+" ";" _SWIGLIB ${_swig_output})
endif()
+endif()
- if(SWIG_FIND_COMPONENTS)
- execute_process(COMMAND ${SWIG_EXECUTABLE} -help
- OUTPUT_VARIABLE SWIG_swighelp_output
- ERROR_VARIABLE SWIG_swighelp_error
- RESULT_VARIABLE SWIG_swighelp_result)
- if(SWIG_swighelp_result)
- message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -help\" failed with output:\n${SWIG_swiglib_error}")
- else()
- string(REPLACE "\n" ";" SWIG_swighelp_output "${SWIG_swighelp_output}")
- foreach(SWIG_line IN LISTS SWIG_swighelp_output)
- if(SWIG_line MATCHES "-([A-Za-z0-9_]+) +- *Generate.*wrappers")
- set(SWIG_${CMAKE_MATCH_1}_FOUND TRUE)
- endif()
- endforeach()
- endif()
+# Find SWIG library directory
+find_path(SWIG_DIR swig.swg PATHS ${_SWIGLIB} NO_CMAKE_FIND_ROOT_PATH)
+unset(_SWIGLIB)
+
+if(SWIG_EXECUTABLE AND SWIG_DIR AND NOT SWIG_VERSION)
+ # Determine SWIG version
+ execute_process(COMMAND ${SWIG_EXECUTABLE} -version
+ OUTPUT_VARIABLE _swig_output
+ ERROR_VARIABLE _swig_output
+ RESULT_VARIABLE _swig_result)
+ if(_swig_result)
+ message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -version\" failed with output:\n${_swig_output}")
+ else()
+ string(REGEX REPLACE ".*SWIG Version[^0-9.]*\([0-9.]+\).*" "\\1"
+ _swig_output "${_swig_output}")
+ set(SWIG_VERSION ${_swig_output} CACHE STRING "Swig version" FORCE)
endif()
endif()
+if(SWIG_EXECUTABLE AND SWIG_FIND_COMPONENTS)
+ execute_process(COMMAND ${SWIG_EXECUTABLE} -help
+ OUTPUT_VARIABLE _swig_output
+ ERROR_VARIABLE _swig_error
+ RESULT_VARIABLE _swig_result)
+ if(_swig_result)
+ message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -help\" failed with output:\n${_swig_error}")
+ else()
+ string(REPLACE "\n" ";" _swig_output "${_swig_output}")
+ foreach(SWIG_line IN LISTS _swig_output)
+ if(SWIG_line MATCHES "-([A-Za-z0-9_]+) +- *Generate.*wrappers")
+ set(SWIG_${CMAKE_MATCH_1}_FOUND TRUE)
+ endif()
+ endforeach()
+ endif()
+endif()
+
+unset(_swig_output)
+unset(_swig_error)
+unset(_swig_result)
+
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(
SWIG HANDLE_COMPONENTS
@@ -144,4 +156,8 @@ find_package_handle_standard_args(
VERSION_VAR SWIG_VERSION
HANDLE_VERSION_RANGE)
+if(SWIG_FOUND)
+ set(SWIG_USE_FILE "${CMAKE_CURRENT_LIST_DIR}/UseSWIG.cmake")
+endif()
+
mark_as_advanced(SWIG_DIR SWIG_VERSION SWIG_EXECUTABLE)