Hi all:

I've been tinkering with optimizing zeek for performance, and came across a problem with CFLAGS/CXXFLAGS specified to the configure script.  Lets say I want to try the -O3 flag for more aggressive optimization than the default -O2:

$ CFLAGS='-O3' CXXFLAGS='-O3' ./configure
====================|  Bro Build Summary  |=====================
CFLAGS:            -O3 -Wall -Wno-unused -O2 -g -DNDEBUG
CXXFLAGS:          -O3 -Wall -Wno-unused -std=c++11 -O2 -g -DNDEBUG

Note that the supplied CFLAGS/CXXFLAGS is before the default options for the build.  From the GCC man page:
If you use multiple -O options, with or without level numbers, the last such option is the one that is effective.
This, of course, means that the -O3 specified will not take effect.  Running make -in confirms that those flags are being passed to the compiler.

There appear to be several alternatives to allow supplied flags to override the defaults, the most reasonable appearing to be modifying the build commands to apply CFLAGS/CXXFLAGS after the defaults.

I'm not a cmake maven, but it seems likely that lines like:
set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS}   ${bro_cache_CMAKE_C_FLAGS}")

could be reversed ala:

set(CMAKE_C_FLAGS   "${bro_cache_CMAKE_C_FLAGS}   ${CMAKE_C_FLAGS}")

to achieve that effect.

(Yes, I know --build-type=Release compiles with -O3, but the point remains that overriding flags via environment variables is generally expected to be operative)