widberg / bgfx.cmake

https://github.com/bkaradzic/bgfx.cmake. Independently maintained CMake build scripts for bgfx. Released under public domain.
https://github.com/bkaradzic/bgfx.cmake
Creative Commons Zero v1.0 Universal
286 stars 252 forks source link

Use CMAKE_CURRENT_LIST_DIR instead of CMAKE_CURRENT_SOURCE_DIR #94

Closed Arcnor closed 4 years ago

Arcnor commented 4 years ago

This makes the project work inside subdirectories, as the path will be relative to the current CMakeList.txt file instead of the source, which could be another directory when this project is being integrated into another.

pezcode commented 4 years ago

CMAKE_CURRENT_SOURCE_DIR works fine when using add_subdirectory(bgfx.cmake). Are you trying to use include(bgfx.cmake/CMakeLists.txt)?

Arcnor commented 4 years ago

It doesn't on a subdirectory further away, like myLibs/bgfx.cmake, unless you have a Cmake file inside the intermediate directory I think.

handsomematt commented 4 years ago

For CMakeLists.txt added by add_subdirectory there will be no difference between CMAKE_CURRENT_LIST_DIR and CMAKE_CURRENT_SOURCE_DIR...

Generally the supported way is to just use add_subdirectory, which we have been doing on openblack without issue.

Arcnor commented 4 years ago

I'm doing add_subdirectory, but it fails without this change unless bgfx.cmake is in the same base directory, which is not what I need in this case. And as you quoted, it should continue working for everybody else.

pezcode commented 4 years ago

I'm doing add_subdirectory, but it fails without this change unless bgfx.cmake is in the same base directory, which is not what I need in this case. And as you quoted, it should continue working for everybody else.

What is CMAKE_CURRENT_SOURCE_DIR in that case? myLibs/?

handsomematt commented 4 years ago

Do other references to CMAKE_CURRENT_SOURCE_DIR have to be changed?

https://github.com/widberg/bgfx.cmake/search?q=CMAKE_CURRENT_SOURCE_DIR&unscoped_q=CMAKE_CURRENT_SOURCE_DIR

pezcode commented 4 years ago

I just tested these variables (with cmake 3.17 and 3.4), and it works as expected:

add_subdirectory(foo/bar)

CMAKE_SOURCE_DIR: S:/Coding/test/cmake-subdir CMAKE_CURRENT_SOURCE_DIR: S:/Coding/test/cmake-subdir/foo/bar CMAKE_CURRENT_LIST_DIR: S:/Coding/test/cmake-subdir/foo/bar

I'm thinking something else is weird with your setup, unless I missed something here.

Arcnor commented 4 years ago

I think you're right, I'm trying to use my project again without the changes and it doesn't fail. I'm not sure how I triggered it before, but as you can imagine I didn't open this PR to waste anybody's time, so it was a real issue for me :). I guess this can be closed, unless I can make it trigger again (my project is really simple, bgfx.cmake was the only dependency, so not sure what else might have changed).

Thanks for your time and sorry.