<div dir="ltr"><div dir="ltr"><div>Jason, thank you for the details. My port's original source is already constructing its own Find Module (Find<Package>.cmake). I am not constructing from scratch, or modifying the auto built one. I do not need to address the Package Configuration File at this time.</div><div><br></div><div>My only issue is the correct install location for this Find Module file. CMake's Find Module documentation [2] discusses the contents in great detail, but it does not say anything about where to install such file within a standard directory structure.</div><div><br></div><div>It looks like you are advising ${prefix}/share/cmake/Modules as the preferred install location within MacPorts context. This is for Find Module files published by one package, to be referenced by other packages, or by CMake defaulting, as needed. I will give that a try.</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Apr 25, 2025 at 10:41 AM Jason Liu <<a href="mailto:jasonliu@umich.edu" target="_blank">jasonliu@umich.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Of the paths you listed, if the path has the name of the <package>, then it very likely means that the port uses something called a "config-file package" [1]. This is something that is often related to us as software packagers, and is made up of "package configuration files" and "package version files". For a package named 'Foo', these files will have names that look something like 'FooConfig.cmake' and 'FooConfigVersion.cmake'. If you look at the documentation that I linked to, you will see that these files are usually placed in ${prefix}/lib/cmake/Foo. The config-file package files may be provided as an alternative to a CMake find module file (or sometimes provided in addition to a find module file).<br></div><div><br></div><div>Here are some general guidelines that I've found when dealing with packaging open source projects that use CMake, which seems to be the majority, these days. (None of this is documented anywhere, of course. It's just my personal experience, and my personal interpretation of the CMake documentation.)</div><div><br></div><div>* In general, you should never place any find module files inside ${prefix}/share/cmake-<cmakeVersion>/Modules. These are the default find modules that are provided by the CMake package itself.</div><div>* You CAN (and probably should) place your package's find module file inside ${prefix}/share/cmake/Modules.</div><div>* You can also place your package's find module file inside one of the package-specific paths you listed (e.g. ${prefix}/lib/cmake/Foo/modules), and then create a symlink from ${prefix}/share/cmake/Modules to the actual file. I've found that sometimes CMake is unable to resolve the symlink when compiling a port that depends on the port with my custom find module, regardless of what file permissions I put on both the symlink and the actual file. YMMV.</div><div><br></div><div>If you are going to be creating a find module file from scratch, you should try to follow the sample that is given in the CMake documentation that discusses CMake find modules [2]. This isn't always possible, because what the find module file looks like is highly dependent on how the source code is getting compiled. Still, you should use the sample as your starting point, and then modify accordingly.</div><div><br></div><div>Note that there are two strategies for getting the find module file into the final products of the package. The first is a MacPorts-specific solution:</div><div><br></div><div>post-destroot {</div><div> ...</div><div> # Install the CMake find module</div><div> set cmake_modules_dir ${prefix}/share/cmake/Modules</div><div> xinstall -d ${destroot}$cmake_modules_dir</div><div> copy ${filespath}/Find${github.author}.<a href="http://cmake.in" target="_blank">cmake.in</a> \</div><div> ${destroot}$cmake_modules_dir/Find${github.author}.cmake</div><div> ...</div><div>}</div><div><br></div><div>The second strategy is to create a patch that modifies 'CMakeLists.txt' to install your find module file for you during the compilation process.</div><div><br></div><div>If your find module file ends up working well, you may also want to consider submitting it upstream so that it gets included in the original project. This is where the second strategy pays off, since it's not MacPorts-specific.</div><div><br></div><div>[1] <a href="https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#package-layout" target="_blank">https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#package-layout</a></div><div>[2] <a href="https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#find-modules" target="_blank">https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#find-modules</a></div><div><br></div><div>P.S.: If you want to be super fancy, you may also want to consider creating a pkg-config file (Foo.pc) for your package. This will allow any downstream projects that are dependent on your package to find your package using either pkg-config OR CMake, and it also allows your CMake find module to utilize pkg-config to find your package<span> </span>(as discussed in the sample given in [2]). I have occasionally run into a situation where a library uses CMake to get compiled, but then the downstream application that depends on the library still uses autotools for its build. Obviously autotools can't use CMake's find_package(), but pkg-config is designed to be highly compatible with the autotools toolchain. So having both a CMake find module file and a pkg-config file allows the library to be used by a wider range of downstream projects. And again, if your pkg-config file works well, you should also submit it upstream to your package's source code.</div><div><br></div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>-- </div><div>Jason Liu</div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 24, 2025 at 10:56 PM Dave Allured - NOAA Affiliate via macports-dev <<a href="mailto:macports-dev@lists.macports.org" target="_blank">macports-dev@lists.macports.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">I am working on a port that tries to install its own Find<package>.cmake file. Is there a standard install directory, or "best" directory, to install such .cmake files?<div><br></div><div>A search of my current MacPorts installs finds multiple choices within $prefix; such as lib/cmake/<package>, lib/cmake/<package>/modules, libexec/<package>/lib/cmake, share/<package>/src, share/cmake/Modules, and share/<package>/cmake. There is also an include/<package> example that I don't trust because it is on the broken port that I am trying to fix.</div><div><br></div><div>I did not find guidance in MacPorts docs or Trac tickets. I hope someone on the dev list has experience in this. Any advice?</div></div>
</blockquote></div>
</blockquote></div></div>
</div>