How do I enable SSE2 from the command line - cmake

I'm compiling Dlib's Python Examples.
The compile script is:
mkdir build
cd build
cmake ../../tools/python
cmake --build . --config Release --target install
cd ..
How do I enable SSE2 from the command line? I tried adding the argument -USE_SSE2_INSTRUCTIONS=ON but got unknown argument error.
From Cmake cache file:
//Compile your program with SSE2 instructions
USE_SSE2_INSTRUCTIONS:BOOL=OFF

You forgot the -D. So you have to say, cmake -DUSE_SSE2_INSTRUCTIONS=ON

Related

CMAKE how to pass arguments to msbuild.exe

I have a cmake project and I'm using the msvc 2019 generator on windows 10.
I can successfully build with the following:
cmake -S . -B build
cd build
cmake --build . -- /m
I'm interested in passing the /m switch to msbuild.exe within the CMakeLists.txt itself.
I've tried the following without success as arguments get passed to cl.exe:
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /m")
message(STATUS "NOTICE: Setting parallel build for msbuild.exe")
add_definitions(/M)
endif()
Also bonus question: How does -- work in the last cmake command above? I'm struggling finding documentation on it.
The answer as #Johnny_xy pointed out is you can't. You need to use ninja as the cmake generator.
cmake -S . -B build -G Ninja Multi-Config
cd build
cmake --build .
link to ninja releases:
https://github.com/ninja-build/ninja/releases
ninja build time: 17.51s
cmake default build time: 44.54s

What is the correct syntax of llvm build in WSL Ubuntu?

I have the LLVM source and I was trying to build it from source the following build script gives me errors, what is wrong with the script, It is very likely that build script has errors in it because no one place was able to give me the correct sequence. I tried making use of the syntax given by official llvm site cmake -G -DCMAKE_BUILD_TYPE= [options] ../llvm
llvm official but it doesn't help.
cmake -G "Unix Makefiles"
-DCMAKE_BUILD_TYPE=Release
-DLLVM_TARGETS_TO_BUILD="X86"
-DLLVM_ENABLE_PROJECTS='clang;lldb;lld;mlir;clang-tools-extra;compiler-rt;libcxx;libcxxabi;libunwind'
-DLLVM_PARALLEL_COMPILE_JOBS=7
-DLLVM_PARALLEL_LINK_JOBS=1
-DLLVM_CCACHE_BUILD=ON
-DCMAKE_C_COMPILER=clang
-DCMAKE_CXX_COMPILER=clang++ ../llvm
Error Log :
pawan31#Jay-s-Pc:~/llvm$ cmake -G "Unix Makefiles"
ase
-DLLVM_TARGETS_TO_BUILD="X86"
-DLLVM_ENABLE_PROJECTS='clang;lldb;lld;mlir;clang-tools-extra;comCMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
CMake Error: The source directory "/home/pawan31/llvm" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
pawan31#Jay-s-Pc:~/llvm$ -DCMAKE_BUILD_TYPE=Release
piler-rt;libcxx;libcxxabi;libunwind'
-DLLVM_PARALLEL_COMPILE_JOBS=7
-DLLVM_PARALLEL_LINK_JOBS=1
-DLLVM_CCACHE_BUILD=ON
-DCMAKE_C_COMPILER=clang
-DCMAKE_CXX_COMPILER=clang++ ../llvm-DCMAKE_BUILD_TYPE=Release: command not found
pawan31#Jay-s-Pc:~/llvm$ -DLLVM_TARGETS_TO_BUILD="X86"
-DLLVM_TARGETS_TO_BUILD=X86: command not found
pawan31#Jay-s-Pc:~/llvm$ -DLLVM_ENABLE_PROJECTS='clang;lldb;lld;mlir;clang-tools-extra;compiler-rt;libcxx;libcxxabi;libunwind'
-DLLVM_ENABLE_PROJECTS=clang;lldb;lld;mlir;clang-tools-extra;compiler-rt;libcxx;libcxxabi;libunwind: command not found
pawan31#Jay-s-Pc:~/llvm$ -DLLVM_PARALLEL_COMPILE_JOBS=7
-DLLVM_PARALLEL_COMPILE_JOBS=7: command not found
pawan31#Jay-s-Pc:~/llvm$ -DLLVM_PARALLEL_LINK_JOBS=1
-DLLVM_PARALLEL_LINK_JOBS=1: command not found
pawan31#Jay-s-Pc:~/llvm$ -DLLVM_CCACHE_BUILD=ON
-DLLVM_CCACHE_BUILD=ON: command not found
pawan31#Jay-s-Pc:~/llvm$ -DCMAKE_C_COMPILER=clang
-DCMAKE_C_COMPILER=clang: command not found
pawan31#Jay-s-Pc:~/llvm$ -DCMAKE_CXX_COMPILER=clang++ ../llvm
-DCMAKE_CXX_COMPILER=clang++: command not found

