Specifying include directories on the cmake command line

If the path to your headers is fixed in relation to your sources, then you should be able to avoid having to pass this info via the command line.

Say your project’s directory structure is:

/CMakeLists.txt
/my_sources/main.cpp
/my_sources/foo.cpp
/my_includes/foo.hpp

and in your CMakeLists.txt, you currently have something like:

add_executable(MyExe my_sources/main.cpp my_sources/foo.cpp)

then to add the /my_includes folder to the the list of include search paths, you only need to add the following:

include_directories(my_includes)

For further info about include_directories, run

cmake --help-command include_directories

Answer to update in question:

Yes, using the -D command line option just do

cmake . -DEO_SOURCE_DIR:PATH=<Path to required dir>

The variable ${EO_SOURCE_DIR} gets cached as a result of this, so you only need this -D argument once (unless the required path changes or you delete your CMakeCache file, etc.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)