-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake: usage of CMAKE_SOURCE_DIR in CMakeLists.txt files. #4268
Comments
Just a quick note on this as I was passing by, but CMake defines |
That depends on where |
Are these subdirectories intended to be used directly? Seems a bit unusual to try to do that as, yes, CMake will complain about the lack of |
"Are these subdirectories intended to be used directly?" "CMake will complain about the lack of cmake_minimum_required() and project() directives" "it's not really independent to begin with" "I might suggest doing away with trying to use them as independent build systems and as top-level subprojects simultaneously - .... and nothing's really gained from trying to build it in isolation." Anyways, let's leave it to the owners to decide if standalone build is needed or not, or how they wish to re-structure cmake scripts. |
There is definitely some inconsistency with the CMakeFiles (e.g. library defines the projects within the directory, but doesn't work by itself), whereas other libraries, e.g. mbedtls_test, are defined in the top-level CMakeFile). I don't really see a strong benefit to being able to include just a single subdirectory from another project. Doing this would require some significant restructuring of our cmake scripts. I think we should focus on any problems caused when another project tries to use the top-level cmake script. I'd also suggest defining a value in this top-level script that we check for in the sub scripts, and if it isn't defined, generate a clearer error. The current behavior about a bunch of undefined symbols is not helpful. |
Unfortunately I can not remember the details, but we were building the library directory only to avoid some issues due to "improper" cmake files. I.e. the top level file sets global C flags based on some in-house compiler identification. If one has to avoid that, a workaround can be to use the library directory. Of course the proper solution would be to fix the top-level cmake file. |
I'd like to pursue this approach. Currently, Zephyr uses its own CMake file when using Mbed TLS, because of these issues with globals and such. Making the top-level cmake file usable as a sub directory, and perhaps even making it so that it detects and flags an error when an external project tries to use sub cmake files directly. |
Description
The following CMakeLists.txt files [1] use CMAKE_SOURCE_DIR to set MBEDTLS_DIR which may have unwanted side-effects when these "projects" are used with add_subdirectory(). This is the case i.e. if the CMakeLists.txt file of an external project uses add_subdirectory(<mbedtls_root>/libarary) to only build the library. In such case MBEDTLS_DIR will pint to the location of the top-level cmake file of the external project.
1:
- library/CMakeLists.txt
- tests/CMakeLists.txt
There are at least the following possible workarounds:
(Note: using a CACHE variable would allow the same behavior which is implemented currently with the conditional block around setting the variable.)
mbed TLS build:
Version: tip of development
The text was updated successfully, but these errors were encountered: