<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div>Thanks for this information Even - very useful and interesting.</div><div><br data-mce-bogus="1"></div><div>I'm still a cmake newbie, and one cmake aspect that drives me nuts is its "inconsistency" when it comes to finding packages ("Should I call find_package(X) with MODULE or CONFIG?", "Is it X_INCLUDE_DIRS or X_INCLUDES?"). So my CMakeLists.txt tend to get complex pretty quickly. </div><div><br data-mce-bogus="1"></div><div>The method you describe looks elegant and straightforward, and it works for GDAL. In general for package 'X', is the following *guaranteed* to produce a usable target of form "X::X" or exit if package X is not found?</div><div><br data-mce-bogus="1"></div><blockquote><div><span style="font-family: "courier new", courier, monaco, monospace, sans-serif; font-size: 10pt;" data-mce-style="font-family: 'courier new', courier, monaco, monospace, sans-serif; font-size: 10pt;"># Find package X</span></div><div><span style="color: rgb(0, 0, 0); font-family: "courier new", courier, monaco, monospace, sans-serif; font-size: 10pt; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;" data-mce-style="color: #000000; font-family: 'courier new', courier, monaco, monospace, sans-serif; font-size: 10pt; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;">find_package(X CONFIG REQUIRED)</span><br style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;" data-mce-style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div style="clear: both;" data-mce-style="clear: both;"><br data-mce-bogus="1"></div><div style="clear: both;" data-mce-style="clear: both;"><p style="color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; margin: 0px;" data-mce-style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; margin: 0px;"><span style="font-family: "courier new", courier, monaco, monospace, sans-serif; font-size: 10pt;" data-mce-style="font-family: 'courier new', courier, monaco, monospace, sans-serif; font-size: 10pt;">add_executable(test_c test_c.c)</span><br><span style="font-family: "courier new", courier, monaco, monospace, sans-serif; font-size: 10pt;" data-mce-style="font-family: 'courier new', courier, monaco, monospace, sans-serif; font-size: 10pt;">target_link_libraries(test_c PRIVATE X::X)</span></p></div></div><div><span style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;" data-mce-style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"><br data-mce-bogus="1"></span></div></blockquote><div>If I could rely on that form, my CMakeLists.txt files would be much simpler!</div><div><br data-mce-bogus="1"></div><div>Thanks</div><div>Tom</div><div><br data-mce-bogus="1"></div><div data-marker="__SIG_PRE__">--------------------------------------------------<br>Thomas C. O'Reilly<br>Monterey Bay Aquarium Research Institute<br>7700 Sandholdt Road<br>Moss Landing, California 95039-9644<br>831-775-1766 (voice)<br>831-775-1620 (FAX)<br>oreilly@mbari.org (email)<br>http://www.mbari.org (World-wide Web)<br> <br>"The machine does not isolate us from the great mysteries<br> of nature, but plunges us more deeply into them."<br> <br>   - ANTOINE DE SAINT-EXUPERY<br>     "Wind, Sand, and Stars" (1939)<br> </div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><b>From: </b>"Even Rouault" <even.rouault@spatialys.com><br><b>To: </b>"Tom O'Reilly" <oreilly@mbari.org>, "gdal-dev" <gdal-dev@lists.osgeo.org><br><b>Sent: </b>Tuesday, June 7, 2022 12:28:42 AM<br><b>Subject: </b>Re: [gdal-dev] Why can't find_package(GDAL CONFIG) find GDAL_LIBRARIES?<br></div><div><br></div><div data-marker="__QUOTED_TEXT__"><p>Tom,</p>
    <p>GDAL_LIBRARIES
        and GDAL_INCLUDE_DIRS are indeed not defined. You have to use
        the "GDAL::GDAL" target in a <br>
      target_link_libraries()
        statement which propagates both include and linking requirements
        and tends to be the modern CMake practice, although admitedly
        not very clearly documented in target_link_libraries() official
        documentation. I found
