FLANN compile (cygwin) - makefile

I'm trying to build FLANN libriary on windows.But I have cygwin installed.
> "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
> cd flann-x.y.z-src
> mkdir build
> cd build
> cmake ..
> nmake
and when I use cmake .. it seems it uses cygwin and gcc compiler.
and then nmake don't work.

Quite unclear what you want to achieve:
You can build FLANN in cygwin environment by cygwin's cmake and make and then use it.
Or you can follow FLANN installation instructions and build it with window's native cmake and C++ compiler and use it (simply do not use cygwin at all, use cmd.exe).
In case you want to use VS2008 C++ compiler, do
cmake -G "Visual Studio 9 2008" ..
cmake --build . --config Release

Related

How to configure CMakeLists to use Windows command line compiler instead of Visual Studio

I would like to convert my project from a Visual Studio solution to build with CMake and compile it with Makefiles.
This is a 2-part question.
Right now the CMakeLists.txt is:
cmake_minimum_required(VERSION 3.13.0)
project(Project2015 CXX)
add_executable(Project Source/main.cpp)
When I run cmake .. out of the build directory, it generates *.vcxproj and *.sln files, but there is no Makefile. How can I change the CMakeLists file to generate a Makefile?
What is the command line equivalent compiler to gcc for windows? And how do I set this compiler as the target for CMake and the generated Makefile?
Reading about the build tools https://learn.microsoft.com/en-us/cpp/build/walkthrough-compile-a-c-program-on-the-command-line?view=vs-2019
Do I need to target the cl.exe compiler? Would this work with CMake and Makefiles?
I'm reading online that these command line flags will set the compiler, how can I add these to the CMakeLists.txt to be used automatically?
DCMAKE_C_COMPILER=cl
DCMAKE_C_COMPILER_FORCED=ON
DCMAKE_CXX_COMPILER=cl
DCMAKE_CXX_COMPILER_FORCED=ON
DCMAKE_BUILD_TYPE=Debug
DCMAKE_INSTALL_PREFIX=%CFITSIO_DIR%
G"NMake Makefiles"
You should use the build tool mode of CMake for builds from the command line.
After configuring your project for a 64bit build using Visual Studio 2019 e.g. with
cmake -S <sourcedir> -B <builddir> -G "Visual Studio 16 2019" -A x64
you would run
cmake --build <builddir> --target ALL_BUILD --config Release
For further options see here for an almost quiet build from the command line see here.
As suggested by #vre, you can run everything from the command line, while still using the Visual Studio generator. Just use CMake's command line build tools:
cmake ..
cmake --build . --config Release
This way, you don't have to open Visual Studio at all to build your libraries/executables.
Another option is to use Microsoft's nmake utility, which will generate NMake Makefiles. You can tell CMake to use this generator instead using this:
cmake -G"NMake Makefiles" ..
The full list of CMake generators you can choose from is listed here.
If you don't want to manually set the CMake generator in the command line, you can set it at the top of your CMakeLists.txt file:
set (CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE)
It will be used on the second CMake configuration in this case, as the first run will use the system default generator. If you want CMake to use it on the first configuration, you can utilize the Preload.cmake procedure outlined in this answer.

Building clang from source code on Ubuntu and Windows

Its been a While that I tried to build clang from source code.
I tried with 2 platforms
a> Ubuntu
b> Windows
I am following the link http://clang.llvm.org/docs/LibASTMatchersTutorial.html
Ubuntu
$ mkdir build
$ cd build
$ cmake -GNinja -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ /path/to/source/llvm
After this in build directory ninja.build files generated along with some more folder
$ ninja after this command inside build directory bin folder can be seen and it contains all the clang executables clang,clang++,clang-check and many more.
Windows
I tried every option that is available to build clang from source
I am trying on developer command prompt and also I am having VS Express edition
> mkdir build
> cd build
> cmake -GNinja -DCMAKE_BUILD_TYPE=release -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ path-to-llvm
It throws error
Host compiler appears to require libatomic,but cannot find it.
So I tried in the another way by making DCMAKE_CXX_COMPILER and DCMAKE_C_COMPILER as clang-cl.exe
> cmake -GNinja -DCMAKE_BUILD_TYPE=release -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_C_COMPILER=clang-cl.exe -DCMAKE_CXX_COMPILER=clang-cl.exe path-to-llvm
It didnt show any error at first but later while building
atlbase.h file not found
Why it is that much difficult to build clang from source on windows.?
Is this the correct procedure that I am doing?
Kindly help with any solution.

Is it possible to exclude a directory from all cmake? [duplicate]

