<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<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 type="cite"
cite="mid:1625091624.2735098.1654620724969.JavaMail.zimbra@mbari.org">
<div>
<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 data-mce-style="font-family: 'courier new',
courier, monaco, monospace, sans-serif; font-size: 10pt;">#
Find package X</span></div>
<div><span 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 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 data-mce-style="clear: both;"><br data-mce-bogus="1">
</div>
<div data-mce-style="clear: both;">
<p 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
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 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 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>
<a class="moz-txt-link-abbreviated" href="mailto:oreilly@mbari.org">oreilly@mbari.org</a> (email)<br>
<a class="moz-txt-link-freetext" href="http://www.mbari.org">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" data-marker="__DIVIDER__">
<div data-marker="__HEADERS__"><b>From: </b>"Even Rouault"
<a class="moz-txt-link-rfc2396E" href="mailto:even.rouault@spatialys.com"><even.rouault@spatialys.com></a><br>
<b>To: </b>"Tom O'Reilly" <a class="moz-txt-link-rfc2396E" href="mailto:oreilly@mbari.org"><oreilly@mbari.org></a>,
"gdal-dev" <a class="moz-txt-link-rfc2396E" href="mailto:gdal-dev@lists.osgeo.org"><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 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"
moz-do-not-send="true" class="moz-txt-link-freetext">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"
moz-do-not-send="true" class="moz-txt-link-freetext">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"
moz-do-not-send="true" class="moz-txt-link-freetext">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"
moz-do-not-send="true" class="moz-txt-link-freetext">oreilly@mbari.org</a>
(email)<br>
<a href="http://www.mbari.org" target="_blank"
rel="nofollow noopener noreferrer"
moz-do-not-send="true" class="moz-txt-link-freetext">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" moz-do-not-send="true" class="moz-txt-link-freetext">gdal-dev@lists.osgeo.org</a>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank" rel="nofollow noopener noreferrer" moz-do-not-send="true" class="moz-txt-link-freetext">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" moz-do-not-send="true" class="moz-txt-link-freetext">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
<br>
</div>
</div>
</blockquote>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</body>
</html>