[CMake] Help request for hierarchical directory example

David Aldrich david.aldrich.ntml at gmail.com
Fri Oct 18 06:52:58 EDT 2019


Hi



I'm learning how to use hierarchical directories in CMake and am trying to
get an example to work that I saw on YouTube. The example isn't doing what
I expect so I would be grateful for some help in understanding why.



I am running CMake 3.10.2 on Ubuntu 18.04 (Microsoft WSL) and using make.



I have a project called 'cmake-good' that should build library
'libsay-hello.a' and executable 'cmake-good'.



Here's the directory tree (excluding CMake artifacts which I don't think I
need to show):



├── CMakeLists.txt

├── build

│   ├── CMakeCache.txt

│   ├── CMakeFiles

│   ├── Makefile

│   ├── cmake_install.cmake

│   ├── hello-exe

│   │   ├── Makefile

│   │   ├── cmake-good

│   └── say-hello

│       ├── Makefile

│       └── libsay-hello.a

├── hello-exe

│   ├── CMakeLists.txt

│   └── main.cpp

├── say-hello

    ├── CMakeLists.txt

    └── src

        └── say-hello

            ├── hello.cpp

            └── hello.hpp



Here are the CMakeLists.txt files:



1) Top level CMakeLists.txt:



cmake_minimum_required(VERSION 3.10)

project(MyProject VERSION 1.0.0)

add_subdirectory(say-hello)

add_subdirectory(hello-exe)



2) hello_exe/CMakeLists.txt:



add_executable(cmake-good main.cpp )

target_link_libraries(cmake-good PRIVATE say-hello)



3) say-hello/CMakeLists.txt:



add_library(

    say-hello

    src/say-hello/hello.hpp

    src/say-hello/hello.cpp

)

target_include_directories(say-hello PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/src")



My problem is that I expect to see:



    hello-exe/cmake-good

    say-hello/libsay-hello.a



but I see:



    build\hello-exe\cmake-good

    build\say-hello\libsay-hello.a



Why is that?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20191018/dbae1fcf/attachment-0001.html>


More information about the CMake mailing list