How to add and remove some flag to cmake in commandline? - cmake

In the command line ubuntu, I want to directly delete a series of flags contained in the source code of the HHVM when using cmake for install HHVM, if available, and add another set of flags to it.
What should I do about this?
please guide me.
for use linker -Wl,--emit-relocs should don't use -E , -s and -c.
example :
$ cmake + (-O3 -fno-reorder-blocks-and-partition -Wl,--emit-relocs)
and
$ cmake - (-E ,-s,-c)

Related

How to run sanitizers on whole project

I'm trying to get familiar with sanitizers as ASAN, LSAN etc and got a lot of useful information already from here: https://developers.redhat.com/blog/2021/05/05/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind
I am able to run all sort of sanitizers on specific files, as shown on the site, like this:
clang -g -fsanitize=address -fno-omit-frame-pointer -g ../TestFiles/ASAN_TestFile.c
ASAN_SYMBOLIZER_PATH=/usr/local/bin/llvm-symbolizer ./a.out >../Logs/ASAN_C.log 2>&1
which generates a log with found issue. Now I would like to extend this to run upon building the project with cmake. This is the command to build it at the moment:
cmake -S . -B build
cd build
make
Is there any way I can use this script with adding the sanitizers, without having to alter the cmakelist.txt file??
For instance something like this:
cmake -S . -B build
cd build
make -fsanitize=address
./a.out >../Logs/ASAN_C.log 2>&1
The reason is that I want to be able to build the project multiple times with different sanitizers (since they cannot be used together) and have a log created without altering the cmakelist.txt file (just want to be able to quickly test the whole project for memory issues instead of doing it for each file created).
You can add additional compiler flags from command line during the build configuration:
cmake -D CMAKE_CXX_FLAGS="-fsanitize=address" -D CMAKE_C_FLAGS="-fsanitize=address" /path/to/CMakeLists.txt
If your CMakeLists.txt is configured properly above should work. If that does not work then try adding flags as environment variable:
cmake -E env CXXFLAGS="-fsanitize=address" CFLAGS="-fsanitize=address" cmake /path/to/CMakeLists.txt

Cannot install regular files for Yocto using CMake

I have been using autotools for a few years, and I'm learning CMake now for new projects.
Here is what I have:
myfirstrecipe.bb:
inherit pkgconfig cmake
...
do_install() {
install -d ${D}${datadir}/folder1/folder2
install -m 0755 ${S}/files/file.txt ${D}${datadir}/folder1/folder2
}
mysecondrecipe.bb:
...
DEPENDS = "myfirstrecipe"
...
This works fine. The second recipe can find the file.txt installed by the first recipe, which I see it is installed in the secondrecipe sysroot:
build/tmp/work/armv7ahf-vfp-os-linux-musleabi/mysecondrecipe/510-r0/mysecondrecipe-sysroot/usr/share/folder1/folder2/file.txt
However I want CMake to install the file instead. So when I try this:
myfirstrecipe.bb:
inherit pkgconfig cmake
...
OECMAKE_TARGET_INSTALL = "file-install"
CMakeLists.txt:
add_custom_target(file-install)
add_custom_command(TARGET file-install POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_INSTALL_DATADIR}/folder1/folder2
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/files/file.txt
${CMAKE_INSTALL_DATADIR}/folder1/folder2/)
Then I get a build error from mysecondrecipe.bb saying it could not find the file since it is not installed. I see it installed here:
build/tmp/work/armv7ahf-vfp-os-linux-musleabi/myfirstrecipe/1.0-r0/myfirstrecipe-1.0/share/folder1/folder2/file.txt
But not in the path above. Anyone can see what I am missing? If I were to use Autotools I could easily get this working with this:
Automake.am:
file-install: $(shell find files/ -type f -name '*.txt')
mkdir -p ${DESTDIR}${datadir}/folder1/folder2
cp -u $^ -t ${DESTDIR}${datadir}/folder1/folder2
Basically you do not use the standard way of installing files.
CMake has an install directive install, wich is commonly used and powerfull.
Doing so, leads to the nice situation, that Within myfirstrecipe.bb an own do_install task is not necessary. The cmake.bbclass, you already inherit, is adding a do_install task and relies on the install directive within your CMakeLists.txt
You can take a look at the cmake.bbclass to see how it is implemented. It's at poky/meta/classes/cmake.bbclass
I guess that switching to install will make life easier

