[CMake] Pure template libraries

Cristóvão Sousa crisjss at gmail.com
Wed Nov 12 07:24:19 EST 2008


Hi,

I'm having some trouble about creating the correct CMakeLists.txt files to 
deal with pure template libraries (header files only).

A simple sample:

I have 3 directories with a file in each one:
- Libbase
        '- base.hpp 
- Libderiv
         '- deriv.hpp
- Exec
     '- main.cpp

File main.cpp includes file deriv.hpp;
File deriv.hpp includes file base.hpp:
main.cpp --> deriv.hpp --> base.hpp


Right now I have the following cmake files:

root CMakeLists.txt :
	add_subdirectory(Libbase)
	add_subdirectory(Libderiv)
	add_subdirectory(Exec)

Libbase/CMakeLists.txt :
#empty

Libderiv/CMakeLists.txt :
#empty

Exec/CMakeLists.txt :
set(exec_SRCS main.cpp)
add_executable(exec ${exec_SRCS})
include_directories(${PROJECT_SOURCE_DIR}/base)
include_directories(${PROJECT_SOURCE_DIR}/deriv)


This works fine, but is a little bit annoying having to place  
"include_directories(${PROJECT_SOURCE_DIR}/base)"
in the Exec/CMakeLists.txt file. (because in the real project
I use a lot of pure template libraries which include a lot of 
other libraries, and often I don't remember them all.)

1- Is it possible to create a pure headers library with "add_library"?
   I tried passing only the header fine name but it complains about not
   knowing how to compile it.

2- And how can we make a include_directory be transitive, i.e.
   having a library XZY which "include_directory( ABC_DIR )",
   automatically do the "include_directory( ABC_DIR )" on any
   "target_link_libraries( EXECTARG XYZ)"?


I hope I'd been clear.


Thanks,
Cristóvão Sousa




















More information about the CMake mailing list