2
votes

I'm having problem getting the source and header files added into my Eclipse CDT project with CMake. In my test project (which generates and builds fine) I have the following CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)

project(WINCA)

file(GLOB WINCA_SRC_BASE "${WINCA_SOURCE_DIR}/src/*.cpp")
file(GLOB WINCA_SRC_HPP_BASE "${WINCA_SOURCE_DIR}/inc/*.hpp")

add_library(WINCABase ${WINCA_SRC_BASE} ${WINCA_SRC_HPP_BASE})

This works fine but the resulting Eclipse project files contains no links to the source or header files. Anyone knows why? Are there any other cmake command I have to use to actually add the files into the project?

3

3 Answers

5
votes

I realize it's been a while since you've post this, but fwiw, it work's for me fine with CMake 2.6 or 2.7 (trunk) versions, generating for Eclipse/Ganymede. What I do is first run

cmake -G "Eclipse CDT4 - Unix Makefiles" /path/to/src

which generates the Eclipse project files as well as the makefiles, then "Import Project" in Eclipse.

Works beautifully...

sly

3
votes

I use CMake 2.4, not 2.6 but in 2.4 they specifically warn against using GLOBs to find the files to build.

This is because it will notice if new files are added or deleted, so it will not be able to figure out the dependencies.

If you have to explicitly add the files to your CMakeLists.txt then this file will be newer than the makefiles and the cache files. So CMake will know to regenerate them.

If the files are added with a glob no files CMake knows about change with you add new files so CMake doesn't know that it has to regenerate the makefiles etc. This is the same for regular makefiles and Visual Studio projects.

Unless the CMake 2.6 docs explicitly says it is ok to add files like this I would avoid it. It is not that hard to manage the source files in cmake. How often do you add new files?

1
votes

The problem I had was I made an "in-source" build instead of an "out-of-source" build. Now it works fine, and it was actually lots of info on this on the Wiki but somehow I misunderstood it.