<a href="https://schneide.blog/2016/04/08/modern-cmake-with-target_link_libraries/" target="_blank" rel="nofollow noopener noreferrer">https://schneide.blog/2016/04/08/modern-cmake-with-target_link_libraries/</a>
        which deal with that.<br>
      </p>
    <p>So a typical
        minimum CMakeLists.txt of a project using GDAL is (this is
        actually
<a href="https://github.com/OSGeo/gdal/blob/master/autotest/postinstall/test_c/CMakeLists.txt" target="_blank" rel="nofollow noopener noreferrer">https://github.com/OSGeo/gdal/blob/master/autotest/postinstall/test_c/CMakeLists.txt</a>
        used in GDAL continuous integration to test usage of GDAL from a
        third-party library/application)<br>
      </p>
    <p>"""<br>
      </p>
    <p>cmake_minimum_required(VERSION 3.0)<br>
      <br>
      project(test_c C CXX) # CXX for properly linking GDAL<br>
      <br>
      find_package(GDAL CONFIG REQUIRED)<br>
      <br>
      add_executable(test_c test_c.c)<br>
      target_link_libraries(test_c PRIVATE GDAL::GDAL)</p>
    <p>"""</p>
    <p>I've created <a href="https://github.com/OSGeo/gdal/issues/5875" target="_blank" rel="nofollow noopener noreferrer">https://github.com/OSGeo/gdal/issues/5875</a> to track
      we need documenting that.</p>
    <p>Note: If you really wanted to get the equivalent of GDAL_INCLUDE_DIRS and
        GDAL_LIBRARIES, you could use the following expressions:<br>
      </p>
    <p>$<TARGET_PROPERTY:GDAL::GDAL,INTERFACE_INCLUDE_DIRECTORIES></p>
    <p>$<TARGET_PROPERTY:GDAL::GDAL,INTERFACE_LINK_LIBRARIES></p>
    <p><br>
    </p>
    <p>Even<br>
    </p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">Le 07/06/2022 à 02:02, Tom O'Reilly a
      écrit :<br>
    </div>
    <blockquote>
      <div>
        <div>I've just
            built and installed GDAL 3.5.0 on ubuntu 20.04, with cmake
            3.5.0 and make. It appears that 'make install' installs
            needed cmake config files for GDAL:</div>
        <div>
          <blockquote>
            <div>-- Installing:
                /usr/local/lib/x86_64-linux-gnu/cmake/gdal/GDALConfigVersion.cmake</div>
            <div>-- Installing:
                /usr/local/lib/x86_64-linux-gnu/cmake/gdal/GDALConfig.cmake</div>
          </blockquote>
        </div>
        <div>I'm
            building my own project that uses GDAL. The CMakelists.txt
            invokes find_package() and prints out resulting variables:</div>
        <div>
          <blockquote>
            <div>find_package(GDAL CONFIG REQUIRED)</div>
            <div><br>
            </div>
            <div>if (GDAL_FOUND)</div>
            <div>  message("GDAL Found!")</div>
            <div>  message("GDAL_INCLUDE_DIRS:
                ${GDAL_INCLUDE_DIRS}")</div>
            <div>  message("GDAL_LIBRARIES: ${GDAL_LIBRARIES}")</div>
            <div>  message("GDAL_VERSION: ${GDAL_VERSION}")</div>
            <div>else()</div>
            <div>  message("GDAL not found")</div>
            <div>endif()</div>
          </blockquote>
          <div>Running
              cmake indicates that GDAL_FOUND is true, GDAL_VERSION is
              set to the expected value(3.5.0), but GDAL_LIBRARIES and
              GDAL_INCLUDE_DIRS are empty:</div>
          <div>
            <blockquote>
              <div>GDAL Found!</div>
              <div>GDAL_INCLUDE_DIRS: </div>
              <div>GDAL_LIBRARIES: </div>
              <div>GDAL_LIBRARY: </div>
              <div>GDAL_VERSION: 3.5.0</div>
            </blockquote>
          </div>
          <div>Why are GDAL_LIBRARIES and GDAL_INCLUDE_DIR empty?<br>
          </div>
          <div><br>
          </div>
          <div>Thanks</div>
          <div>Tom</div>
          <div><br>
          </div>
          <blockquote>
            <div><br>
            </div>
          </blockquote>
        </div>
        <div><br>
        </div>
        <div>--------------------------------------------------<br>
          Thomas C.
            O'Reilly<br>
          Monterey
            Bay Aquarium Research Institute<br>
          7700
            Sandholdt Road<br>
          Moss
            Landing, California 95039-9644<br>
          831-775-1766
            (voice)<br>
          831-775-1620
            (FAX)<br>
          <a href="mailto:oreilly@mbari.org" target="_blank" rel="nofollow noopener noreferrer">oreilly@mbari.org</a>
            (email)<br>
          <a href="http://www.mbari.org" target="_blank" rel="nofollow noopener noreferrer">http://www.mbari.org</a>
            (World-wide Web)<br>
           <br>
          "The
            machine does not isolate us from the great mysteries<br>
           of nature,
            but plunges us more deeply into them."<br>
           <br>
             -
            ANTOINE DE SAINT-EXUPERY<br>
               "Wind,
            Sand, and Stars" (1939)<br>
           </div>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre">_______________________________________________
gdal-dev mailing list
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank" rel="nofollow noopener noreferrer">gdal-dev@lists.osgeo.org</a>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank" rel="nofollow noopener noreferrer">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
    </blockquote>
    <pre class="moz-signature">-- 
<a href="http://www.spatialys.com" target="_blank" rel="nofollow noopener noreferrer">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre><br></div></div></body></html>