From 6f2d003bc5aeba3e4448a9cb20818e8b40b34dc7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 24 Apr 2014 10:49:57 +0000 Subject: [PATCH] From Mattias Helsing, "Seems I was only half right given what you asked for. CMP0017 only says that modules that are found and ran from cmake modules dir should prefer cmake-provided modules. find_package() and include() still look in CMAKE_MODULE_PATH first. After some investigating I've come up with a proposal examplified in the attached FindGDAL.cmake script. It simply calls the cmake provided FindGDAL.cmake if it exists and returns if it succeeds in finding GDAL using that, otherwise continue with our local cmake code. Pro: Wont clutter our root CMakeLists.txt Con: If we begin to write more advanced Findxxx modules (using COMPONENTS, REQUIRED etc.) we may have to revise this scheme. " --- CMakeModules/FindGDAL.cmake | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeModules/FindGDAL.cmake b/CMakeModules/FindGDAL.cmake index 5006e6c72..7abccec53 100644 --- a/CMakeModules/FindGDAL.cmake +++ b/CMakeModules/FindGDAL.cmake @@ -19,6 +19,14 @@ # This makes the presumption that you are include gdal.h like # #include "gdal.h" +if(EXISTS ${CMAKE_ROOT}/Modules/FindGDAL.cmake) + include(${CMAKE_ROOT}/Modules/FindGDAL.cmake) + + if(GDAL_FOUND) + return() + endif() +endif() + FIND_PATH(GDAL_INCLUDE_DIR gdal.h PATHS $ENV{GDAL_DIR}