Closed PetrusZ closed 1 year ago
The C_FLAGS in the CMakeFiles.txt's are mostly inherited from earlier code.
Can you review them all and make suggestions?
lib/CMakeLists.txt
# Common Linux cflags
if ( UNIX AND NOT APPLE )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g" )
endif()
if ( WIN32 )
message( STATUS "Building for Windows " )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_WIN32 -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g" )
endif()
# Common x86/x86_64 cflags
if( NOT NO_MARCH_NATIVE AND CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Ofast -march=native" )
message( STATUS "Using CFLAGS with -march=native" )
message( STATUS "*** ONLY USE THIS WHEN COMPILING ON THE MACHINE THAT WILL RUN UXPLAY" )
message( STATUS " run \"cmake -DNO_MARCH_NATIVE=ON\" to switch off this compiler option" )
else()
message( STATUS "Not using -march=native" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2" )
endif()
message( STATUS "using CMAKE_CFLAGS: " ${CMAKE_C_FLAGS} )
OK, I'll debug/test it tomorrow, it's a little late today.
@PetrusZ I have rearranged lib/CMakeLists.txt so any $CFLAGS in the user's build environment are postpended (not prepended) to Cflags. This will fix the reported issue.
Thank you so much!
man gcc says: "If you use multiple -O options, with or without level numbers, the last such option is the one that is effective".
https://github.com/FDH2/UxPlay/blob/a5f2ba39b227dc0f7feaf15ec6ece908e9be31bd/lib/CMakeLists.txt#L16
So, since the build system adds -O after -O provided by my CFLAGS/CXXFLAGS means that it is overwritten and unless there are known issues with -O configured by the user, the build system should not overwrite -O.
See also: https://bugs.gentoo.org/887789