Click here to Skip to main content
15,887,240 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can't seem to find this answer anywhere.

I have several libraries that are header-only due to being templatized.

What I'd like is to provide a CMakeLists.txt under each of them that exports their include folder as an include location, if that makes sense.

See what I've tried.

One option would be to include an empty cmake_dummy.cpp file with htcw_bits and other similar header only libraries just to give CMake something to bind to but this seems sloppy as heck.

Surely, they've thought of this use case and I'm just not looking in the right place.

What I have tried:

Note below, I'd like htcw_bits to have its own CMakeLists.txt to export a target_include_directory as PUBLIC:

However, I cannot do it since there are no source files with the htcw_bits project - only headers. If I try add_library(htcw_bits), it will fail.

C++
add_library(htcw_io lib/htcw_io/src/io_stream.cpp)
target_include_directories(htcw_io PUBLIC
"${PROJECT_SOURCE_DIR}/lib/htcw_bits/include"
"${PROJECT_SOURCE_DIR}/lib/htcw_io/include"
"${PROJECT_BINARY_DIR}")
Posted
Updated 2-Oct-23 5:10am
v4

1 solution

Declare using INTERFACE

add_library(htcw_bits INTERFACE)
target_include_directories(htcw_bits INTERFACE
    "${PROJECT_SOURCE_DIR}/include"
    "${PROJECT_BINARY_DIR}"
)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900