I tried to follow the steps here : https://cyber.dabamos.de/programming/modernfortran/gtk.html
We first have to build the Fortran interface library gtk-fortran.
Create a directory build/, run CMake to output a Makefile, and then
compile the libraries:
$ git clone https://github.com/vmagnin/gtk-fortran
$ cd gtk-fortran/
$ mkdir build && cd build/
$ cmake ..
Here what happened when I tried to run "cmake .." :
My Fortran compilator has been installed by MSYS (pacman) AND by using MINGW. I can compile and execute my Fortran program from the CMD.
If you have an idea what happened... It will be very helpful. I'm not an expert in the use of those tools but I'll try anything...
The Windows gtk-fortran instructions states that you should generate make files with the command $ cmake -G "MSYS Makefiles" .. (default on MSYS or MINGW is "NMake Makefiles"). It works form the MINGW terminal window. From the CMD window, I don't know.
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.
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.
A gitlab-runner configuration script .gitlab-ci.yml, for execution in the Powershell:
windows:
tags:
- windows
stage: build
script:
- New-Item -ItemType "directory" -Confirm:$false -Force:$true -Name "build"
- cd build
- cmd.exe "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
- cmake -G "Visual Studio 15 2017" -A x64 -T host=x64 -B. ..
- cmake -j8 --build . --config Debug
- ctest -j4
results in
$ cmd.exe "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
[...]
-- Configuring done
-- Generating done
-- Build files have been written to: C:/gitlab-runner/builds/xxxxxxxx/build
$ cmake -j8 --build . --config Debug
CMake Error: The source directory "C:/gitlab-runner/builds/xxxxxxxx/build/Debug" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
ERROR: Job failed: exit status 1
How to resolve this conflict between the configure step (cmake) and
the build step (cmake --build)?
The latter won't work without the option --config Debug;
but if that option is given, then it looks for a nonexistent directory.
Same problem with --config Release.
Disclosure: cross-posting from the CMake mailing list.
The ordering of command line arguments to cmake matters in this case. For build mode, the --build option must be the first one listed, but the -j8 option has been put before it. Change the build command to the following and it should work:
cmake --build . --config Debug -j8
The ordering requirement is documented for the --build option in the Build A Project section of the cmake manual.
I am trying to build a project in Release mode. By default it is built in debug mode. I am setting the variable CMAKE_BUILD_TYPE to "Release" in CMakeLists.txt. But it is still building the project in debug mode.
When I pass "Release" as the build type in the CMake command, it still does not work.
The CMake command that I am using is:
cmake -G"Visual Studio 10" -DCMAKE_BUILD_TYPE=Release
-H"source_path" -B"Build path"
Please provide a solution if any.
To change the build type, on Windows, it must be done at build time:
cmake --build {DIR} --config Release
By default it's Debug. I'm still looking for a way of changing this default. CMAKE_BUILD_TYPE doesn't work of course, and tweaking CMAKE_CONFIGURATION_TYPES doesn't work either, obviously for the same reason, they only apply for Unix makefiles, not for Visual projects.
I checked it with Visual Studio 2015 and cmake 3.3 .
Short answer
Link
cmake --build {BUILD_DIR_PATH} --target ALL_BUILD --config {BUILD_TYPE}
Example
cmake --build . --target ALL_BUILD --config Release
Long answer
cmake -G{GENERATOR_NAME} -B{BUILD_DIR_PATH} -H{SOURCE_DIR_PATH}
cmake --build {BUILD_DIR_PATH} --target ALL_BUILD --config {BUILD_TYPE}
Example
cmake -GVisual Studio 14 -Bbuild/win32/x86 -H.
cmake --build build/win32/x86 --target ALL_BUILD --config Release
Additional info
"-G" - specifies the generator name
"-B" - specifies path to the build folder
"-H" - specifies path to the source folder
You cannot set the default build type for Visual Studio from the command line.
CMake's Visual Studio Generators will generate the four standard profiles (Debug, RelWithDebInfo, MinSizeRel and Release) and you have to choose the one you want to build from within VS. This is because the information about the active configuration is not part of the project files generated by CMake, but part of the .suo file generated by VS.
If you want an automated build of a particular configuration, use MSBuild instead of VS which allows you to specify a configuration on the command line.
Tried the things below which worked for me to build the binaries in release/debug mode in Windows.
Added the following line in the root CMakeLists.txt file, just above the project command:
SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "" FORCE)
Used the following command for setting the release mode configuration:
cmake -DCMAKE_BUILD_TYPE=Release ..
Used this command to build the same in Release mode:
cmake --build . --config Release
You can repeat the same procedure for debug mode as well, it works.
Bit late, but I found this worked for me and was quite clean:
This means that just calling cmake builds in release mode, but if you want debug mode just call cmake -DCMAKE_BUILD_TYPE=Debug
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
endif()
If your generator is a single-config generator like "Unix Makefiles" or "Ninja", then the build type is specified by the CMAKE_BUILD_TYPE variable, which can be set in the configure command by using -DCMAKE_BUILD_TYPE:STRING=Release.
For multi-config generators like the Visual Studio generators and "Ninja Multi-Config", the config to build is specified in the build command using the --config argument argument like --config Release. A default value can currently be specified at configure time for the Ninja Multi-Config generator by setting the value of the CMAKE_DEFAULT_BUILD_TYPE variable, which will be used if the --config argument isn't passed to the build command. At the current time, a default cannot be set for Visual Studio generators.
Use it as you do it but in the root cmake file add the following before the project keyword
SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "" FORCE)
PROJECT(MY_PROJECT)#It's here just to show where you should add it.