Re: [CMake] Pure template libraries
On Wednesday 12 November 2008 16:00:32 Eric Noulard wrote: > 2008/11/12 Cristóvão Sousa <[EMAIL PROTECTED]>: > > > > This two doesn't help because I also need to know which are the hpp files > > included by the one the executable includes. (This is true for compiled > > libraries too, right?) > > Yes, when executable uses "classical" lib you have to: > > TARGET_LINK_LIBRARIES(YOUR_EXE_TARGET YOURLIB1 YOURLIB2) etc... > But if in YOURLIB1 I do TARGET_LINK_LIBRARIES(YOURLIB1 YOURLIB2) then in YOUR_EXE_TARGET I only need to do TARGET_LINK_LIBRARIES(YOUR_EXE_TARGET YOURLIB1) So, in one hand, I don't need to know that YOURLIB1 needs YOURLIB2. OTHO, I have to know, because of the include files... Taking headers files into account, the sample above will be For YOURLIB1: INCLUDE_DIRECTORIES( YOURLIB2_DIR ) TARGET_LINK_LIBRARIES( YOURLIB1 YOURLIB2 ) For YOUR_EXE_TARGET: # Here I have to include YOURLIB2_DIR INCLUDE_DIRECTORIES( YOURLIB2_DIR YOURLIB1_DIR ) TARGET_LINK_LIBRARIES( YOUR_EXE_TARGET YOURLIB1 ) What I said is correct, isn't it? ___ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake
[CMake] Pure template libraries
2008/11/12 Cristóvão Sousa <[EMAIL PROTECTED]>: > On Wednesday 12 November 2008 12:58:08 "Eric Noulard" <[EMAIL PROTECTED]> > wrote: >> 2008/11/12 Cristóvão Sousa <[EMAIL PROTECTED]>: >> > >> > 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) add them explicitely to your exe sources files: >> >> 2) Or may be defining "template lib" > > This two doesn't help because I also need to know which are the hpp files > included by the one the executable includes. (This is true for compiled > libraries too, right?) Yes, when executable uses "classical" lib you have to: TARGET_LINK_LIBRARIES(YOUR_EXE_TARGET YOURLIB1 YOURLIB2) etc... >> 3) export them somewhere in your build tree and include_directory the >> choosen place: >> >>Libbase/CMakeLists.txt : >>CONFIGURE_FILE(base.hpp build_include) this is a mistake one should read: CONFIGURE_FILE(base.hpp build_include/base.hpp @COPYONLY) >> >>Libderiv/CMakeLists.txt : >>CONFIGURE_FILE(deriv.hpp build_include) same here: CONFIGURE_FILE(deriv.hpp build_include/deriv.hpp @COPYONLY) >>Exec/CMakeLists.txt : >>include_directories(build_include) >>set(exec_SRCS main.cpp) >>add_executable(exec ${exec_SRCS}) > > This is a little better, however I cannot managed to define "build_include" build_include in my example was meant to be a directory name located in the build tree. CONFIGURE_FILE(deriv.hpp build_include/deriv.hpp @COPYONLY) should create the directory if needed, if it is not the case you should file(MAKE_DIRECTORY build_include) before CONFIGURE_FILE(... You may specify it using absolute path: ${CMAKE_BINARY_DIR}/build_include > correctly. I set(BUILD_INCS_DIR ./build_incs), but no good... Sorry for the wrong tips -- Erk ___ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Pure template libraries
2008/11/12 Cristóvão Sousa <[EMAIL PROTECTED]>: > 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)"? If your header are somehow "public" since they must be included by other part of the porject you may either: 1) add them explicitely to your exe sources files: set(exec_SRCS main.cpp ../ Libbase/base.hpp ../Libderiv/deriv.hpp) 2) Or may be defining "template lib" like (note the PARENT_SCOPE in SET) Libbase/CMakeLists.txt : SET(TLIB_BASE ${CMAKE_CURRENT_SOURCE_DIR}/base.hpp PARENT_SCOPE) Libderiv/CMakeLists.txt : SET(TLIB_DERIV ${CMAKE_CURRENT_SOURCE_DIR}/deriv.hpp PARENT_SCOPE) Exec/CMakeLists.txt : set(exec_SRCS main.cpp ${TLIB_BASE} ${TLIB_DERIV}) add_executable(exec ${exec_SRCS}) 3) export them somewhere in your build tree and include_directory the choosen place: Libbase/CMakeLists.txt : CONFIGURE_FILE(base.hpp build_include) Libderiv/CMakeLists.txt : CONFIGURE_FILE(deriv.hpp build_include) Exec/CMakeLists.txt : include_directories(build_include) set(exec_SRCS main.cpp) add_executable(exec ${exec_SRCS}) I did not test my proposal, but I think they should work. -- Erk ___ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake
[CMake] Pure template libraries
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 ___ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake