Unknown Cmake command "add_llvm_tool" - cmake

I am trying to build llvm from source using Cmake.
I have an error coming when Cmake is trying to build it : Unknown CMake command "add_llvm_tool".
I don't know why there is this error, here is my CMakeLists.txt file
cmake_minimum_required(VERSION 3.2)
set(LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
Core
Object
Support
)
add_llvm_tool(llvm-nm
llvm-nm.cpp
)

You need to include(AddLLVM.cmake) to have this macro defined.

Related

Cmake: using conan pybind11 package

I'm having trouble understanding how to use pybind11 conan package. I can use some others, but pybind11 is giving me hard time.
My starting point is as follows:
conanfile.txt:
[requires]
pybind11/2.7.1
[generators]
cmake
main.cpp:
#include <pybind11/pybind11.h>
int add(int i, int j) {return i + j;}
PYBIND11_MODULE(cobind, m) {m.def("add", &add);}
CMakeLists.txt
cmake_minimum_required(VERSION 3.21)
project(cobind11 VERSION 1.0 LANGUAGES CXX)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
pybind11_add_module(cobind main.cpp)
The log of my suffering trying to make this work:
💀 Starting point
If I try to build as above the project I get the following error:
CMake Error at CMakeLists.txt:10 (pybind11_add_module):
Unknown CMake command "pybind11_add_module".
-- Configuring incomplete, errors occurred!
💀💀 Adding find_package(pybind11 REQUIRED)
If I add a line find_package(pybind11 REQUIRED) I get the following error:
CMake Error at CMakeLists.txt:16 (find_package):
By not providing "Findpybind11.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "pybind11",
but CMake did not find one.
💀💀💀 Adding include([...]/pybind11Tools.cmake)
If I add a line #include(${CONAN_PYBIND11_ROOT}/lib/cmake/pybind11/pybind11Tools.cmake) I get the following error:
CMake Error at /home/[...]/pybind11Tools.cmake:100 (set_property):
set_property could not find TARGET pybind11::pybind11. Perhaps it has not yet been created.
like in this issue https://github.com/pybind/pybind11/issues/3388. Maybe it is fixed in the new release?
💀💀💀💀 Upgrading to 2.8.1
The fresh pybind11 is 2.8.1, let's upgrade
pybind11/2.8.1: Not found in local cache, looking in remotes...
pybind11/2.8.1: Trying with 'conancenter'...
ERROR: Unable to find 'pybind11/2.8.1' in remotes
OK. One can read between the lines, that it used to work, so maybe let's downgrade?
💀💀💀💀💀 Downgrading to 2.4.3
If I require pybind/2.4.3 instead of pybind/2.7.1 in conanfile.txt I get
fatal error: Python.h: No such file or directory
112 | #include <Python.h>
| ^~~~~~~~~
like in this issue https://github.com/pybind/pybind11/issues/1781. Differently from that issue, installing python*-dev does not help. But whatever, I don't want to use old pybind anyway.
💀💀💀💀💀💀 Trying a conanfile from test package
The conancentral recipes contain a test package (https://github.com/conan-io/conan-center-index/tree/master/recipes/pybind11/all/test_package), which is tested automatically when the package is created. Let's try that instead!
CMake Error at CMakeLists.txt:13 (find_package):
By not providing "Findpybind11.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "pybind11",
but CMake did not find one.
Am I just hopeless???
Maybe, but! I can:
💪 Build the https://github.com/pybind/cmake_example
💪 Build the https://github.com/pybind/python_example
💪 Build the conancentral pybind11 recipe! The same that fails when I extract the test package to a separate folder. Whaaat?? 😱
I have used pybind in the past (two or three years ago) and it worked without problems with conan. However, I tried to install it now and faced similar problems. This might be related to the evolution of conan towards conan 2.0 (an alpha version was released today) and that the recipe was not updated to account changes.
An alternative that you might consider, is to install pybind with conan using a different generator. More specifically, the CMakeDeps generator. With the CMakeDeps generator conan will create a pybind11-config.cmake file for you and you just need to use find_package(pybind11 REQUIRED) in CMakeLists.txt. That is, there is no "conan specific stuff" in your CMakeLists.txt file.
conanfile.txt
[requires]
pybind11/2.7.1
[generators]
CMakeDeps
CMakeLists.txt
cmake_minimum_required(VERSION 3.21)
project(cobind11 VERSION 1.0 LANGUAGES CXX)
# Tell cmake to also search in the buld folder for the "<library>-config.cmake"
# files
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")
find_package(pybind11 REQUIRED)
pybind11_add_module(cobind main.cpp)
main.cpp
#include <pybind11/pybind11.h>
int add(int i, int j) { return i + j; }
PYBIND11_MODULE(cobind, m) { m.def("add", &add); }
With this I was able to build the library and use it in Python.
Conan deeper integration with CMake
You can also use the CMakeToolchain generator in addition to the CMakeDeps generator. It generates a conan_toolchain.cmake file that you pass to the cmake command with --toolchain conan_toolchain.cmake. If you use it, there is no need to add the list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}") line to your CMakeLists.txt file. Furthermore, the settings you specify in conan, such as build type and compiler, will impact cmake. That is, you don't need to specify these things in both conan and cmake. This seems to be where conan is going, regarding cmake integration, in the comming 2.0 release.

How to make a project written with Tcl in CMake?

I am using cmake version 3.14.0-rc3 to make my codes. When I target any code written in C or C++ in my CMakelist.txt as follows, it works pretty and makes the executable file.
cmake_minimum_required(VERSION 3.3)
PROJECT (HELLO)
ADD_EXECUTABLE(hello hello_world.cpp)
but while I am trying to make this code with Tcl scripts, it fails and I receive the following fatal error:
Fatal error while making a tcl script with cmake
Can anyone help me to overcome this issue? It seems that cmake is not normally able to compile Tcl scripts.
Thank in advance for your kind replies and helps.
Bests,
Daryon
You have to watch out for a different path, e.g., running custom commands or adding custom targets to your CMake project. You seem to confuse the nature of libraries, executables, and external commands in the context of CMake, I am afraid.
I think there should be a way to execute Tcl scripts with CMake as
well.
You might want to attempt the following: In CMakeLists.txt, you define a custom target MyTarget that calls out to a TCLSH executable, if available:
CMAKE_MINIMUM_REQUIRED(VERSION 3.3)
PROJECT (HELLO)
find_program (TCLSH tclsh)
if (TCLSH)
add_custom_target(
MyTarget ALL
COMMAND TCLSH myScript.tcl
)
endif (TCLSH)
(1) find_program and if/endif will make the custom target only available under the condition that an executable called tclsh was found.
(2) myScript.tcl is a Tcl script in your project directory.
(3) Running cmake . && make will call out to effectively to: tclsh myScript.tcl, producing:
$cmake . && make
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/hello
This is a message written by Tcl scripts
Built target MyTarget
This is just to get you started, you will have to read more about adding commands, targets, or executing sub-processes from within CMake.

CMake Error : execution of make failed on Windows

I am getting errors when trying to build nanomsg project in Windows 7:
cmake ..
-- Building for: NMake Makefiles
-- The C compiler identification is GNU 4.7.1
-- Check for working C compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_5d837\fast"
-- Check for working C compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files (x86)/cmake-3.9.4-win64-x64/share/cmake-3.9/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe" is not
able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/User/Documents/Internal/nanomsg-master/build/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_5d837\fast"
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO"
"cmTC_5d837\fast"
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:29 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/User/Documents/Internal/nanomsg-master/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/User/Documents/Internal/nanomsg-master/build/CMakeFiles/CMakeError.log".
I use gcc compiler and make from Mingw toolchain and I can run succesfully gcc.exe and mingw32-make.exe on a simple example.
In the file CMakeCache.txt the cache variables are set as follows:
//C compiler
CMAKE_C_COMPILER:FILEPATH=C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe
//Program used to build from makefiles.
CMAKE_MAKE_PROGRAM:STRING=nmake
I think that the problem comes from CMAKE_MAKE_PROGRAM variable it should take C:/Program Files (x86)/CodeBlocks/MinGW/bin/mingw32-make.exe, however i dont understand from where it gets the value nmake.
Even i replaced it manually I get the same problem.
My questions :
How CMake fills the Cache variables ?
Why CMAKE_MAKE_PROGRAM takes the value nmake ?
Why changing manually this variable didn t solve the problem ?
CMake fills the cache file with the values it detects based what is in CMakeLists.txt and whatever files it includes in combination with any -D paramters supplied to cmake.
On Windows CMake will default to Microsoft's nmake tool. The way to override this is by passing parameter -G"MinGW Makefiles" to cmake, or in case you use MSYS shell -G"MSYS Makefiles".
But there is a faster build tool than make called Ninja (get it from https://ninja-build.org/) which you can use by passing -GNinja to cmake.
Note: I see you're using the old MinGW that comes with Code::Blocks. There is a more up to date successor to MinGW called MinGW-w64, which supports both Windows 32-bit and 64-bit. A recent standalone build can be downloaded from https://winlibs.com/ and it also includes ninja.exe.
P.S.: If you run into more issues building the nanomsg sources after following these tips, consider passing -DNN_TESTS:BOOL=OFF to cmake

Errors with Tensorflow Cmake Build

I'm trying to build Tensorflow on Windows 7 x64 using the guide published here, however, when invoking MSBuild to build TensorFlow (step 4), I get a "Build FAILED" message followed by several errors.
The first:
CUSTOMBUILD : CMake error : CMake can not determine linker language for target: grpc [grpc.vcxproj]
CUSTOMBUILD : CMake error : CMake can not determine linker language for target: grpc_unsecure [grpc.vcxproj]
CUSTOMBUILD : CMake error : CMake can not determine linker language for target: cares [grpc.vcxproj]
does not make sense because within my grpc CMakelists.txt I have the following defined:
set(PACKAGE_NAME "grpc")
project(${PACKAGE_NAME} C CXX)
The other errors all involve source directories not containing a CMakelists.txt file:
CUSTOMBUILD : CMake error : The source directory "C:/tf-dev/local_repos/cub-1.6.4" does not appear to contain CMakeLists.txt. [cub.vcxproj]
which occurs for the following external projects:
cub
farmhash
fft2d
gemmlowp
gif
highwayhash
jpeg
lmdb
However, the Tensorflow build guide does not make any reference to creating additional CMakelists.txt for the externally added projects. Any idea where I might be going wrong? Thanks.

Unknown CMake Command "slicerMacroBuildScriptedModule"

Currently I am trying to build PlusRemote from SlicerIGT, but I keep getting errors that don't make much sense to me. I downloaded SlicerIGT from GitHub here, and I made sure to update CMake to version 3.2.3. The directory I am getting the source from should be fine. This is the error log I am getting:
CMake Error at CMakeLists.txt:19 (slicerMacroBuildScriptedModule):
Unknown CMake command "slicerMacroBuildScriptedModule".
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.2)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
Is there any way to solve this, or is there a better way to go about building PlusRemote?
EDIT:
I managed to specify the minimum required version so now the only error I am getting is:
CMake Error at CMakeLists.txt:19 (slicerMacroBuildScriptedModule):
Unknown CMake command "slicerMacroBuildScriptedModule".
If anything, this is what CMake is reading:
#-----------------------------------------------------------------------------
set(MODULE_NAME PlusRemote)
cmake_minimum_required(VERSION 3.2)
#-----------------------------------------------------------------------------
set(MODULE_PYTHON_SCRIPTS
${MODULE_NAME}.py
)
set(MODULE_PYTHON_RESOURCES
Resources/Icons/${MODULE_NAME}.png
Resources/Icons/icon_Record.png
Resources/Icons/icon_Stop.png
Resources/Icons/icon_Wait.png
Resources/Icons/VisibleOff.png
Resources/Icons/VisibleOn.png
)
#-----------------------------------------------------------------------------
slicerMacroBuildScriptedModule(
NAME ${MODULE_NAME}
SCRIPTS ${MODULE_PYTHON_SCRIPTS}
RESOURCES ${MODULE_PYTHON_RESOURCES}
WITH_GENERIC_TESTS
)
#-----------------------------------------------------------------------------
if(BUILD_TESTING)
# Register the unittest subclass in the main script as a ctest.
# Note that the test will also be available at runtime.
slicer_add_python_unittest(SCRIPT ${MODULE_NAME}.py)
# Additional build-time testing
add_subdirectory(Testing)
endif()
Did I miss downloading or updating anything?
EDIT: Is this what I'm missing?
PlusRemote does not need to be built using CMake in order to have Plus run. Plus will start on it's own. Wish I had known this 3 hours ago.