clion wsl "CMake 3.20 or higher is required. You are running version 3.16.3" - cmake

so I just downloaded wslusing the wsl --install command using PowerShell
now I'm trying to connect it to Clion which works
i cant add images so here is a link to it
but when i'm tying to build the project i get this error
"CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
CMake 3.20 or higher is required. You are running version 3.16.3"
my cmake file:
cmake_minimum_required(VERSION 3.20)
project(ex2 C)
set(CMAKE_C_STANDARD 99)
add_executable(ex2
ex2.c ex2.h
main1.c
main2.c)
i tried updating wsl using wsl --update (in powershell)

The CMake installation inside the WSL is used. Unfortunately currently snap doesn't seem to be available in WSL, but installing the latest CMake version isn't too complicated nonetheless:
(optional) uninstall the old cmake installation in WSL; personally I don't see any benefit in multiple CMake installations, but there may be valid reasons for this. Most likely this will just makes the use of cmake more complex, since you need to remember which cmake version is used.
Download the appropriate cmake version from the cmake website ( https://cmake.org/download/ ). The version to choose is the tar.gz file under binary distributions for the x86_64 target. To get version 3.21.4 (currently the latest release), you can download the file from https://github.com/Kitware/CMake/releases/download/v3.21.4/cmake-3.21.4-linux-x86_64.tar.gz (Identical to the link on the CMake download page).
Unpack the archive from WSL. Navigate to the directory where you want the cmake installation to recide. This will add the cmake-3.21.4-linux-x86_64 directory containing all the files required to work with cmake to the current working directory. Let's assume you want to add the cmake files to the /opt directory. Furthermore let's assume the windows user name to be fabian, C: to be the primary hard drive and the download to be saved to the Downloads directory in the user directory:
cd /opt
tar -xf /mnt/c/Users/fabian/Downloads/cmake-3.21.4-linux-x86_64.tar.gz
(optional) make CMake available without specifying the path; this could be done as described here: https://unix.stackexchange.com/questions/3809/how-can-i-make-a-program-executable-from-everywhere ; don't do this, if an existing cmake installation is already available in the command line assuming you did install cmake to /opt, the cmake binary recides at /opt/cmake-3.21.4-linux-x86_64/bin
You should now be able to use cmake specifying either the full path to the executable (/opt/cmake-3.21.4-linux-x86_64/bin/cmake assuming you used the /opt directory) or directly via a command after opening the WLS commandline again (provided you followed step 4).
Now the only thing left to do should be telling CLion about the location of the cmake executable. Note that I haven't tested this, since I don't use this IDE. It's working fine using Visual Studio Code though...

Related

cmake: difference between "make install" and "make package"

I'm using CMake to generate my makefiles. My deployable target is an RPM, and that's all working well. Per the file system guidelines, my RPM installs to
/opt/mytool
/bin - executables
/lib64 - libraries
/etc/opt/mytool - configuration files
The RPM gets built by CPack using make package
During development testing, I don't want to install an RPM. It requires elevated privileges and limits any given machine to one (developer) version at a time. Before I got all the RPM stuff working, I was able to "make install" and create a simple install tree like this:
install
/opt/mytool
bin
lib64
However, the introduction of the config files to a different location has gummed up the works. I'd like this to be extended to include
install
/etc/opt/mytool
but I can live without it. Unfortunately, when I try make install I get this error:
Install the project...
-- Install configuration: "Debug"
CMake Error at cmake_install.cmake:49 (file):
file cannot create directory: /etc/opt/mytool. Maybe need administrative
privileges.
The offending part of the CMakeLists.txt file is
install(FILES ${PROJECT_SOURCE_DIR}/../Config/mytool.cfg
DESTINATION /etc/opt/mytool
)
I've looked at CMake rpm installing a file in /etc/init.d, but my RPM builds just fine (and I'm using CMake 3)
What is the difference between make install and make package (I can infer that the latter is running CPack, and it works just fine)? How can I create a development install tree
The difference between the two build targets is that package creates an RPM file in your case while install copies the resources given to the install() command to the location provided to the DESTINATION parameter:
DESTINATION
Specify the directory on disk to which a file will be
installed. If a full path (with a leading slash or drive letter) is
given it is used directly. If a relative path is given it is
interpreted relative to the value of the CMAKE_INSTALL_PREFIX
variable. The prefix can be relocated at install time using the
DESTDIR mechanism explained in the CMAKE_INSTALL_PREFIX variable
documentation.
You specified to copy files to /etc/opt/mytool for which you obviously have no write permissions and encounter the cited error.
You have two options to resolve this, the second one is clearly preferred, because it allows every developer to provide their own, system-local setting, where to temporarily install dev files:
set a DESTINATION path for which you have write permissions
set a relative path and call cmake with an additional argument to specify where your development install tree is:
cmake -H<source path> -B<build path> -DCMAKE_INSTALL_PREFIX=<install path>

