[CMake] organizing includes statements

Raymond Wan rwan.work at gmail.com
Thu Dec 10 03:20:38 EST 2015


Hi Owen,

Sorry to jump into the discussion, but what you're talking is
something I was thinking of just recently...

I think the choice between this:


On Thu, Dec 10, 2015 at 3:48 PM, Owen Alanzo Hogarth
<gurenchan at gmail.com> wrote:
> set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
> set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
> set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)


and this:


> it seems like this line in your reply above
> install( TARGETS lib1 lib2 DESTINATION lib )
> install( FILES lib1/headers/lib1.h lib2/headers/lib2.h DESTINATION include )


comes down to whether you want to compile other programs with these
libraries.  If you will not, then you can set the paths to
CMAKE_BINARY_DIR, which is the path to the top of the build tree.  As
far as I know, after you compile your program, you can/should delete
the build tree (i.e., assuming an out-of-source build).

So, most likely, you'd want to pick the second option if you need the
header files and archives to build something else.  This is because
when you run cmake, you can set the prefix to install files to (i.e.,
using "make install").  In my case, I only need header files and
archives to build something within a single build (i.e., various
inter-related subdirectories, all under one CMakeLists.txt).  So, I do
something similar to the first option.

I did toy with the second option a bit but, in the end, realized that
much of what I wrote won't be reused by another project of mine.  At
least, that's my understanding of the two options above...

Ray


More information about the CMake mailing list