Check if directory has already been processed by cmake - cmake

I need to invoke get_directory_properties on a given directory. However the given directory may be a directory that cmake has not processed (yet) in which case aforementioned command returns an error:
CMake Error at CMakeLists.txt:111 (get_directory_property):
get_directory_property DIRECTORY argument provided but requested directory
not found. This could be because the directory argument was invalid or, it
is valid but has not been processed yet.
Therefore my idea is to verify that the given directory was indeed processed by cmake already (and thus I can safely invoke get_directory_properties on it) and if not I want to do something else.
I was however unable to find a way to check for that and I can't seem to find anything on that on the internet so far. Does anyone know how this could be done?

Related

make looks for libraries in the wrong directory

I am trying to compile SageMath from source, following the instructions here. I'm under Ubuntu 20.04.
The compilation fails with two errors and the log file says, among a lot of other things (I can post it all if you want, but it's very long):
g++: error: /usr/lib64/libcudart.so: No such file or directory
g++: error: /usr/lib64/libcublas.so: No such file or directory
Indeed there's no such file in there, they are under /usr/lib/x86_64-linux-gnu.
How do I tell make to look in the right directory? Or is there any other way to fix this?

cmake, linux: build directory given as symbolic link does not work: why?

I have setup with build directory set to ./bin within source root.
Everything works until I change ./bin to symbolic link.
Then everything configures correctly but make starts complaining about not found source files:
make[2]: *** No rule to make target '../cpp/foo.cpp', needed by 'CMakeFiles/mylib.dir/cpp/foo.cpp.o'.
Why it happens and what could I do about it?
I had idea to convert this path to absolute (inside makefile) and dump it to console in order to figure-out where it points to but it turned out that this "build.cmake" is recreated automatically at every make invocation :(
Thanks to Tsyvarev I realized that it is unmovable OS constraint with potential workaround using mount bind
I needed to do the same on a Mac (to exclude the build directory from iCloud Drive) and had success with executing the cmake-command from the build directory (not going there via link) and giving the absolute path for the source to cmake.
See also: https://stackoverflow.com/a/24435795/4883924

This bundle is invalid - The file extension must be .zip

I built a very small app in swift using objective-c cocoapods.
I can build it on my phone, but every time I try to upload it on testflight, I receive an email with a message saying that:
This bundle is invalid - The file extension must be .zip
Any idea what could possibly cause that?
This problem is caused by having spaces in the build source path that the Pods-frameworks.sh script attempts to check for symlink status. For example, this path references a build scheme called "MyApp QA", which causes the -L check to fail with binary operator expected, and ultimately copies the symlink file instead of the actual framework files:
/Users/me/Library/Developer/Xcode/DerivedData/MyApp-ecinfzhnelbxxegrpzcpwnezmvot/Build/Intermediates/ArchiveIntermediates/MyApp QA/BuildProductsPath/QA-iphoneos/Pods/ActionSheetPicker_3_0.framework
The easiest way to get around this is to make sure that nothing in your build path has spaces. This includes your app name, scheme, build config, etc.
A pull request has been merged to fix this, which will resolve the issue when the next version of CocoaPods is released.

Lua, io.input() can't find file

I have myfile.txt sitting in the same directory as my lua file, yet when I call io.input("myfile.txt") I get the error bad argument #1 to 'input' (myfile.txt: No such file or directory).
I don't see how this can be going wrong, have I misunderstood Lua's I/O?
You need to fully qualify the path (eg. "/home/username/myfile.txt" on *NIX, "C:\directory\myfile.txt" on Windows). When you don't, the Lua interpreter expects the file to be in the same directory as the interpreter.
Read this question for an easy fix using arg[0] to get the current directory of the script being executed.

Proper approach to sharing CMake module across projects?

I have written a CMake module that contains a couple of useful macros that I would like to use across a number of other CMake projects. However, I'm not sure where to put the module.
I would like to be able to do this inside each project that uses the macro:
include(MyModule)
However, I'm not sure if there is an easy and cross-platform way of achieving this. In fact, I can't even get it to work on Unix. I put the module (MyModule.cmake) in the following locations:
/usr/lib/cmake/
/usr/lib/cmake/Modules
/usr/local/lib/cmake
/usr/local/lib/cmake/Modules
...and the project with the include() was unable to load the module.
What is the correct location for this module? Is there a better approach?
I should also point out that the macros are not related to "finding" a third-party library and therefore have nothing to do with find_package().
Put the module in a directory of your choice, and then add that directory to CMAKE_MODULE_PATH using list(APPEND).
You can even host that module somewhere and then download it via file(DOWNLOAD). If you download it to the same directory as the current CMake script being processed, you just include(MyModule.cmake) and don't need to modify CMAKE_MODULE_PATH.
You could download the file to a common location on disk and then add a check using if(EXISTS "${module_location_on_disk}") to skip the download if it's already downloaded. Of course, more logic will be required if your module changes, or you want to have a common location and multiple versions of the module, but that's out of those scope of your question.