-
Notifications
You must be signed in to change notification settings - Fork 76
Building library
CMake build system is used to configure the library for building. You can get more information about CMake in the documentation.
CMake encourages to use out-of-source builds to not to pollute the directory with source code with compiled binaries. Typical building scenario on UNIX-like system looks as following:
mkdir ./plibsys-build
cd ./plibsys-build
cmake -DCMAKE_BUILD_TYPE=Release ../plibsys
make
The above example assumes that source code and build directories are on the same hierarchy level. It is recommended to run tests after building the library. To do that, perform the following command in the build directory:
ctest
Use -G
option to select build system other than based on Makefile
. To pass any variable to CMake use -D
option.
Use CMAKE_C_COMPILER
variable to override default C compiler, and CMAKE_CXX_COMPILER
variable to override default C++ compiler.
Use CMAKE_C_FLAGS
variable to add specific compilation flags to C compiler, and CMAKE_CXX_FLAGS
variable for C++ compiler.
Atomic operations can be performed in a lock-free way or not. Lock-free way requires hardware and software support from the target platform. Non lock-free way utilizes simulation of the memory barrier through the thread synchronization primitives, i.e. mutexes. The latter approach is slower.
Currently not all compilers provide support for lock-free atomic operations on all target platforms. Generally speaking there are two widely used models of lock-free atomic operations among the compilers:
- GCC-styled __sync* calls. They are supported by some other compilers, but marked as deprecated.
- C++11 memory model (also introduced in C11) __atomic* calls. A modern approach, but a few compilers have support for these calls, though the situation is getting better.
You can override automatically detected atomic model using PLIBSYS_ATOMIC_MODEL
CMake variable with one of the following values:
- "sync" for __sync* calls.
- "c11" for __atomic* cals.
- "win" for Windows atomic calls.
- "sim" for simulation (slow) approach.
By default C++11 memory model is used if available. But sometimes it can bring more troubles than the profit (you need to pass proper compiler flags, link with proper atomic libraries, implement atomic operations on unsupported platforms). If C++11 memory model is not available then GCC-styled model will be used if possible.
More about C++11 memory model in GCC:
By default shared and static libraries are built both. You can disable the static build by passing PLIBSYS_BUILD_STATIC=OFF
variable to CMake while configuring the project.
Code coverage build can be enabled using PLIBSYS_COVERAGE
option. Disabled by default.
To disable building tests use PLIBSYS_TESTS
option. Enabled by default.
To disable building HTML documentation with Doxygen tool use PLIBSYS_BUILD_DOC
option. Enabled by default.