[opus] Opus cmake build
Marcus Asteborg
xnorpx at outlook.com
Wed Apr 10 15:29:53 UTC 2019
Hi Mark,
Thanks for the feedback.
By default CMake is building the static library in debug, to get other things one has to explicit turn it on.
To build in release mode for CMake you use the following flag:
-DCMAKE_BUILD_TYPE=Release
https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
CMAKE_BUILD_TYPE — CMake 3.14.1 Documentation<https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html>
CMAKE_BUILD_TYPE¶. Specifies the build type on single-configuration generators. This statically specifies what build type (configuration) will be built in this build tree.
cmake.org
To build shared library you use the following flag:
-DBUILD_SHARED_LIBS=ON
https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html
BUILD_SHARED_LIBS — CMake 3.14.1 Documentation<https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html>
BUILD_SHARED_LIBS¶. Global flag to cause add_library() to create shared libraries if on.. If present and true, this will cause all libraries to be built shared unless the library was explicitly added as a static library.
cmake.org
To build tests use the following flags:
-DBUILD_TESTING=ON
Then you can use: ctest -j 4 to run the test in parallel
For programs use:
-DBUILD_PROGRAMS=ON
For the missing build flags this is great feedback and I will to fix those:
Add:
-DENABLE_HARDENING,
-D_FORTIFY_SOURCE=2
Add option:
-fstack-protector-strong (on compilers where it is supported, unless
disabled with --disable-stack-protector).
-DCUSTOM_MODES
Please let me know if there is more missing flags.
I might reach out to you directly if I am having issues with the build with these flags.
I would like to aim that CMake can produce binaries similar as autotools with same build flags etc.
Some documentation regarding these options for people not familiar with CMake would probably also help.
Best Regards Marcus
________________________________
From: Mark Harris <markh.sj at gmail.com> on behalf of Mark Harris <mark.hsj at gmail.com>
Sent: Wednesday, April 10, 2019 07:24
To: opus at xiph.org
Cc: Marcus Asteborg
Subject: Opus cmake build
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xiph.org/pipermail/opus/attachments/20190410/c893981a/attachment-0001.html>
More information about the opus
mailing list