Cannot "link" to interface library


I am working on a library (you can see the files structure here).
I have packaged and zipped it, I get it from a remote server with FetchContent and everything is (almost) fine.

In the root CMakeLists.txt, I added an INTERFACE library, and use it as target in a call to target_compile_options() (by using also INTERFACE).
In the src/ directory, I define a static library, and I link it to the interface library. No problem either.
In its directory, I export a configuration so that this static library may be built and delivered as a ZIP file.

When I want to use the interface library in an other CMake project (after having used FethContent), I get an error message telling the .lib cannot be found (of course : this interface library only define compilation switches).

What should I do ?

You may find a good example of a generated cmake-init-header-only library.

To help you, I would need to see your CMake files!

Nice project !

They’re mainly inspired by what is done here :

I added a level of hierarchy to add tests.

I also added, in the root CMakeLists.txt, this piece of code :

add_library(CommonConfig INTERFACE)
target_compile_features(CommonConfig INTERFACE cxx_std_17)
target_compile_options(CommonConfig INTERFACE
target_link_options(CommonConfig INTERFACE
$<$<CXX_COMPILER_ID:MSVC>:/INCREMENTAL>debugging / VisualStudio

I retrieve CommonConfig in the src directory by :

target_link_libraries(${PROJECT_NAME} PUBLIC CommonConfig)

But I am not sure how to retrieve it from the consumer.
After FetchContent_Declare(), FetchContent_MakeAvailable(), FetchContent_GetProperties() and find_package(), I can link to the binary library, but I am not sure how I am supposed to retrieve CommonConfig interface library from the library client.

If you need all the CMakeLists.txt, let me know.

if you link it this way, you have to export the config packages too!

Or you should use it like this:

target_link_libraries(${PROJECT_NAME} PRIVATE $<BUILD_INTERFACE:CommonConfig>)

Sorry to say it, this is not quite up to date:

  • FILE_SETS are not used!
  • header only libs are not handled!
  • cmake workflow preset are missing?
  • GitHub workflow (CI) is missing?

not quite up to date
FILE_SETS, header only libs, cmake workflow preset

From what I can see 3 years later since that blog post was published, none of the essentials became “not up to date” in there. But I can certainly agree that being a blog post it does not replace the entire “Professional CMake” book :slight_smile:

GitHub workflow (CI)

Did not know that this is required for everyone nowadays. So far we’ve been hosting our Git repositories with Gitea on internal network. I’ll ask around, could be that we are missing something.

You are right. A lot of new features has been added to CMake. :grinning: