smallpants
smallpants

Reputation: 490

CMake cannot find existing file using absolute path

I'm trying to build an openFrameworks application (which is a nightmare in itself) and CMake refuses to acknowledge the existence of another CMake file necessary to link all of openFrameworks libraries. This other CMake file is linked with an absolute path and it still cannot be found using

set( OF_DIRECTORY_BY_USER "/home/jp/openframeworks" )
include(${OF_DIRECTORY_BY_USER}/addons/ofxCMake/modules/main.cmake)

The file is most definitely in that path. I can see it in terminal and in the explorer.

The full error:

CMake Error at CMakeLists.txt:44 (include):
  include could not find load file:

    /home/jp/openframeworks/addons/ofxCMake/modules/main.cmake


-- Configuring incomplete, errors occurred!

The project's CMakeLists.txt resides in the main project directory but I don't think this should be a problem considering I'm not using relative paths.

Upvotes: 1

Views: 1908

Answers (2)

smallpants
smallpants

Reputation: 490

So rather embarrassingly, I didn't realize that the actual directory was openFrameworks not openframeworks. This is what happens at 2:00 in the morning...

Upvotes: 1

Matt
Matt

Reputation: 385

Could you try the following:

Add the path that contains additional cmake files, in your case /home/jp/openframeworks/addons/ofxCMake/modules, to the CMAKE_MODULE_PATH. The cmake executable will look through the list of folders stored in that variable when it searches for cmake files.

# In your top-level CMakeLists.txt
list(APPEND CMAKE_MODULE_PATH /home/jp/openframeworks/addons/ofxCMake/modules/cmake)

Note that, once you get it working you could, instead of hard-coding the full path to the cmake folder that holds your custom modules, use variables managed by the cmake executable to make your cmake files more portable. E.g.:

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/addons/ofxCMake/modules/cmake)

Then use it, either in the same top-level file, or in a cmake file that has been brought into the build via a add_subdirectory call.

include(main)

See https://cgold.readthedocs.io/en/latest/tutorials/cmake-sources/includes.html#include-custom for a nice tutorial on this topic.

Upvotes: 2

Related Questions