[opus] Opus cmake build

Mark Harris mark.hsj at gmail.com
Wed Apr 10 14:24:55 UTC 2019

I tried the new cmake-based build system to build Opus on Linux and
macOS.  I'm not familiar with cmake but based on instructions I found
online I used it as follows:

 - mkdir build
 - cd build
 - cmake -DCMAKE_INSTALL_PREFIX:PATH=<install-path> ..
 - make
 - ctest
 - make install

Although the "make" command completed, it reported that optimizations
were disabled:

opus_decoder.c:37:10: warning: You appear to be compiling without
optimization, if so opus will be very slow. [-W#pragma-messages]

The autotools build builds with -g -O2, unless overridden.  It appears
that cmake is using neither of those options.  I don't have a strong
opinion on -g, but for Opus it is important to build with optimizations
enabled; so much so that this message was added so that if somehow the
user managed to build with optimizations off they would be made aware
that they messed something up.  How can we make this build by default
with optimizations enabled?

Checking the compiler options that cmake was using, I also found that it
was enabling custom modes with -DCUSTOM_MODES.  This is not a
recommended option, and the autotools build does not enable this unless
configured with --enable-custom-modes.  And it is not present at all in
the Visual Studio project files, so it is not clear where this came
from.  I could not even find an option to disable this with cmake.  This
should default to disabled.

To reduce the chance that Opus can be used as part of a security
exploit, Opus builds with a number of hardening options in a default
autotools build, including -DENABLE_HARDENING, -D_FORTIFY_SOURCE=2, and
-fstack-protector-strong (on compilers where it is supported, unless
disabled with --disable-stack-protector).  It also enables a number of
compiler warnings by default, to help catch mistakes.  However it
appears that all of that is lost in the cmake build.  How can we get
those added?

When I ran the ctest command it reported "No test configuration file
found!" and did not run any of the tests.  Is this the correct command?
With autotools the tests are run using "make check", but that did not
work either using the cmake-generated Makefile.

I went ahead and installed with "make install" without running the
tests, but checking the install location I could not find the libopus.so
file (or libopus.dylib on macOS).  There was a libopus.a but the shared
library was missing.  In the autotools build both libopus.so (or
libopus.dylib on macOS) and libopus.a are installed in the lib directory
by default.  I could not find a cmake option for this either.

Is there work to bring the cmake build up to the level of what we have
today with the autotools build, or is it intended only as an alternative
to the Visual Studio project files for Windows users?

 - Mark

More information about the opus mailing list