<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi, the simplest way AFAIK would be like</p>
<p><span style="font-family:monospace">install(<br>
TARGETS foo EXPORT Foo-config<br>
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}<br>
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}<br>
)</span></p>
<p>install(EXPORT Foo-config DESTINATION
${CMAKE_INSTALL_DATADIR}/Foo/cmake)</p>
<p>or</p>
<p>install(EXPORT Foo-config NAMESPACE foo: DESTINATION
${CMAKE_INSTALL_DATADIR}/Foo/cmake)</p>
<p>You could also do</p>
<p>set(CMAKE_EXPORT_PACKAGE_REGISTRY ON)<br>
export(TARGETS foo NAMESPACE foo:: FILE "Foo-config.cmake")<br>
export(PACKAGE Foo)<br>
</p>
<p>which puts the build directory in ~/.cmake (Unix|Linux) or a
registry key (Windows) so you don't have to do an install to build
against the package, but you can easily run into problems so it is
not recommended.</p>
<p>Note most docs will have the CamelCase syntax for config files
(e.g. FooConfig vs foo-config) but in my experience either form
works.<br>
</p>
<div class="moz-cite-prefix">On 11/14/2019 3:28 AM, Edvard Fagerholm
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAMF0iZ4gdqwwVW==tmmMntwJpBfRQMRqoC+W9t-NmwuJH8aQ4w@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr"><span style="font-family:monospace">Hi,<br>
<br>
I'm trying to get started with CMake in a personal project
having used other build system previously. The main reason to
try out CMake is that CUDA support sucks in Bazel. I see a lot
of conflicting information in tutorials and blog posts and I'm
trying to avoid going down the rabbit hole reading docs, so
I'm hoping someone can point me to the simplest way of doing
what I want.<br>
<br>
My template project has the following layout<br>
<br>
</span>
<div><span style="font-family:monospace">foo/CMakeLists.txt</span></div>
<div><span style="font-family:monospace"> /src/foo.cc</span></div>
<div><span style="font-family:monospace"> /foo.h</span></div>
<div><span style="font-family:monospace"> /internal/log.h</span></div>
<div><span style="font-family:monospace"><br>
</span></div>
<div><span style="font-family:monospace">The header foo.h should
after installation be usable as "#include <foo/foo.h>"
by users and the header in the internal subfolder should not
be installed. It should also be possible for a user to just
do:</span></div>
<div><span style="font-family:monospace"><br>
</span></div>
<div><span style="font-family:monospace">find_package(foo
REQUIRED)</span></div>
<div><span style="font-family:monospace">target_link_libraries(bar
PRIVATE foo)</span></div>
<div><span style="font-family:monospace"><br>
</span></div>
<div><span style="font-family:monospace">Some other minor
points:</span></div>
<div><span style="font-family:monospace"><br>
</span></div>
<div><span style="font-family:monospace">1. I want to use apply
the "-Wall -Werror" flags on my own code (not on deps or
force it on client code).<br>
</span></div>
<div><span style="font-family:monospace"><br>
</span></div>
<div><span style="font-family:monospace">2. My own code should
be compiled as C++17.<br>
</span></div>
<div><span style="font-family:monospace"><br>
</span></div>
<div><span style="font-family:monospace">I'm attaching my
current CMakeLists.txt below. What's currently missing is
that the library won't be found using "find_package", since
I haven't figured out the simplest way to accomplish this.
I'm also not sure whether I'm correctly and idiomatically.<br>
</span></div>
<div><span style="font-family:monospace"><br>
</span></div>
<div><span style="font-family:monospace">Anyone care to point on
non-idiomatic things in my file below as well as what the
simplest way is to make find_package work? My understanding
is that there are some packages that can automatically
generate the required files.<br>
</span></div>
<div><span style="font-family:monospace"><br>
</span></div>
<div><span style="font-family:monospace">==== start ====<br>
</span></div>
<div><span style="font-family:monospace">cmake_minimum_required(VERSION
3.15)<br>
project(foo<br>
VERSION 0.1<br>
DESCRIPTION "Foo project"<br>
LANGUAGES CXX<br>
)<br>
include(GNUInstallDirs)<br>
add_library(foo SHARED src/foo.cc)<br>
target_compile_options(foo PRIVATE -Wall)<br>
target_compile_options(foo PRIVATE -Werror)<br>
set_target_properties(foo PROPERTIES CXX_STANDARD 17)<br>
target_compile_features(foo PUBLIC cxx_std_17)<br>
<br>
target_include_directories(foo<br>
PUBLIC<br>
$<INSTALL_INTERFACE:include><br>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src><br>
PRIVATE<br>
${CMAKE_CURRENT_SOURCE_DIR}/src<br>
)</span></div>
<div><span style="font-family:monospace"><br>
install(<br>
TARGETS foo<br>
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}<br>
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}<br>
)<br>
install(<br>
FILES src/foo.h<br>
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/foo<br>
)<br>
</span></div>
<div><span style="font-family:monospace">==== end ===</span></div>
<div><span style="font-family:monospace"><br>
</span></div>
<div><span style="font-family:monospace">Best,</span></div>
<div><span style="font-family:monospace">Edvard<br>
</span></div>
<div><span style="font-family:monospace"></span><br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
</blockquote>
</body>
</html>