Why won't find_library find libgmp

I'm trying to build a cmake project, and the repo I have been given has the lines
find_library(gmp gmp)
if(NOT gmp)
message(FATAL_ERROR "gmp not found")
endif()
which cause CMake configuration to fail.
I have been told this CMake works on Redhat Enterprise Linux 7.3.
I have also been told this repo should build in any Linux environment with the correct libraries installed, and an Ubuntu environment has been specifically referenced.
I am building in Debian 9.4.0, I have installed gmp, libgmp.so is located at /usr/lib/x86_64-linux-gnu/openssl-1.0.2/engines/libgmp.so
and I also have a libgmp.so.10 at /usr/lib/x86_64-linux-gnu/libgmp.so.10.
So, to recap, I have been handed a repo I have been told builds, but it does not build, it fails at this specific step, and I can't get google to give me any relevant results on how to fix the issue/what I am doing wrong.
libgmp is installed, but the development libraries are not.
Cmake find_libraries looks for the files required for software development, and while the libgmp package is installed, the libgmp-dev package is not.
Install libgmp-dev.
CMake doesn't search "so-version" files:
If find_library is called for "gmp" library name, CMake searches libgmp.so file, but not libgmp.so.10 one.
Normally, the library file without so-version is just a soft link to the newest so-version file. If your Linux distro doesn't create such link, you may create it manually:
ln -s libgmp.so libgmp.so.10
If you want CMake to find /usr/lib/x86_64-linux-gnu/openssl-1.0.2/engines/libgmp.so file, which is not under directory normally searched by CMake, you need to hint CMake about it. E.g. with PATHS option:
find_library(gmp gmp PATHS "/usr/lib/x86_64-linux-gnu/openssl-1.0.2/engines")

Where should I install FindXXX.cmake file of my own project and how to find it?

I am developing two CMake projects: libABC and libXYZ. libXYZ requires libABC, and so I would like install FindABC.cmake in an appropriate location on Mac and Linux machines.
libABC and its related files are installed under /usr/local by default, and I think FindABC.cmake also should be installed under the same directory. I tried installing it in the following six different locations.
/usr/local/lib/cmake/ABC/FindABC.cmake
/usr/local/share/cmake/ABC/FindABC.cmake
/usr/local/lib/ABC/FindABC.cmake
/usr/local/share/ABC/FindABC.cmake
/usr/local/lib/ABC/cmake/FindABC.cmake
/usr/local/share/ABC/cmake/FindABC.cmake
However CMakeList.txt of libXYZ cannot find it with the following error.
CMake Error at CMakeLists.txt:51 (find_package):
By not providing "FindABC.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"ABC", but CMake did not find one.
My cmake command was installed under /opt/local by using MacPorts on OS X. So I think it searches not /usr/local but only /opt/local.
I know that defining CMAKE_MODULE_PATH when executing cmake command solve this issue (e.g., cmake -DCMAKE_MODULE_PATH=/usr/local/lib/cmake/ABC), but I do not want to ask all users to do it every time.
My questions are
Q1. Where should I install FindABC.cmake during the libABC installation process?
Q2. How do I properly find FindABC.cmake in CMakeLists.txt of libXYZ without hard-coding CMAKE_MODULE_PATH in it?

How to get IDE setup running for CustusX for plugin development?

