-1

I'm trying to build MySQL from source but I hit a configuration error:

CMake Error at CMakeLists.txt:283 (MESSAGE):
  Please do not build in-source.  Out-of source builds are highly
  recommended: you can have multiple builds for the same source, and there is
  an easy way to do cleanup, simply remove the build directory (note that
  'make clean' or 'make distclean' does *not* work)
  You *can* force in-source build by invoking cmake with
  -DFORCE_INSOURCE_BUILD=1
-- Source directory /usr/local/mysql-source
-- Binary directory /usr/local/mysql-source
-- Configuring incomplete, errors occurred!
See also "/usr/local/mysql-source/CMakeFiles/CMakeOutput.log".
The command '/bin/sh -c cd /usr/local/mysql-source/   && cmake   -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/install   -DWITH_INNOBASE_STORAGE_ENGINE=1   -DWITHOUT_TOKUDB=1   -DMYSQL_DATADIR=/usr/local/mysql/install/data   -DDOWNLOAD_BOOST=1   -DWITH_BOOST=/usr/local/mysql/install/boost   -DMYSQL_UNIX_ADDR=/usr/local/mysql/install/tmp/mysql.sock' returned a non-zero code: 1

I thought the CMAKE_INSTALL_PREFIX option was supposed to do exactly that, that is, specify the binary installation directory.

Here are my build commands:

RUN apt-get install -y libncurses-dev

COPY mysql-8.0.15.tar.gz /usr/local/
WORKDIR /usr/local
RUN gzip -d mysql-8.0.15.tar.gz \
  && tar -xvf mysql-8.0.15.tar \
  && mv mysql-8.0.15 mysql-source

RUN mkdir mysql
WORKDIR /usr/local/mysql/
RUN mkdir install \
  && mkdir install/data \
  && mkdir install/var \
  && mkdir install/etc \
  && mkdir install/tmp

RUN cd /usr/local/mysql-source/ \
  && cmake \
  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/install \
  -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  -DWITHOUT_TOKUDB=1 \
  -DMYSQL_DATADIR=/usr/local/mysql/install/data \
  -DDOWNLOAD_BOOST=1 \
  -DWITH_BOOST=/usr/local/mysql/install/boost \
  -DMYSQL_UNIX_ADDR=/usr/local/mysql/install/tmp/mysql.sock \
  && make \
  && make install \
  && make clean

I read other similar questions but none explained why this CMAKE_INSTALL_PREFIX option was not doing it, nor if there was any other option.

I'm hoping not to have to edit the Makefile as I'm in a Docker environment.

I tried adding the -DDESTDIR=/usr/local/mysql/install \ option but the issue remained the exact same.

The cmake documentation didn't help me.

UPDATE: Following the provided solution I could successfully build with the command:

WORKDIR /usr/local/mysql/
RUN cmake -- -j4 \
  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/install \
  -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  -DWITHOUT_TOKUDB=1 \
  -DMYSQL_DATADIR=/usr/local/mysql/install/data \
  -DDOWNLOAD_BOOST=1 \
  -DWITH_BOOST=/usr/local/mysql/install/boost \
  -DMYSQL_UNIX_ADDR=/usr/local/mysql/install/tmp/mysql.sock \
  /usr/local/mysql-source/ \
  && make \
  && make install \
  && make clean

with the -- -j4 option being optional here, as it only tells cmake to use the 4 cores of the computer.

Stephane
  • 11,836
  • 25
  • 112
  • 175
  • Do you mean `cmake -H. -Bdir -G"Unix Makefiles"` where `-H` option is the source directory, `-B` option is the build directory (maybe absolute paths)? In newer CMake versions `-H` and `-S` denote the same. -B also creates the builddir if it does not exist. – vre Feb 09 '19 at 14:57
  • I mean cmake with the options I listed in the question. – Stephane Feb 09 '19 at 15:02
  • 1
    Variable `CMAKE_INSTALL_PREFIX` specifies **install** directory, not a **build** one. Build directory is the one from which `cmake` is called, in that case source directory may be given by the non-option argument. Alternatively, you may specify build directory with `-B` option, as noted by @vre. – Tsyvarev Feb 09 '19 at 18:02

1 Answers1

1

CMake is complaining about the fact you are trying to build MySQL in the source tree and therefore tainting it. A typical scenario is to use a separate builddir (that might be located under the source dir, but not necessarily need to). CMAKE_INSTALL_PREFIX is the place where after a successful build the binaries are installed to.

Create your solutions with

cmake -Hsourcedir -Bbuilddir ....<all your options>

CMake will create the builddir if it does not exist. In your case this could be called from the current source dir with

cmake -H. -Bbuilddir ....<all your options>

Newer CMake versions know about a -S option that is equivalent to -H Later then the build tool mode of CMake comes very handy.

cmake --build builddir --target all --config Release -- -j4

It uses the default build tool of the platform (make in your case). (give special options to the build tool after the trailing --, in this case -j4 for a parallel build)

Installing then is done by

cmake --build builddir --target install --config Release

AFAIK if you omit the --config Releaseoption CMake will use the CMAKE_BUILD_TYPE that was specified at configuration time either from CMakeLists.txt or from the command line.

Your entire RUN command then would look as follows:

RUN cd /usr/local/mysql-source/ \
  && cmake -H. -Bbuilddir \
  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/install \
  -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  -DWITHOUT_TOKUDB=1 \
  -DMYSQL_DATADIR=/usr/local/mysql/install/data \
  -DDOWNLOAD_BOOST=1 \
  -DWITH_BOOST=/usr/local/mysql/install/boost \
  -DMYSQL_UNIX_ADDR=/usr/local/mysql/install/tmp/mysql.sock \
  && cmake --build builddir --target all \
  && cmake --build builddir --target install \
  && cmake --build builddir --target clean
vre
  • 6,041
  • 1
  • 25
  • 39
  • `--config Release` is useful for multi-configuration generators like Visual Studio where `CMAKE_BUILD_TYPE` is not used. Otherwise it should just be ignored. – fdk1342 Feb 09 '19 at 16:38
  • Exactly. Thank you for pointing it out. – vre Feb 09 '19 at 17:09