So, I am making a part of the project a library with some headers that are the interface to the library, and the rest are private to the library itself. Therefore, for my library, the CMAKE part looks like this:
add_library(${PROJECT_NAME} ${PROJECT_SOURCES} "${PROJECT_BINARY_DIR}/libversion.h") add_library(my::lib ALIAS ${PROJECT_NAME}) target_include_directories(${PROJECT_NAME} PRIVATE ${Boost_INCLUDE_DIRS} PRIVATE ${PROJECT_BINARY_DIR}
And then my test goal:
add_executable(${TEST_NAME} ${TEST_SOURCES}) add_test(NAME LibTest COMMAND ${TEST_NAME}) target_link_libraries(${TEST_NAME} PRIVATE ${Boost_LIBRARIES} PRIVATE my::lib )
But this only allows me to check my public interface. If I want to unit test my library, how can I declare access to the remaining headers in the lib project? The way I see this would be to add a whole new purpose, my::lib::testing , which will declare the interface as the current source directory (where all the headers are currently located, separating the publication from the private headers, is another problem that I have not done it yet). So something like this:
add_library(${PROJECT_NAME}_TESTING ${PROJECT_SOURCES} "${PROJECT_BINARY_DIR}/libversion.h") add_library(my::lib::testing ALIAS ${PROJECT_NAME}_TESTING) target_include_directories(${PROJECT_NAME}_TESTING PRIVATE ${Boost_INCLUDE_DIRS} PRIVATE ${PROJECT_BINARY_DIR}
But this requires the creation of two different goals depending on the use. One for my application, associated with the my::lib alias, and one for unit testing, binding the my::lib::testing alias.
So my question is, how can I clearly separate the headers, so I can only have INTERFACE headers shown by goals, but still access the rest of the headers for my test purpose?
Sheph source share