elements icon indicating copy to clipboard operation
elements copied to clipboard

Should the current working dir be added automatically to search paths?

Open MoAlyousef opened this issue 4 years ago • 6 comments

Hello Thanks for working on elements. This is more of a question than an issue.

I use CMake's fetch content to add elements as a dependency, cmake also fetches other git submodules automatically:

cmake_minimum_required(VERSION 3.15)
project(app)

set(ELEMENTS_BUILD_EXAMPLES OFF CACHE BOOL " " FORCE)

include(FetchContent)
FetchContent_Declare(elements GIT_REPOSITORY https://github.com/cycfi/elements)
FetchContent_MakeAvailable(elements)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE cycfi::elements)

The problem is adding resources via ELEMENTS_APP_RESOURCES won't work in that setup, and add_search_path("."); feels like it should be implied.

MoAlyousef avatar Apr 06 '21 23:04 MoAlyousef

Sorry, I can't see a question there. Can you make the question more explicit?

djowel avatar Apr 07 '21 00:04 djowel

Sorry, I can't see a question there. Can you make the question more explicit?

Ah... the question is in the title. Well, if you think you have a way to improve the cmake build, I'll welcome a PR.

djowel avatar Apr 07 '21 00:04 djowel

Sure. I’ll have a go at it.

MoAlyousef avatar Apr 07 '21 00:04 MoAlyousef

So I found a solution to using fetchContent without having to modify element's cmake files. It also allows the use of elements' bundled fonts and other resources, and allows specifying a resource dir for my test project. The minimal CMakeLists.txt looks like:

cmake_minimum_required(VERSION 3.15)
project(elements_example)

set(ELEMENTS_BUILD_EXAMPLES OFF CACHE BOOL " " FORCE)

include(FetchContent)
FetchContent_Declare(elements GIT_REPOSITORY https://github.com/cycfi/elements)
FetchContent_MakeAvailable(elements)

set(ELEMENTS_ROOT ${elements_SOURCE_DIR})
set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${ELEMENTS_ROOT}/cmake")

set(ELEMENTS_APP_PROJECT "app")

set(ELEMENTS_APP_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/resources/ex.png)

include(ElementsConfigApp)

MoAlyousef avatar Apr 10 '21 22:04 MoAlyousef

Looks good. Perhaps the examples could make use of that as well. I'd welcome a PR.

djowel avatar Apr 10 '21 23:04 djowel

Using fetchContent in the examples dir seems out of place. I could add it to the setup docs, assuming it's under the qplug_api_changes branch.

MoAlyousef avatar Apr 11 '21 17:04 MoAlyousef