I am an llvm beginner. I compiled llvm which checked from svn, and I got the error: unknown cmake command add_llvm_loadable_module when using cmake to create a makefile in llvmroot/lib/Transform/Hello/build. I have no idea why this occur. Is there something wrong when compiling llvm? In this case, I compiled llvm by cmake -G "Unix Makefiles" in macros. Thanks for your help.
You just mixed things up.
You should cd into ~/llvm/build and run cmake ~/llvm or cmake ... And you don't need -DCMAKE_PREFIX_PATH at all in this case.
This command will just generate build files for you. Now, if you want to build only that Hello pass instead of whole LLVM, run make help | grep Hello to find out how the corresponding target is called and then make <target>.
You should used add_llvm_library in CMakeLists.txt
like this:
add_llvm_library(My_Plugin MODULE My_Plugin.cpp PLUGIN_TOOL clang)
Related
I use CMake with GNU Make and would like to see all commands exactly (for example how the compiler is executed, all the flags etc.).
GNU make has --debug, but it does not seem to be that helpful are there any other options? Does CMake provide additional flags in the generated Makefile for debugging purpose?
When you run make, add VERBOSE=1 to see the full command output. For example:
cmake .
make VERBOSE=1
Or you can add -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON to the cmake command for permanent verbose command output from the generated Makefiles.
cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON .
make
To reduce some possibly less-interesting output you might like to use the following options. The option CMAKE_RULE_MESSAGES=OFF removes lines like [ 33%] Building C object..., while --no-print-directory tells make to not print out the current directory filtering out lines like make[1]: Entering directory and make[1]: Leaving directory.
cmake -DCMAKE_RULE_MESSAGES:BOOL=OFF -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON .
make --no-print-directory
It is convenient to set the option in the CMakeLists.txt file as:
set(CMAKE_VERBOSE_MAKEFILE ON)
Or simply export VERBOSE environment variable on the shell like this:
export VERBOSE=1
cmake --build . --verbose
On Linux and with Makefile generation, this is likely just calling make VERBOSE=1 under the hood, but cmake --build can be more portable for your build system, e.g. working across OSes or if you decide to do e.g. Ninja builds later on:
mkdir build
cd build
cmake ..
cmake --build . --verbose
Its documentation also suggests that it is equivalent to VERBOSE=1:
--verbose, -v
Enable verbose output - if supported - including the build commands to be executed.
This option can be omitted if VERBOSE environment variable or CMAKE_VERBOSE_MAKEFILE cached variable is set.
Tested on Cmake 3.22.1, Ubuntu 22.04.
If you use the CMake GUI then swap to the advanced view and then the option is called CMAKE_VERBOSE_MAKEFILE.
I was trying something similar to ensure the -ggdb flag was present.
Call make in a clean directory and grep the flag you are looking for. Looking for debug rather than ggdb I would just write.
make VERBOSE=1 | grep debug
The -ggdb flag was obscure enough that only the compile commands popped up.
CMake 3.14+
CMake now has --verbose to specify verbose build output. This works regardless of your generator.
cd project
cmake -B build/
cmake --build build --verbose
It's worth noting however Xcode may not work with --verbose
Some generators such as Xcode don't support this option currently.
Another option it to use the VERBOSE environment variable.
New in version 3.14.
Activates verbose output from CMake and your build tools of choice when you start to actually build your project.
Note that any given value is ignored. It's just checked for existence.
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE will generate a file with all compilation commands.
This file is required by some LSP to know how to compile a source file out of the box, but it could also help for debugging compilation problems.
The output file is named ${CMAKE_BINARY_DIR}/compile_commands.json.
Can someone explain me please how to install properly Cmake and GoogleTest so the command
gtest_discover_tests
becomes available ?. I installed
cmake-3.23.0-rc3
and
googletest-release-1.11.0
from source but I still can't compile that project
https://github.com/D-os/libbinder
because of fallowing error
CMake Error at tests/CMakeLists.txt:15 (gtest_discover_tests):
Unknown CMake command "gtest_discover_tests".
I'm using Slackware 14.2 x64
That function is defined in the GoogleTest script file (module) so you need to include it like this: include(GoogleTest)
Then you can use the function.
I've been trying to build wxwidget 3.1.5 on Windows 10 using CMake.
I simply used the command recommended on the official website:
cmake -G "MinGW Makefiles" ..\wxWidgets-3.1.5\ -DwxBUILD_TESTS=ALL
cmake --build .
It went smoothly until a message popped up
[100%] Building CXX object tests/headers/CMakeFiles/test_headers.dir/__/__/__/__/tests/allheaders.cpp.obj
In file included from D:/tools/wxwidget/wxWidgets-3.1.5/include/wx/platform.h:343,
from D:/tools/wxwidget/wxWidgets-3.1.5/include/wx/defs.h:45,
from D:/tools/wxwidget/wxWidgets-3.1.5/include/wx/wxprec.h:12,
from D:\tools\wxwidget\wxWidgets-3.1.5\tests\testprec.h:4,
from D:\tools\wxwidget\wxWidgets-3.1.5\tests\allheaders.cpp:433:
D:/tools/wxwidget/wxWidgets-3.1.5/include/wx/wxcrtbase.h:228:39: error: redundant redeclaration of 'size_t wcsnlen(const wchar_t*, size_t)' in same scope [-Werror=redundant-decls]
228 | wxDECL_FOR_MINGW32_ALWAYS(size_t, wcsnlen, (const wchar_t*, size_t))
Anybody knows how to cope with it? Thanks in advance!
WxWidgets already provides makefile for you. All you need to do is use it 😀:
cd WxWidgets-3.1.5\build\msw
mingw32-bin.exe -f makefile.gcc BUILD=debug
I've tried playing with the idea to compile my mixed swift/objective-c/c++ based project using CMake. So as a starter, I went to SwiftMix example and run the following CMakeList.txt file :
cmake_minimum_required(VERSION 3.3)
project(SwiftMix C Swift)
add_executable(SwiftMix CMain.c ObjCMain.m SwiftMain.swift ObjC-Swift.h)
set_property(TARGET SwiftMix PROPERTY XCODE_ATTRIBUTE_SWIFT_OBJC_BRIDGING_HEADER "ObjC-Swift.h")
After running cmake on the file above, I got the following error :
CMake Error: CMAKE_Swift_COMPILER not set, after EnableLanguage
However, it looks like inside CMake installation (version 3.9.1), there's a file/files which handle the swift support and define the missing variable from the error message :
/usr/local/Cellar/cmake/3.9.1//share/cmake/Modules/CMakeSwiftCompiler.cmake.in
Any idea how can I change the "CMakeLists.txt" to support swift ?
First, Swift language not supported by "Unix Makefiles" generator. So, you have to use cmake -G Xcode .
Then, generator the Xcode project, if it does not work, you can try the sudo xcode-select --reset or upgrade your cmake version.
Final, try cmake -G Xcode . again.
I'm trying to make Ninja work with CMake on FreeBSD 10.3:
cmake -GNinja ..
-- Configuring done
CMake Error:
The detected version of Ninja () is less than the version of Ninja required
by CMake (1.3).
-- Build files have been written to: /home/me/pj/_build
I have put a locally compiled (from Git tag v1.8.2) Ninja in ~/bin/ninja (which is in my $PATH).
$ cmake -version
cmake version 3.4.1
$ ninja --version
1.8.2
I also tried to add -DCMAKE_MAKE_PROGRAM=ninja and -DCMAKE_MAKE_PROGRAM=~/bin/ninja without effect.
I also tried to see if Ninja was really called (by putting a script writing a new file), and it looks like it's never called.
Is there a way to see which commands are used to to check the Ninja version?
By inspecting the generated CMakeCache.txt file, you should be able to tell which Ninja version is picked by CMake.
In CMakeCache.txt you should have something similar to:
// Path to a program.
CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/ninja
which could tell which Ninja version is picked by default and whether -DCMAKE_MAKE_PROGRAM is respected or from some reason ignored.
Also, it is worth looking into the generated CMakeOutput.log and CMakeError.log files.
I would also suggest adding ninja to your PATH, hoping CMake would pick it from there.
I came across this question while getting the same error message. What I forgot to do was delete the CMakeCache.txt file before I ran cmake with the -GNinja or -DCMAKE_GENERATOR=Ninja options. So cmake was pulling the cached variable.
You can also get this error message when forgetting to call project(my_project) before calling add_library or add_executable.