I have Mingw64 GCC 6.3.0 (always in PATH) and Visual C++ compiler tools from Visual Studio 2017 RTM (not in PATH).
If I run cmake . -G "MinGW Makefiles", GCC 6.3.0 will be selected.
If I run cmake . -G "Ninja", GCC 6.3.0 will be selected.
My Visual C++ compiler tools is none standard, I only keep the parts I need and delete the rest (like MSBuild, IDE etc.). I use my own batch script to set up PATH, INCLUDE and LIB (works just fine).
If I run this batch script and run cmake ., MSVC will be selected and build with NMake.
With the same environment, cmake . -G "Ninja", GCC 6.3.0 is selected instead of MSVC.
So my question is, how to tell CMake I want to use MSVC + Ninja rather than GCC + Ninja when both are in PATH? Any environment variable I should set?
You can also use the inverted approach and exclude all compilers you don't want with CMAKE_IGNORE_PATH. It takes a list of paths to ignore, but be aware that it needs to be an exact string match. The advantage would be that you can declare those directly from the command line.
So what I did is to take the path from the compiler found but "not to be taken" into CMAKE_IGNORE_PATH.
And on my system there were actually three GCC compilers in my PATH (just make sure to start from an empty binary output directory with each try):
> cmake -G"Ninja" ..
...
-- Check for working C compiler: C:/MinGW/bin/cc.exe
...
> cmake -DCMAKE_IGNORE_PATH="C:/MinGW/bin" -G"Ninja" ..
...
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe
...
> cmake -DCMAKE_IGNORE_PATH="C:/MinGW/bin;C:/Strawberry/c/bin" -G"Ninja" ..
...
-- Check for working C compiler: C:/Program Files (x86)/LLVM/bin/clang.exe
...
> cmake -DCMAKE_IGNORE_PATH="C:/MinGW/bin;C:/Strawberry/c/bin;C:/Program Files (x86)/LLVM/bin" -G"Ninja" ..
...
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
...
use a toolchain file
set(CMAKE_C_COMPILER cl.exe)
set(CMAKE_CXX_COMPILER cl.exe)
then build your cmake project with with -DCMAKE_TOOLCHAIN_FILE=toolchainfile

how to set v120xp in cmake with vs2013's NMake

I'm using win7-32bit + cmake + vs2013's NMake.exe to build exe, I need the exe be able to run on WinXP, I know how to do that with vs2013 IDE(set the Platform-Toolset to v120xp), but I'm not using the IDE, I just use its NMake. This is how I generate the project file and exe:
build> cmake -G "NMake Makefiles" ..
build> nmake
Question 1: In the CMakeLists.txt, how to set it use v120xp?
Question 2: Is it necessary to build all static lib with the v120xp? Or just the exe?
Try setting CMAKE_GENERATOR_TOOLSET. It allows selecting the toolset for Genertors that support it. Generators that support Toolsets are Visual Studio and XCode.
Your call to CMake should look like this:
cmake -G "NMake Makefiles" -DCMAKE_GENERATOR_TOOLSET=v120_xp ..
Update 1: As pointed out in the comments NMake doesn't support Toolsets
Thes solution is to specify
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE,5.01")
for console applications, or
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS,5.01")
for windows applications.

Boost + Visual Studio 2010 + Windows Platform SDK 7.1

Could someone tell me a command line switch for bjam or something else that will make boost compile with VS2010 using the new Windows Platform SDK 7.1 toolchain? It's an option you can set in a normal visual studio project. The default is v100 a variant of the platform 7.0 toolchain. Thanks in advance.
Try this in your environment
set SdkTools=c:\Program Files\Microsoft SDKs\Windows\v7.1\Bin
call "%SdkTools%\SetEnv.Cmd" /xp /x86
assuming that's where you have the Windows SDK installed. Info is from here - there may be more to do, but this looks on the right track to me.
To build boost 1.43.0 libraries for VS 2010:
Download and extract to C:\Temp\boost_1_43_0
Start Visual Studio 2010 Command Prompt
Build BJam
cd C:\Temp\boost_1_43_0\tools\jam\src
build.bat
Build Boost using BJam
cd C:\Temp\boost_1_43_0
tools\jam\src\bin.ntx86\bjam.exe --with-regex link=static runtime-link=static threading=multi variant=debug,release address-model=32,64
Check bin.v2 or stage/lib for output. Note naming conventions.
May need to build in two phases with just address-model=32 then with just address-model=64. In this case we are choosing to build libs that statically link to the C runtime and to statically link to the boost lib itself.
Use --with to build non-header based libs like regex. Note stage/lib will be overwritten after each address-model build, but all libs are always kept in bin.v2.

Resources