tags:

views:

173

answers:

1

Hi SO,

I have two cmake-related problems: first, I can't make it to find the includes in the include folder, and it doesn't find the main.cpp file unless I place it in the same directory as the CMakeLists.txt. Can you please help me?

I have the following directory structure:

/TRT
 |
 +--- /src                 (bunch of .cpp files here)
       |
       +--- /include       (header files here)

The CMakeLists.txt is located in /TRT, main.cpp is located in /TRT/src, the includes are in /TRT/src/include.

I have written the following CMakeLists.txt and placed it in /TRT:

cmake_minimum_required( VERSION 2.6 )
project(TRT)
add_subdirectory(src)
include_directories( $(TRT_SOURCE_DIR)/include )
add_executable( trt main )
target_link_libraries( glut )

Thanks in advance

+1  A: 

I use the PARENT_SCOPE option. Here's a basic example:
#CMakeLists.txt in TRT/src
set(trtSources ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp PARENT_SCOPE)


#CMakeLists.txt in TRT
cmake_minimum_required( VERSION 2.6 )
project(TRT)
add_subdirectory(src)
include_directories( $(TRT_SOURCE_DIR)/src/include )
add_executable( trt ${trtSources} )
target_link_libraries( glut )

Stephen Newell
It's weird, because cmake drops warnings (it says it can't find main.cpp), but generates the Makefile. But it still doesn't work, it won't find the includes.
Tamás Szelei
I didn't notice your include directory was a subdirectory of src. Change the include_directories statement to include_directories( $(TRT_SOURCE_DIR)/src/include )
Stephen Newell
Thank you very much :)
Tamás Szelei
No problem. Glad to be of help.
Stephen Newell