Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake cannot create MakeFile on Windows

Tags:

c

makefile

cmake

When I tried to run cmake, it did generate a bunch of files but no MakeFile was created.

CMakeLists.txt

PROJECT(main)
CMAKE_MINIMUM_REQUIRED(VERSION 3.16) 
AUX_SOURCE_DIRECTORY(. DIR_SRCS)
ADD_EXECUTABLE(main ${DIR_SRCS})

main.c

int main()
{
    return 0;
}

After running cmake in cmd, it gives me this

E:\practiceFolder\cake>cmake .
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.18362.
-- The C compiler identification is MSVC 19.21.27702.2
-- The CXX compiler identification is MSVC 19.21.27702.2
-- Check for working C compiler: D:/VisualStudio2019/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: D:/VisualStudio2019/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: D:/VisualStudio2019/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: D:/VisualStudio2019/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: E:/practiceFolder/cake

After that the some files are generated

E:.
│  ALL_BUILD.vcxproj
│  ALL_BUILD.vcxproj.filters
│  CMakeCache.txt
│  CMakeLists.txt
│  cmake_install.cmake
│  main.c
│  main.sln
│  main.vcxproj
│  main.vcxproj.filters
│  ZERO_CHECK.vcxproj
│  ZERO_CHECK.vcxproj.filters
│
└─CMakeFiles
    │  cmake.check_cache
    │  CMakeOutput.log
    │  generate.stamp
    │  generate.stamp.depend
    │  generate.stamp.list
    │  TargetDirectories.txt
    │
    ├─3.16.2
and some other files

Cannot find MakeFile in it. Probably some obvious mistakes here but I just can't find it. I've been stuck here for hours, any help would be appreciated, thank you!

like image 830
王子铭 Avatar asked Jan 01 '20 07:01

王子铭


People also ask

How do I make a CMake Makefile?

CMake generates a Unix makefile by default when run from the command line in a Unix-like environment. Of course, you can generate makefiles explicitly using the -G option. When generating a makefile, you should also define the CMAKE_BUILD_TYPE variable.

Can CMake run Makefile?

CMake will create makefiles inside many of the folders inside a build directory and you can run make or make -j8 in any of these directories and it will do the right thing. You can even run make in your src tree, but since there is no Makefile in your source tree, only CMakeLists.

Is CMake and Makefile the same?

Make (or rather a Makefile) is a buildsystem - it drives the compiler and other build tools to build your code. CMake is a generator of buildsystems. It can produce Makefiles, it can produce Ninja build files, it can produce KDEvelop or Xcode projects, it can produce Visual Studio solutions.

How do I create a makefile with CMake?

In a Unix-like platform, running cmake and then make creates the Makefiles by default. This is not the case on Windows. On Windows, CMake generates an MSVC solution by default. Check for a .sln file in your build directory. If you actually want Makefiles on Windows, add -G "Unix Makefiles" to the cmake line.

How do I use MSVC with CMake?

On Windows, CMake generates an MSVC solution by default. Check for a .sln file in your build directory. If you actually want Makefiles on Windows, add -G "Unix Makefiles" to the cmake line. If you want to use MSVC as compiler but work on the command line, another option is -G "NMake Makefiles", and calling make after that.

When to use CMake and make on Windows?

Use CMake and Make, when sh.exe is in PATH on Windows. Use CMake and Make, when sh.exe is in PATH on WindowsJuly 3, 2017. In order to be trapped by this problem your project / environment has to meet following conditions: You need to use Windows. Your project uses make as a base build system. You have available sh.exe as a system command.

How to use makefiles with MSVC?

If you actually want Makefiles on Windows, add -G "Unix Makefiles" to the cmake line. If you want to use MSVC as compiler but work on the command line, another option is -G "NMake Makefiles", and calling make after that. Make sure to delete your build directory before trying to build a new generator target.


1 Answers

In a Unix-like platform, running cmake and then make creates the Makefiles by default. This is not the case on Windows.

On Windows, CMake generates an MSVC solution by default. Check for a .sln file in your build directory.

If you actually want Makefiles on Windows, add -G "Unix Makefiles" to the cmake line.

If you want to use MSVC as compiler but work on the command line, another option is -G "NMake Makefiles", and calling make after that.

Make sure to delete your build directory before trying to build a new generator target. CMake can be touchy about that.

Check cmake --help for a list of available options. (Especially the generator targets are platform-specific.)

like image 100
Eyal Golan Avatar answered Sep 19 '22 19:09

Eyal Golan