CMAKE_CTEST_COMMAND not defined

I am using cmake 3.0.2 (on debian 8). I am trying to add some tests using a custom check target like this:
ADD_CUSTOM_TARGET(check
COMMAND ${CMAKE_COMMAND} -E env CTEST_OUTPUT_ON_FAILURE=1 ${CMAKE_CTEST_COMMAND}
DEPENDS test_1 test_2)
I am using the built-in CMAKE_CTEST_COMMAND which is supposedly available in cmake However, the variable is undefined and the command does not work. My questions are the following:
1: Am I doing it wrong? It seems to work with cmake 3.3.2, when was this variable added?
2: How can I get this to work in cmake 3.0.2, should I just replace CMAKE_CTEST_COMMAND with "ctest"?

How to set the CMAKE_PREFIX_PATH?

I have a problem with the global environmental variable CMAKE_PREFIX_PATH. I already set this and I can see it is set when I type env, but when I run cmake . to build HipHop, it tells me that the variable isn't set.
Is there a way I can hard-code this into the makefiles?
Try to run cmake -DCMAKE_PREFIX_PATH=/your/path .
CMAKE_PREFIX_PATH works as a build directive, rather than as an environment variable. Moreover, you may perform the build into a dedicated temporary directory (it's cleaner, because when done, you can remove that temporary directory and you get back a clean pristine source tree).
$ mkdir -p tmpbuild && cd tmpbuild
$ cmake -DCMAKE_PREFIX_PATH=~/deliveries/hiphop ..
$ make install
$ cd ..
On MacOS it's different. I had to use:
make -i CMAKE_PREFIX_PATH="/the/path"
This was while installing VMQT, and this error was shown:
CMake Error at CMakeLists.txt:87 (find_package): By not providing
"FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has asked CMake
to find a package configuration file provided by "OpenCV", but CMake
did not find one.
Could not find a package configuration file provided by "OpenCV"
with any of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If
"OpenCV" provides a separate development package or SDK, be sure it
has been installed.
Used this to solve it: make -i CMAKE_PREFIX_PATH="/opt/homebrew/Cellar/opencv/4.6.0_1/lib/cmake/opencv4/"

How to set PATH environment variable in CMake script?

I want to build my sources by Mingw compiler which in not placed on my system PATH.
I tried this in the beginning of my script:
set(Env{PATH} "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
And this:
set(CMAKE_PROGRAM_PATH "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
set(CMAKE_LIBRARY_PATH "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
set(CMAKE_SYSTEM_PROGRAM_PATH "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
set(CMAKE_SYSTEM_PREFIX_PATH "c:/MyProject/Tools/mingw/bin/" "c:/MyProject/Tools/mingw/msys/1.0/bin/")
The first variant doesn't work at all. A suggest that I can't overwrite the value of the environment variable in CMake script.
The second script finds my mingw compiler, but catches the error while running gcc (can't find libgmp-10.dll which needs by gcc). This is because the PATH variable is not set to my Mingw.
CMAKE_SYSTEM_PROGRAM_PATH is not meant to be modified, use
LIST(APPEND CMAKE_PROGRAM_PATH "c:/MyProject/Tools/mingw/bin/" ...)
You might approach it as if it were a cross compiling toolchain, even if you're not cross compiling from Linux to Windows as in this example:
http://www.vtk.org/Wiki/CmakeMingw
After you follow that guide you set the mingw toolchain at the command line when calling cmake:
~/src/helloworld/ $ mkdir build
~/src/helloworld/ $ cd build
~/src/helloworld/build/ $ cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake
then if you're using this a whole lot you can make an alias to limit typing in that ugly -D every time you want to regenerate makefiles:
alias mingw-cmake='cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-mingw32.cmake'
Write a script file to start CMake.
On Windows make a batch file:
#echo off
set path=c:\MyProject\Tools\mingw\bin;c:\MyProject\Tools\mingw\msys\1.0\bin
"C:\Program Files\CMake 2.8\bin\cmake-gui.exe"
On Linux make a bash script:
export PATH=$PATH:/your/path