0

Asked this question:
CMake cannot indentify path to compiler mentioned by set(CMAKE_C_COMPILER "path") rule
received an incorrect rules order response(it was obviously correct).
Aplied changes and tried again:
cmake .
output:

-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: nmake /nologo cmTC_fc6d3\fast &&
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe - broken

But I need not nmake but mingw make file ,found this topic:
CMake Error : execution of make failed on Windows

The 100% same problem I have .Tried provided solution:

You need to specify a generator in CMake command line like -G "MinGW Makefiles" and - depending on how many compilers you have installed - also the full paths to the compilers.

cmake -G "MinGW Makefiles"

output:

CMake 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: Error: generator : MinGW Makefiles
Does not match the generator used previously: NMake Makefiles
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.

and next cmake . output gives (after deleting CMakeCache.txt file and CMakeFiles directory as mentioned above):

-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe
CMake Error: CMake was unable to find a build program corresponding to "NMake Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error at C:/Program Files/CMake/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:44 (try_compile):
  Failed to configure test project build system.
Call Stack (most recent call first):
  CMakeLists.txt:9 (project)


-- Configuring incomplete, errors occurred!
See also "CMakeFiles/CMakeOutput.log".


CMake Error: Generator: execution of make failed. Make command was:  cmTC_4b6e5/fast &&
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe - broken

The 3 things i cannot understand:

  1. How to ... specify ... the full paths to the compilers or needed source or binary directory.
  2. Why compilers are connected to make.exe in any way.
  3. Why CMAKE_MAKE_PROGRAM is not set if there is proper rule.

Changing rules order :

set( CMAKE_MAKE_PROGRAM FORCE ) set(CMAKE_C_COMPILER ) set(CMAKE_CXX_COMPILER ) and
set(CMAKE_C_COMPILER ) set(CMAKE_CXX_COMPILER ) set( CMAKE_MAKE_PROGRAM FORCE ) has the same result after call.

If I remove set( CMAKE_MAKE_PROGRAM ) rule configuring with CMake GUI is possible but with cmd manual cmake . call is not .Same output as provided above.

Inside CMakeCache.txt generated by CMake GUI call's are lines :

//Path to a program.
CMAKE_MAKE_PROGRAM:FILEPATH=C:/Strawberry/c/bin/mingw32-make.exe

so for it was possible to find mingw32-make.exe and path provided for manual call is also right.

My CMakeLists.txt:

cmake_minimum_required(VERSION 3.17.1)

#set(CMAKE_MAKE_PROGRAM C:/Strawberry/c/bin/make.exe FORCE )
set( CMAKE_MAKE_PROGRAM C:/Strawberry/c/bin/mingw32-make.exe FORCE )

set(CMAKE_C_COMPILER "C:/Strawberry/c/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/Strawberry/c/bin/g++.exe")

project("Client")

enable_testing()

set(CMAKE_CXX_FLAGS "-std=c++17 " )

add_executable(Client
  main.cpp
  client.cpp
  client.h
  logmsg.cpp
  includes.h
)

target_link_libraries(Client wsock32 ws2_32)

add_test(NAME test COMMAND Client )
  • 2
    Invocation `cmake .` uses a single argument - `.` - as a *source directory*. Option `-G` is used for specify CMake generator. In a single `cmake` invocation you need to specify **both** these arguments: `cmake -G "MinGW Makefiles" .`. BTW, using the **same** directory as a source an build one is known as **in-source build** and it is not recommended. It is better to create separate build directory. From this directory you may run `cmake` and pass the source directory as a last parameter. This is known as **out-of-source build**. – Tsyvarev May 04 '20 at 08:09
  • @Tsyvarev thanks ,it works but why do i need to write it every time? I want to have once written `set( CMAKE_MAKE_PROGRAM FORCE )` rule and use it with `cmake .` – Gaurav Goswami May 04 '20 at 18:56
  • What do you mean by "write it every time"? In your question post you set generator only once, and this `cmake` invocation has failed (for other reason). It is sufficient to call `cmake` with `-G` option once, and further `cmake` calls from the same directory wouldn't require it. Note, that `CMAKE_MAKE_PROGRAM` sets only a **build program** for the current **generator**, it doesn't set a generator itself. It is impossible to set generator in the `CMakeLists.txt`, see that question for more info: https://stackoverflow.com/questions/11269833/cmake-selecting-a-generator-within-cmakelists-txt – Tsyvarev May 04 '20 at 19:29
  • @Tsyvarev now I got it ,thanks again. The last one question: If I transfer my `makefile` to another person, will they need the same software ? For example: my friend got from me copy of all directory with sources ,headers ,cmakelists ,generated `makefile` and `*.exe` file ,does he need something other than the same version mingw and mingw32-make.exe? To build it by himself by `make` call. – Gaurav Goswami May 04 '20 at 19:48
  • Makefile, generated by CMake, is not "transferrable". Your friend needs to run `cmake` too. – Tsyvarev May 04 '20 at 20:21

0 Answers0