patrickfrey/strus

Cannot set custom CFLAGS or CXXFLAGS

andreasbaumann opened this issue · 1 comments

For instance:

cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DLIB_INSTALL_DIR=lib -DCMAKE_CXX_FLAGS_RELEASE='-g -O0' -DCMAKE_C_FLAGS_RELEASE='-g -O0' .

or

cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DLIB_INSTALL_DIR=lib -DCMAKE_CXX_FLAGS='-g -O0' -DCMAKE_C_FLAGS='-g -O0' .

has now effect as I can see in:

Compiler:
  C++ compilation flags: -std=c++98  -Wall -pedantic -g -Wfatal-errors -fvisibility=hidden -fPIC -O3
  C compilation flags: -std=c99 -Wall -pedantic -Wfatal-errors -fPIC -O3

This is because in cmake/build_rules.cmake the corresponding flag variables are
just brutally set:

if(CMAKE_COMPILER_IS_GNUCXX)
set( STRUS_OPTIMIZATION_LEVEL "3" )
set( CMAKE_CXX_FLAGS "-std=c++98  -Wall -pedantic -g -Wfatal-errors -fvisibility=hidden -fPIC -O${STRUS_O
PTIMIZATION_LEVEL}" )
set( CMAKE_C_FLAGS "-std=c99 -Wall -pedantic -Wfatal-errors -fPIC -O${STRUS_OPTIMIZATION_LEVEL}" )
endif()

With 'make VERBOSE=1' I can even see, that flags get used in parallel:

[ 33%] Building CXX object src/utils/CMakeFiles/strus_private_utils.dir/utils.cpp.o
cd /home/user/strusAnalyzer_tsv/src/utils && /bin/c++    -I/home/user/strusAnalyzer_tsv/include  -std=c++98  -Wall -pedantic -g -Wfatal-errors -fvisibility=hidden -fPIC -O3 -g -O0   -o CMakeFiles/strus_private_utils.dir/utils.cpp.o -c /home/user/strusAnalyzer_tsv/src/utils/utils.cpp

O3 and O0 in parallel.

All cmake support should be fixed in this regard, see also tipps in:

http://voices.canonical.com/jussi.pakkanen/2013/03/26/a-list-of-common-cmake-antipatterns/

Several reasons why this fix is important:

  • Developers want to set debug options like optimization levels when calling cmake,
    not by editing a file
  • Packagers must respect the flags of their distribution, it's not allowed to
    use your own flags.

This bug is valid for all strus repos.

Some third-party modules have to set their own compilation flags (snowball, textcat, etc.).
Also there we should combine the flags set by the user and the default ones known to
work on the code.