Release workflow and useful developer settings in cmake/ConfigUser.cmake

Added by Florian over 5 years ago

Here are some of the warning flags that I have enabled:

if(UNIX)
  # warnings:
  #-Wno-missing-field-initializers -Wno-sign-compare -Wno-unused-parameter
  #-Werror=pointer-to-int-cast -Wdeclaration-after-statement
  #-Werror-implicit-function-declaration -Wformat-nonliteral -Wformat-security
  #-Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wmissing-noreturn
  #-Wnested-externs -Wpointer-arith
  # check for undefined behavior:
  # -ftrapv -fcatch-undefined-behavior
  set (_extra_warnings -Wextra -Wundef -Wno-unused-parameter
    #-Wshadow -Wcast-align -Wfloat-equal -Wwrite-strings
    -Wpointer-arith -Wno-long-long)
  string (REPLACE ";" " " _extra_warnings "${_extra_warnings}")

  # Extra debugging for developers:
  #set(CMAKE_C_FLAGS_RELEASE "-ggdb3 ${CMAKE_C_FLAGS_RELEASE}") # default is -O3 -DNDEBUG
  #set(CMAKE_C_FLAGS_RELEASE "-ggdb3 -O2")
  set(CMAKE_C_FLAGS_DEBUG "-ggdb3 -O0")
  set(CMAKE_C_FLAGS "-std=gnu99 -fstrict-aliasing -Wall -Wdeclaration-after-statement ${_extra_warnings} ${CMAKE_C_FLAGS}")
  set(CMAKE_C_FLAGS_RELEASE "-Wuninitialized -Wstrict-aliasing ${CMAKE_C_FLAGS_RELEASE}")

  # clang flags
  if (CMAKE_C_COMPILER MATCHES clang)
    set(CMAKE_C_FLAGS_RELEASE "-Wno-unused-but-set-variable ${CMAKE_C_FLAGS_RELEASE}")
    set(CMAKE_C_FLAGS_RELWITHDEBINFO "-ftrapv -fcatch-undefined-behavior ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
  endif (CMAKE_C_COMPILER MATCHES clang)

  add_definitions(-DDEBUG)
  #set (CMAKE_C_FLAGS "-Wextra ${CMAKE_C_FLAGS}")            # extra warnings
  #set (CMAKE_LINK_DEPENDS_DEBUG_MODE TRUE)                  # debug link dependencies

endif(UNIX)
The clang flags might be useful to detect memory corruption: -ftrapv -fcatch-undefined-behavior

If you do regular packaging this saves some typing:

# Uncomment when making a release build.  Note: have to manually set
# GMT_SOURCE_CODE_CONTROL_VERSION_STRING in cmake/ConfigDefaults.cmake
# when exporting a release source tree!
execute_process (COMMAND svnversion
  OUTPUT_VARIABLE GMT_SOURCE_CODE_CONTROL_VERSION_STRING
  OUTPUT_STRIP_TRAILING_WHITESPACE)
You still have to update cmake/ConfigDefaults.cmake in a source release!

Building a release, e.g., Mac.app is just

make -j8 gmt_doc_shrink
make -j8 package
or
make -j8
make -j8 gmt_doc_shrink
cpack -G Bundle
be sure to set the correct release version in cmake/Config.cmake or cmake/ConfigDefaults.cmake first.

Source release: set the correct release version, then

make -j8 gmt_doc_shrink
make -j8 gmt_release
and edit GMT_SOURCE_CODE_CONTROL_VERSION_STRING in cmake/ConfigDefaults.cmake and create a tarball.