I've written a module on top of a private fork off of TensorFlow that uses nanomsg.
For my local development server, I used cmake install to install nanomsg (to /usr/local) and accessed the header files from their installed location. The project runs fine locally.
However, I now need to package nanomsg within my TensorFlow workspace. I've tried the following two approaches, and find neither satisfactory:
Similar to this answer for OpenCV, I precompiled nanomsg into a private repository, loaded it within my workspace (within tensorflow/workspace.bzl) using an http_archive directive then included the headers and libraries in the relevant build script. This runs fine, but is not a portable solution.
A more portable solution, I created a genrule to run a specific sequence of cmake commands that can be used to build nanomsg. This approach is neater, but the genrule cannot be reused to cmake other projects. (I referred to this discussion).
Clearly cmake is not supported as a first-class citizen in Bazel builds. Is there anyone who has faced this problem in your own projects created a generic, portable way to include libraries within Bazel projects that are built using cmake? If so, how did you approach it?
As Ulf wrote, I think your suggested option 2 should work fine.
Regarding "can I identify if the cmake fails", yes: cmake should return with an error exit code (!= 0) when it fails. This in turn will cause Bazel to automatically recognize the genrule action as failed and thus fail the build. Because Bazel sets "set -e -o pipefail" before running your command (cf. https://docs.bazel.build/versions/master/be/general.html#genrule-environment), it should also work if you chain multiple cmake commands in your genrule "cmd".
If you call out to a shell script in your "cmd" attribute that then actually runs the cmake commands, make sure to put "set -e -o pipefail" in the first line of your script yourself. Otherwise the script will not fail when cmake fails.
If I misunderstood your question "Can I identify if the cmake fails", please let me know. :)
This new project: https://github.com/bazelbuild/rules_foreign_cc seems like a solution(it build rules for cmake to build your project inside bazel).
I'm trying to get cmake working on msys2. I try to compile some code that I've been given for another project and:
CMake Error: Could not create named generator MSYS Makefiles
I've found this thread and this thread and tried to follow the instructions...only to realize that the wiki that the threads eventually link back to never states where msys stores toolchains. Googling around didn't really help.
Even more oddly, the program that I'm trying to use somehow runs and produces valid data despite throwing an error due to the missing cmake. I don't get it.
I've never used msys before; as someone who's brand new to msys2/cygwin and can't even understand the lingo, how do I get cmake installed and working?
Sounds like you are specifying a -G "MSYS Makefiles" as the CMake generator, but CMake doesn't recognize that generator. When I use CMake on msys2 I just use the default Unix Makefiles generator and everything works just fine. Also, on my current msys2 install, CMake doesn't seem to have a MSYS Makefile generator that I can see (running cmake --help will list the available generators). Try running cmake without the -G option. Also, make sure make is installed first via pacman -Sy make.
I'm trying to use CppUTest in Windows, first step is to get it to work and I already have problems. These are the things I've tried:
First Approach
With CMake, using the cmake GUI I can do the configure and generate command and I get something in the output directory, but no binaries and no libraries, just a bunch of cmakefiles. The CMake GUI says everything went OK during the configuration and generation steps, however the libraries (.lib files) are not generated in the output directory... is there something I am missing? I've never used CMake before.
Second approach
With MinGW and msys alone, running cmd in Windows and executing a MinGW shell by typing sh in the Windows terminal, afterwards I execute the following commands:
cd <CppUTest folder>
mount c:\mingw /mingw
./autogen.sh
./configure
make
The build process starts but it fails with a message indicating that pthread.h was not found in MinGW directory. If I install the pthread-win32 package with the MinGW package manager and repeat the same steps as above the build process starts but fails with a message indicating that the structure timespec is defined in time.h and pthread.h.
I've tried to follow this same procedure with CppUTest 3.6 and it works perfectly fine, I get the .lib files, so I guess I will have to continue with this for now.
Does anyone know how to build CppUTest 3.7 (latest release) with MinGW or CMake?
In the end I used Cygwin to compile it, I couldn't find a way to compile it with MinGW properly, I added a dirty trick to make it compile under MinGW (handled the timespec redifinition) but chances are that is going to cause issues.
Just make sure that you use Cygwin aswell to compile your tests, something that I found out after making this question (https://www.youtube.com/watch?v=oVmd0P85D8o).
I'm using Cmake to try to build a project for Eclipse. When I try running Cmake, I get the following error:
Error: could not load cache
Error: Batch build stopped due to Eclipse CDT4 - Unix Makefiles error.
---- Time Elapsed: 3 secs ----
Error: could not load cache
Error: Batch build stopped due to Eclipse CDT4 - Unix Makefiles error.
I'm completely stumped on what might be causing this. I know that I'm running Cmake in the correct directory and the CMakeCache.txt file is present. Could someone point me in the right direction to solve this?
If you are using the CLion, you can use File---"Reload CMake Project".
I meet this problem after using git force pull, and Reload CMake Project solves it.
Remove the CMakeCache.txt and try again. You probably had a bad cmake setup.
I have faced the same problem and solved it using the terminal.
Delete the cached/configurations files as we will get them again.
To configure the project run cmake .
Build the project using cmake --build .
run cmake --configure . it should generate required files.
I ran into this recently using JetBrains CLion and the above instructions were helpful but not directly, I was able to reload the project using the "cog" drop down in the CMake tab:
If you are absolutely positive that you are running the build command from the binary directory, this error probably means that you have had an issue during the configuration/generation step that you should have ran before trying the build. You can try to configure again to check (cmake your-build-dir)
I would advise running the Gui and trying to load the cache to see if you get a more explicit error (although I doubt it).
Another possibility would be to try to create a new clean build directory and take it from there.
In your example Eclipse must run something like
cmake --build folder_name --target all
and I opt that the *folder_name* is bad in this case. You probably messed something up in Eclipse.
For me it helps to select CMake tab (next to Run, TODO) in CLion. Then click the Reload CMakeProject button.
I got this error on Windows WSL with ubuntu
~/tmp/cmake$ cmake --build ./build
Error: could not load cache
I was able to fix the above error by running the following cmds in order:
% cmake -S . -B ./build
% cmake --build ./build
The above solution was derived from this post.
If you are using Visual Studio 2019, close Visual Studio, delete .vs and out folders then rebuild your project.
I removed the .cxx and other ide-generated files to the recycle.bin, except app.iml. Then I restarted Android Studio, and eventually it worked fine.
The solution that worked for me using VisualStudio 2017 was choosing:
CMake --> Cache --> Generate (from the top menu)
Apart from the already given answers, it might be due to the wrong commands or in wrong order.
To be precise, for me, it was due to
cmake -B build -G Ninja
cmake --build .
The "cmake --build ." command will throw the Could Not Load Cache error.
The problem is the build directory is given as '.' which doesn't have the cache or whatever files cmake generates, so correct command was 'cmake --build build'... and fixed !
There maybe trillion other ways but my solution was this.
For eg, it happened with the repo -> https://github.com/adi-g15/worldlinesim, though may show the same for other repos too.
For Ubuntu users, provide the source code open-pose path in the CMake-GUI.
P.S I had this issue and my path was not set there.
Most probably the issue is you have not wrote the correct name of the Visual Studio version you have installed during the build file preparation:
cmake .. -G "Visual Studio 16 2019" (note if you have VS 2016 you should change in in there)
The most realistic answer and personal experienced answer is
If you are using Clion and building files with IDE
And getting the error Cmake Error: could not load cache
Because you have accidentally deleted the cache file (like me: permanently and cant get back) or there is other problems or other problems
Then do this:
Run -> Clean
Run -> Build
And your project will be working all fine
cmake -B ./build(dest dir)
cmake --build ./build(
I'm a little unsure of terminology in this problem domain, which is an issue when I try to search for things.
I'm using CMake for my build process. I'd like to make a Makefile target such that I can use make run to run a given process (specifically, the one I've just built with make). I realize I could just make a shell script, or just run the command by typing it out. If I was writing a Makefile myself, I'd do this like so:
run:
./path/to/binary
I don't ever write a Makefile myself, though - that's generated by cmake - and I'm not sure what to put in my CMakeLists.txt to get it to generate the desired make run target.
I've found the cmake command 'execute_process', but that doesn't seem to be what I'm after - I don't want to actually run anything during the build process.
Extra: In addition, I'd love to be able to do something like the following:
CMAKE_COMMAND_ADD_MAKEFILE_TARGET ( ${CMAKE_PROJECT_DIR}/binary )
That is, add the path/to/binary using a cmake variable, if that's possible.
You are looking for add_custom_target. For instance:
add_custom_target(run
COMMAND binary
DEPENDS binary
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
)