Closed Arcnor closed 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)
?
It doesn't on a subdirectory further away, like myLibs/bgfx.cmake
, unless you have a Cmake file inside the intermediate directory I think.
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.
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.
I'm doing
add_subdirectory
, but it fails without this change unlessbgfx.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/
?
Do other references to CMAKE_CURRENT_SOURCE_DIR have to be changed?
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.
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.
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.