<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div>Hi Even,</div><div><br data-mce-bogus="1"></div><div>You write:</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;">> There's no universal way however of knowing the X::Y target name for a random package. You have to consult each package's documentation.<span> </span></span><div style="clear: both;" data-mce-style="clear: both;"><br data-mce-bogus="1"></div></div><div>Where is this typically documented?  For example, where can I find GDAL package documentation? I looked in the <a data-mce-href="https://gdal.org/gdal.pdf" href="https://gdal.org/gdal.pdf">main GDAL document</a> but didn't find it there (I might have missed it there...)</div><div><br data-mce-bogus="1"></div><div>Thanks!</div><div>Tom</div><div> </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><br><b>Cc: </b>"gdal-dev" <gdal-dev@lists.osgeo.org><br><b>Sent: </b>Tuesday, June 7, 2022 10:10:26 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>That becomes slightly out-of-topic, but CMake practices have
      evolved over time. Having depencies expressed from target name is
      indeed more elegant/powerful. There's no universal way however of
      knowing the X::Y target name for a random package. You have to
      consult each package's documentation. One good reason is that the
      same package can expose several targets (sub-components, shared vs
      static, etc.)<br>
    </p>
    <div class="moz-cite-prefix">Le 07/06/2022 à 18:52, Tom O'Reilly a
      écrit :<br>
    </div>
    <blockquote>
      <div>
        <div>Thanks for this information Even - very useful and
          interesting.</div>
        <div><br>
        </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>
        </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>
        </div>
        <blockquote>
          <div>#
              Find package X</div>
          <div>find_package(X CONFIG
              REQUIRED)<br>
            <div><br>
            </div>
            <div>
              <p>add_executable(test_c
                  test_c.c)<br>
                target_link_libraries(test_c PRIVATE X::X)</p>
            </div>
          </div>
          <div><br>
            </div>
        </blockquote>
        <div>If I could rely on that form, my CMakeLists.txt files would
          be much simpler!</div>
        <div><br>
        </div>
        <div>Thanks</div>
        <div>Tom</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>
        </div>
        <hr id="zwchr">
        <div><b>From: </b>"Even Rouault"
          <a href="mailto:even.rouault@spatialys.com" target="_blank" rel="nofollow noopener noreferrer"><even.rouault@spatialys.com></a><br>
          <b>To: </b>"Tom O'Reilly" <a href="mailto:oreilly@mbari.org" target="_blank" rel="nofollow noopener noreferrer"><oreilly@mbari.org></a>,
          "gdal-dev" <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank" rel="nofollow noopener noreferrer"><gdal-dev@lists.osgeo.org></a><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>
          <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/" rel="nofollow noopener noreferrer nofollow noopener noreferrer" target="_blank">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" rel="nofollow noopener noreferrer nofollow noopener noreferrer" target="_blank">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" rel="nofollow noopener noreferrer nofollow noopener noreferrer" target="_blank">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" rel="nofollow noopener noreferrer nofollow noopener noreferrer" target="_blank">oreilly@mbari.org</a>
                (email)<br>
                <a href="http://www.mbari.org" rel="nofollow noopener noreferrer nofollow noopener noreferrer" target="_blank">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" rel="nofollow noopener noreferrer nofollow noopener noreferrer" target="_blank">gdal-dev@lists.osgeo.org</a>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="nofollow noopener noreferrer nofollow noopener noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
          </blockquote>
          <pre class="moz-signature">-- 
<a href="http://www.spatialys.com" rel="nofollow noopener noreferrer nofollow noopener noreferrer" target="_blank">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
          <br>
        </div>
      </div>
    </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>