CMake error "attempted to write a file ... into a source directory."

5.2k Views Asked by At

I got errors after update CMake to version 3.12.1

CMake Error at /usr/local/share/cmake-3.12/Modules/CMakeDetermineSystem.cmake:174 (file):
  file attempted to write a file:
  /home/wow/TrinityCore/CMakeFiles/CMakeOutput.log into a source directory.
Call Stack (most recent call first):
  CMakeLists.txt:19 (project)


CMake Error: CMake was unable to find a build program corresponding to "Unix 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: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

make is installed

GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu

g++ is installed too. Ubuntu Version 14.04.5.

How to solve that error?

1

There are 1 best solutions below

0
On

As already noted in the comments, the message

file attempted to write a file ... into a source directory

is a result of CMAKE_DISABLE_SOURCE_CHANGES variable set in the project's CMakeLists.txt. This setting activates the check, that CMake project won't create any file under the source directory. (More precise description of this variable setting see in that answer).

Normally, setting CMAKE_DISABLE_SOURCE_CHANGES variable is accompanied with setting CMAKE_DISABLE_IN_SOURCE_BUILD variable, with literal meaning:

The project should NOT be built in-source.

Solution is to build the project out-of-source, in the build directory which differs from the source one.

E.g. that way:

cd <project-dir>
mkdir build
cd build
cmake ..