What happened to CMake's --target argument?

With CMake version 3.19.2 I can use --target argument to build specific targets, instead of all.
For example --target tests to build tests.
However, with CMake 3.22.1 I'm getting an error like this:
CMake Error: Unknown argument --target
CMake Error: Run 'cmake --help' for all supported options.
You can see the manual of CMake here:
https://cmake.org/cmake/help/latest/manual/cmake.1.html
(There is a drop-down list for version selection)
It describes the --target argument, and It doesn't seem any different from what it was earlier. Nonetheless, after switching from 3.19.2 to 3.22.1 it doesn't let me use --target.
#EDIT thank you for your feedback, here's what I use:
cmake -G Ninja -DCROSS_COMPILER_PREFIX=<some_prefix> -Dsomeothervariables=1 --target tests $directory_with_cmake_project
It works with 3.19.2, but executing the same thing with cmake 3.22.1 causes the error.
I expect that the order of providing -G Ninja, variables, target directory and --target matters, but I haven't managed to get it to work in any order I could think of.
CMake is composed of stages - first you configure the project, then you build it:
configuration stage cmake <sourcedir> ... https://cmake.org/cmake/help/v3.22/manual/cmake.1.html#generate-a-project-buildsystem
build stage cmake --build <builddir> ... https://cmake.org/cmake/help/v3.22/manual/cmake.1.html#build-a-project
--target argument if for the build stage, and it is invalid for configuration stage, hence your error.
CMake prints this message, if you haven't specified a directory to build by passing --build <some dir> first. (The --target option only if mentioned in this usage version of the cmake command line tool, see the documentation.)
Wrong
cmake --target foo
CMake Error: Unknown argument --target
CMake Error: Run 'cmake --help' for all supported options.
Correct
(assuming in the subdirectory build of the current working directory contains a configured cmake project with a target foo).
cmake --build build --target foo

Cmake --config since version 3.20

All the build hierarchy of my project is based on ExternalProject with --config option. A few days ago I updated to cmake 3.20, and now --config is gone:
$ cmake --config
CMake Error: Unknown argument --config
CMake Error: Run 'cmake --help' for all supported options.
while documentation still advises to use it. Release notes are also silent about the option.
What should I use instead of --config?
You should use for configure
cmake -S . `-D CMAKE_BUILD_TYPE=Release`
CMAKE_BUILD_TYPE will be ignored at configure
And for build
cmake --build . --config Release
Based on https://stackoverflow.com/a/64719718
I don't understand why docs ignored this movement
Based on github Issue you should use
cmake --build .
OK I had the same problem on macOS with the XCode generator.
Turns out all I was missing was the --build command.
i.e. instead of:
cmake . --config Debug
I have to type:
cmake --build . --config Debug

the option "--build" of cmake

I want to use the cmake --build command to build my project.
This command has a --config option. I don't know how many different parameters I can assign to. And I found cmake doesn't check if the parameter of --config is correct or not
You can call cmake --build like this:
cmake --build . --target MyExe --config Debug
This would be run from your build root, since the directory is passed as ., and would build the target MyExe in Debug mode.
If your build tool is a multi-configuration one (like devenv on Windows), the --config argument matters. If you pass an invalid parameter as the config type here, the build tool should give an error.
If the build tool isn't multi-config (like gcc), then the --config argument is ignored. Instead the build type is set via the CMAKE_BUILD_TYPE CMake variable; i.e. it's set when running CMake, not when running the build tool.
You can pass further options to the build tool by adding them at the end after a --, e.g to pass -j4 if using gcc:
cmake --build . --target MyExe -- -j4