[CMake] Advice on converting legacy project to modern CMake
Rolf Eike Beer
eike at sf-mail.de
Mon Aug 7 08:05:42 EDT 2017
Am 2017-08-07 11:57, schrieb Björn Blissing:
> Hi Eike,
>
>>> 3. Some of my legacy projects have all source in the same directory,
>>> i.e. both source and header files are in the same directory. Others
>>> have both private and public headers in the same directory. How do I
>>> handle this with target_include_directories()? Preferably I would
>>> like
>>> to avoid reorganizing the file structure.
>>
>> If things are in the same directory you don't need
>> target_include_directories(), as the header files will be found anyway
>> if you use "" (probably also <>). If they are in a different directory
>> it doesn't matter if the private and public things are mixed, you need
>> to add that directory anyway.
>
> Lets see if I understood what you are suggesting correctly:
>
> Alternative 1: If both source and headers are in the same directory.
> ===========
> Solution: Omit the target_include_directories() statement completely
> and just add the private and public header files in the add_library()
> statement and the public headers in the install(FILES ...) statement.
>
>
> Alternative 2: If source and headers are separated but both private
> and public headers are included in the same directory.
> ===========
> Solution: Add the private and public header files in the add_library()
> statement . Then add a target_include_directories() statement such as:
> target_include_directories(anvil_lib PUBLIC
> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
> $<INSTALL_INTERFACE:include>
> )
>
> Then add the public headers in the install(FILES ...) statement.
Yes.
> Is this correct? Follow up question: Since the directory include
> contains both public and private headers should the
> target_include_directories() be specified as PUBLIC or PRIVATE?
I would make it public: less code, and the private headers will simply
not exist when installed.
Eike
More information about the CMake
mailing list