东西不分
东西不分

Reputation: 103

CMake cannot create MakeFile on Windows

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!

Upvotes: 10

Views: 8551

Answers (1)

user3980558
user3980558

Reputation:

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.)

Upvotes: 16

Related Questions