<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>