I am attempting to use the generate_export_header function. My library source code is in the src folder, so CMake generates the export header at src/mylib_export.h. In order, to use this export header do I just copy it into my library’s include folder to use in the implementation code? Here is a snippet of the CMake code I’m using:
ADD_LIBRARY(${PROJECT_NAME} ${LIB_TYPE} ${SOURCES})
GENERATE_EXPORT_HEADER(${PROJECT_NAME})
FILE(COPY
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h
DESTINATION
${PROJECT_SOURCE_DIR}/include
)
Is there a more CMake way of doing this?
When I do this with CMake, I normally add the binary folder to the include_directories and do not copy the export header at all.
This way the source tree does not have any generated parts in it and this makes it simpler to use with source control and also I usually build my projects with more than 1 build tree per source tree mostly to allow building under more than 1 compiler or building with different settings or separate 32bit / 64 bit build trees with the same compiler.