I downloaded CustusX from the homepage and tried to follow the build instructions. (with ./cxInstaller.py --full --all -t RelWithDebInfo as last command. That went smoothly on Kubuntu 14.04.
Now with everything checked out and available on the harddisk I tried to set up a project that such that I can do some debugging from within an IDE eg. qtcreator or eclipse. I searched the documentation but didn't find it there.
I tried to point cmake-gui at /[...]/custusx/CX/CX, chose Eclipse CDT4 - Ninja and tried to configure. But it fails since it cannot find FindEigen.cmake:
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find Eigen (missing: EIGEN_INCLUDE_DIR EIGEN_VERSION_OK)
(Required is at least version "2.91.0")
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
CMake/FindEigen.cmake:76 (find_package_handle_standard_args)
CMake/cxInitializeLibraries.cmake:273 (find_package)
source/CMakeLists.txt:11 (cx_initialize_Eigen)`
I see there is a FindEigen.cmake in the CMake directory, but setting the CMAKE_MODULE_PATH didn't help either.
QtCreator didn't work either as it experiences the same problems parsing the CMake files when pointed at CMakeLists.txt at custusx/CX/CX
So, the question is how to get a running setup in an IDE preferable qtcreator or eclipse for developing custusx plugins?
CustusX is configured using the superbuild cxInstaller.py. As part of this build, cmake is invoked with parameters:
cmake arguments source_folder
An example when located in the build folder /home/cas/cx/CX/build_Release:
cmake -G"Eclipse CDT4 - Ninja" -DCMAKE_BUILD_TYPE:STRING=Release -DEIGEN_INCLUDE_DIR:PATH=/home/cas/cx/eigen/eigen -DCTK_DIR:PATH=/home/cas/cx/CTK/build_Release -DOpenCV_DIR:PATH=/home/cas/cx/OpenCV/build_Release ...more arguments omitted... /home/cas/cx/CX/CX
This command can be found by looking through the console output of cxInstaller.py, under the heading == configure CustusX ==. Once the superbuild is run once, you can start working with cmake-gui, QtCreator or Eclipse:
When using cmake-gui, set "Where to build the binaries" to your build folder. This will automatally cause the existing cmake configuration to be loaded. In your case, cmake-gui probably tried to configure from scratch, without arguments.
When using QtCreator, first open the root CustusX CMakeLists.txt file. This leads you to the "Configure Project" page. The cmake configuration must be added manually: Set the location of the build folder, then configure, which fails. Then, in "Project->Build Settings->CMake arguments", paste in all arguments that the superbuild (cxInstaller.py) sent to cmake, i.e. the cmake command line excluding cmake and source folder. If using ninja, you might have to configure that as well.
It seems like the current version of QtCreator (3.0.1, Ubuntu 14.04) do not read the cmake configuration of a project, requiring the procedure described above. This was not necessary with the version shipped with Ubuntu 12.04.
When using Eclipse, use "Import", then "General->Existing Projects into Workspace", select CX as root directory, when CustusX should appear as a project that can be imported directly (Caution: If you prevously configured using QtCreator, the Eclipse project files will have been deleted. Run the superbuild again)
How to set up QtCreator 3.0.1 (Not needed for other versions of QtCreator) on Ubuntu 14.04 for CustusX:
Get CMake arguments (with minimal output):
./install/cxInstaller.py --configure -t RelWithDebInfo CustusX
Search through the output for the (long) line starting with cmake and ending with ...cx/CX/CX
Paste in these arguments in Project->Build Settings->CMake arguments

CMake rpm installing a file in /etc/init.d

I want to install a file in
/etc/init.d directory
I have written code
INSTALL(FILES ${CMAKE_SOURCE_DIR}/app/script/appd DESTINATION /etc/init.d/appd)
but when I run packing code using cmake I get error
CMake Error at /home/vivek/workspace/app/build/standalone/cmake_install.cmake:54 (FILE):
file cannot create directory: /etc/init.d/appd. Maybe need
administrative privileges.
How can I set cmake to install a file inside /etc/init.d directory ?
You can do this, but you may need to explicitly set:
set(CPACK_SET_DESTDIR ON)
prior to:
include(CPack)
in your CMakeLists.txt file. (You will need to do this only for older versions on CMake/CPack, prior to 2.8.3)
The reason you need to do this is that you are specifying a full path name as the DESTINATION of one of your installed files. In order to do that properly in the packing phase, CPack needs to use a DESTDIR environment variable in its "make install" call.
We didn't do this automatically by default for backwards compatibility reasons.
But then, this bug was fixed in version 2.8.3 so that it could be done transparently and automatically with install rules that use full path names:
http://public.kitware.com/Bug/view.php?id=7000
Hopefully, you can use either CPACK_SET_DESTDIR to ON for your rpm packages, OR use a more recent version of CMake/CPack that includes the automatic fix.
You can't. Only thing you can do is to ask user to run make install for your app with administrative priveleges.
Also, you can try detecting presense of sudo command and add_custom_command() which would install your files with sudo.