From 698500fd3e0d3179b0e00773d1446c8dbfb54ba4 Mon Sep 17 00:00:00 2001 From: Alexander Shaduri Date: Mon, 1 Mar 2021 14:04:35 +0400 Subject: [PATCH] Refactored the build config header and macros; Added OS- and compiler-specific options and macros to cmake. --- CMakeLists.txt | 10 ++ src/CMakeLists.txt | 2 +- src/applib/CMakeLists.txt | 1 - src/applib/examples/CMakeLists.txt | 4 - src/applib/storage_detector.cpp | 2 +- src/applib/storage_detector_helpers.h | 1 + src/applib/storage_detector_linux.cpp | 4 +- src/applib/storage_detector_linux.h | 2 +- src/applib/storage_detector_other.cpp | 2 +- src/applib/storage_detector_other.h | 2 +- src/applib/storage_detector_win32.cpp | 2 +- src/applib/storage_detector_win32.h | 2 +- src/build_config/CMakeLists.txt | 144 +++++++++--------- .../{config.in.h => build_config.in.h} | 22 ++- src/build_config/compiler_options.cmake | 85 ++++++++--- src/gsc_about_dialog.cpp | 41 ++--- src/gsc_add_device_window.cpp | 1 + src/gsc_init.cpp | 24 +-- src/gsc_preferences_window.cpp | 1 + src/hz/examples/CMakeLists.txt | 3 - src/libdebug/CMakeLists.txt | 4 +- src/libdebug/dcmdarg.cpp | 2 +- src/libdebug/examples/CMakeLists.txt | 1 - src/rconfig/CMakeLists.txt | 3 + src/rconfig/examples/CMakeLists.txt | 1 - toolchains/win32-prod-gcc-release.cmake | 9 ++ 26 files changed, 228 insertions(+), 147 deletions(-) rename src/build_config/{config.in.h => build_config.in.h} (52%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5520c1e..77c95d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,15 +12,25 @@ include(${CMAKE_SOURCE_DIR}/version.txt) project(gsmartcontrol VERSION ${CMAKE_PROJECT_VERSION}) + # Provide DATADIR, etc... include(GNUInstallDirs) include(src/build_config/compiler_options.cmake) + +# Disable RPATH manipulation, we don't have shared libraries +set(CMAKE_SKIP_BUILD_RPATH TRUE) +set(CMAKE_SKIP_INSTALL_RPATH TRUE) + + option(APP_BUILD_EXAMPLES "Build examples" ON) + configure_file(gsmartcontrol.in.spec gsmartcontrol.spec) + + add_subdirectory(contrib) add_subdirectory(data) add_subdirectory(debian.dist) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c8d27d5..d9bd921 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,12 +51,12 @@ if (WIN32) target_sources(gsmartcontrol PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/gsc_winres.rc") endif() + target_link_libraries(gsmartcontrol PRIVATE applib app_pcrecpp_interface app_gtkmm_interface - compiler_warnings build_config ) diff --git a/src/applib/CMakeLists.txt b/src/applib/CMakeLists.txt index 7ce24f9..3ee0569 100644 --- a/src/applib/CMakeLists.txt +++ b/src/applib/CMakeLists.txt @@ -59,7 +59,6 @@ target_link_libraries(applib app_pcrecpp_interface app_gettext_interface PRIVATE - compiler_warnings build_config ) diff --git a/src/applib/examples/CMakeLists.txt b/src/applib/examples/CMakeLists.txt index 4cb7864..563f2c8 100644 --- a/src/applib/examples/CMakeLists.txt +++ b/src/applib/examples/CMakeLists.txt @@ -17,7 +17,6 @@ target_sources(smartctl_executor_example PRIVATE ) target_link_libraries(smartctl_executor_example PRIVATE applib - compiler_warnings ) @@ -27,7 +26,6 @@ target_sources(smartctl_parser_example PRIVATE ) target_link_libraries(smartctl_parser_example PRIVATE applib - compiler_warnings ) @@ -37,7 +35,6 @@ target_sources(spawn_example PRIVATE ) target_link_libraries(spawn_example PRIVATE applib - compiler_warnings ) @@ -47,5 +44,4 @@ target_sources(storage_detector_example PRIVATE ) target_link_libraries(storage_detector_example PRIVATE applib - compiler_warnings ) diff --git a/src/applib/storage_detector.cpp b/src/applib/storage_detector.cpp index 816dd94..78b6663 100644 --- a/src/applib/storage_detector.cpp +++ b/src/applib/storage_detector.cpp @@ -16,7 +16,7 @@ Copyright: #include #include -#include "config.h" // CONFIG_* +#include "build_config.h" // CONFIG_* #include "hz/debug.h" diff --git a/src/applib/storage_detector_helpers.h b/src/applib/storage_detector_helpers.h index 716d68c..c417940 100644 --- a/src/applib/storage_detector_helpers.h +++ b/src/applib/storage_detector_helpers.h @@ -21,6 +21,7 @@ Copyright: #include // Glib::shell_quote(), compose #include +#include "build_config.h" #include "executor_factory.h" #include "storage_device.h" #include "rconfig/rconfig.h" diff --git a/src/applib/storage_detector_linux.cpp b/src/applib/storage_detector_linux.cpp index 764d878..84762e6 100644 --- a/src/applib/storage_detector_linux.cpp +++ b/src/applib/storage_detector_linux.cpp @@ -9,7 +9,7 @@ Copyright: /// \weakgroup applib /// @{ -#include "config.h" // CONFIG_* +#include "build_config.h" // CONFIG_* #if defined CONFIG_KERNEL_LINUX @@ -26,7 +26,7 @@ Copyright: #include "hz/debug.h" #include "hz/fs.h" #include "hz/string_num.h" -#include "rconfig/config.h" +#include "rconfig/rconfig.h" #include "app_pcrecpp.h" #include "storage_detector_linux.h" #include "storage_detector_helpers.h" diff --git a/src/applib/storage_detector_linux.h b/src/applib/storage_detector_linux.h index c825c8a..a873328 100644 --- a/src/applib/storage_detector_linux.h +++ b/src/applib/storage_detector_linux.h @@ -12,7 +12,7 @@ Copyright: #ifndef STORAGE_DETECTOR_LINUX_H #define STORAGE_DETECTOR_LINUX_H -#include "config.h" // CONFIG_* +#include "build_config.h" // CONFIG_* #if defined CONFIG_KERNEL_LINUX diff --git a/src/applib/storage_detector_other.cpp b/src/applib/storage_detector_other.cpp index 6d0464b..f53aeaf 100644 --- a/src/applib/storage_detector_other.cpp +++ b/src/applib/storage_detector_other.cpp @@ -9,7 +9,7 @@ Copyright: /// \weakgroup applib /// @{ -#include "config.h" // CONFIG_* +#include "build_config.h" // CONFIG_* #if !defined CONFIG_KERNEL_LINUX && !defined CONFIG_KERNEL_FAMILY_WINDOWS diff --git a/src/applib/storage_detector_other.h b/src/applib/storage_detector_other.h index 52dc9a2..eadaeae 100644 --- a/src/applib/storage_detector_other.h +++ b/src/applib/storage_detector_other.h @@ -12,7 +12,7 @@ Copyright: #ifndef STORAGE_DETECTOR_OTHER_H #define STORAGE_DETECTOR_OTHER_H -#include "config.h" // CONFIG_* +#include "build_config.h" // CONFIG_* #if !defined CONFIG_KERNEL_LINUX && !defined CONFIG_KERNEL_FAMILY_WINDOWS diff --git a/src/applib/storage_detector_win32.cpp b/src/applib/storage_detector_win32.cpp index 42c2ee0..dc1a900 100644 --- a/src/applib/storage_detector_win32.cpp +++ b/src/applib/storage_detector_win32.cpp @@ -9,7 +9,7 @@ Copyright: /// \weakgroup applib /// @{ -#include "config.h" // CONFIG_* +#include "build_config.h" // CONFIG_* #if defined CONFIG_KERNEL_FAMILY_WINDOWS diff --git a/src/applib/storage_detector_win32.h b/src/applib/storage_detector_win32.h index d532eae..da43c3e 100644 --- a/src/applib/storage_detector_win32.h +++ b/src/applib/storage_detector_win32.h @@ -12,7 +12,7 @@ Copyright: #ifndef STORAGE_DETECTOR_WIN32_H #define STORAGE_DETECTOR_WIN32_H -#include "config.h" // CONFIG_* +#include "build_config.h" // CONFIG_* #if defined CONFIG_KERNEL_FAMILY_WINDOWS diff --git a/src/build_config/CMakeLists.txt b/src/build_config/CMakeLists.txt index ffb7e5f..6ac64cf 100644 --- a/src/build_config/CMakeLists.txt +++ b/src/build_config/CMakeLists.txt @@ -4,56 +4,83 @@ # (C) 2021 Alexander Shaduri ############################################################################### +# We print these here (as opposed to compiler_options.cmake) because it's the final state of these variables. + # Host system +message(STATUS "Host system:") message(STATUS "CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}") +message(STATUS "CMAKE_HOST_SYSTEM_VERSION: ${CMAKE_HOST_SYSTEM_VERSION}") +message(STATUS "CMAKE_HOST_SYSTEM_PROCESSOR: ${CMAKE_HOST_SYSTEM_PROCESSOR}") # Target system +message(STATUS "Target system:") message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") +message(STATUS "CMAKE_SYSTEM_VERSION: ${CMAKE_SYSTEM_VERSION}") +message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") +message(STATUS "CMAKE_SIZEOF_VOID_P: ${CMAKE_SIZEOF_VOID_P}") + +# Compiler +message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}") +message(STATUS "CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}") +message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}") +message(STATUS "CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN: ${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}") +message(STATUS "CMAKE_CXX_COMPILER_TARGET: ${CMAKE_CXX_COMPILER_TARGET}") +message(STATUS "CMAKE_CXX_COMPILE_FEATURES: ${CMAKE_CXX_COMPILE_FEATURES}") + +message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") +message(STATUS "CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}") +message(STATUS "CMAKE_CXX_FLAGS_MINSIZEREL: ${CMAKE_CXX_FLAGS_MINSIZEREL}") +message(STATUS "CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}") +message(STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") + +message(STATUS "CMAKE_STATIC_LINKER_FLAGS: ${CMAKE_STATIC_LINKER_FLAGS}") +message(STATUS "CMAKE_STATIC_LINKER_FLAGS_DEBUG: ${CMAKE_STATIC_LINKER_FLAGS_DEBUG}") +message(STATUS "CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL: ${CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL}") +message(STATUS "CMAKE_STATIC_LINKER_FLAGS_RELEASE: ${CMAKE_STATIC_LINKER_FLAGS_RELEASE}") +message(STATUS "CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO: ${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO}") + +message(STATUS "CMAKE_SHARED_LINKER_FLAGS: ${CMAKE_SHARED_LINKER_FLAGS}") +message(STATUS "CMAKE_SHARED_LINKER_FLAGS_DEBUG: ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}") +message(STATUS "CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL: ${CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL}") +message(STATUS "CMAKE_SHARED_LINKER_FLAGS_RELEASE: ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") +message(STATUS "CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO: ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}") + +message(STATUS "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}") +message(STATUS "CMAKE_EXE_LINKER_FLAGS_DEBUG: ${CMAKE_EXE_LINKER_FLAGS_DEBUG}") +message(STATUS "CMAKE_EXE_LINKER_FLAGS_MINSIZEREL: ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}") +message(STATUS "CMAKE_EXE_LINKER_FLAGS_RELEASE: ${CMAKE_EXE_LINKER_FLAGS_RELEASE}") +message(STATUS "CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO: ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}") + +# These variables are used in build_config.in.h +if ("${CMAKE_SYSTEM_NAME}" MATCHES "Windows" + OR "${CMAKE_SYSTEM_NAME}" MATCHES "CYGWIN.*") + if (CMAKE_SIZEOF_VOID_P EQUAL 4) + set(CONFIG_KERNEL_WINDOWS32 TRUE) + else() + set(CONFIG_KERNEL_WINDOWS64 TRUE) + endif() +elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") + set(CONFIG_KERNEL_LINUX TRUE) +elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" + OR "${CMAKE_SYSTEM_NAME}" MATCHES "GNU/kFreeBSD") + set(CONFIG_KERNEL_FREEBSD TRUE) +elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "DragonFly") + set(CONFIG_KERNEL_DRAGONFLY TRUE) +elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "NetBSD") + set(CONFIG_KERNEL_NETBSD TRUE) +elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "OpenBSD") + set(CONFIG_KERNEL_OPENBSD TRUE) +elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "SunOS" OR "${CMAKE_SYSTEM_NAME}" MATCHES "Solaris") + set(CONFIG_KERNEL_SOLARIS TRUE) +elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") + set(CONFIG_KERNEL_DARWIN TRUE) +elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "QNX") + set(CONFIG_KERNEL_QNX TRUE) +endif() -# TODO Add these flags +# Additionally, these macros are defined by OS / compilers: -# Note: Some operating systems / compilers have built-in defines. -# For gcc, check with -# $ gcc -dM -E - < /dev/null - -# -mms-bitfields (target os env = mingw32, mingw64, cygwin; compiler = gnu, clang) - -# gcc warnings: -Wall -Wcast-align -Wcast-qual -Wconversion -#-Wfloat-equal -Wnon-virtual-dtor -Woverloaded-virtual -#-Wpointer-arith -Wshadow -Wsign-compare -Wsign-promo -Wundef -Wwrite-strings - -# clang warnings: gcc warnings plus: -# -Wno-sign-conversion -Wno-format-security - -# debug builds: -# -DDEBUG=1 -DDEBUG_BUILD=1 -O0 -g3 - -# optimized builds (target mingw32): -# -g0 -O3 -s -march=i686 - -# optimized builds (target mingw64, cygwin): -# -g0 -O3 -s - -# optimized builds (i686, x86_64 only; others don't have "generic") -# -mtune=generic - - - -# host, target OS kernels (pattern, os name, C macro): -# *linux*, linux, LINUX -# i*86-*mingw* | i*86-*cygwin*, windows32, WINDOWS32 -# x86_64-*-mingw* | x86_64-*-cygwin*, windows64, WINDOWS64 -# *freebsd*, freebsd, FREEBSD -# *dragonfly*, dragonfly, DRAGONFLY -# *openbsd*, openbsd, OPENBSD -# *netbsd*, netbsd, NETBSD -# *solaris*, solaris, SOLARIS -# *darwin*, darwin, DARWIN -# *qnx*, qnx, QNX -# *, unknown, UNKNOWN - -# Notes: # Linux: gcc defines __linux__ on linux. Other defines include: __linux, __unix__, __gnu_linux__, # linux, unix, __i386__, i386. @@ -70,41 +97,20 @@ message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") # See http://glibc-bsd.alioth.debian.org/porting/PORTING . -# OS environments: -# *-gnu | gnu* (This includes gnu/linux, debian gnu/kfreebsd, debian gnu/netbsd...) -# cygwin -# mingw32 -# mingw64 -# freebsd (FreeBSD libc) -# dragonfly -# openbsd -# netbsd -# solaris -# darwin -# qnx -# unknown - -# MT flags -# -pthread -D_MT -D_THREAD_SAFE (linux/gcc, linux/clang, freebsd, dragonfly) -# -mthreads -D_THREAD_SAFE (win/gcc, win/clang) -# -pthread -D_REENTRANT (openbsd, netbsd) -# -pthreads -D_MT -D_THREAD_SAFE -D_REENTRANT (solaris) -# darwin, qnx - MT enabled by default. - - -include(CheckSymbolExists) +#include(CheckSymbolExists) # getrawpartition() for netbsd and openbsd in -lutil. -check_symbol_exists(getrawpartition "util.h" HAVE_GETRAWPARTITION) - +# This is just a check to see whether we have it. The code uses getrawpartition() without any checks on *BSD. +#check_symbol_exists(getrawpartition "util.h" HAVE_GETRAWPARTITION) +#message(STATUS "getrawpartition() detected: ${HAVE_GETRAWPARTITION}") # System-specific definitions add_library(build_config INTERFACE) -configure_file("config.in.h" "config.h" ESCAPE_QUOTES @ONLY) +configure_file("build_config.in.h" "build_config.h" ESCAPE_QUOTES @ONLY) target_sources(build_config INTERFACE - config.in.h + build_config.in.h ) target_include_directories(build_config INTERFACE "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/src/build_config/config.in.h b/src/build_config/build_config.in.h similarity index 52% rename from src/build_config/config.in.h rename to src/build_config/build_config.in.h index 08fd45a..0bb8bfc 100644 --- a/src/build_config/config.in.h +++ b/src/build_config/build_config.in.h @@ -15,14 +15,32 @@ Copyright: // Parts of this file are replaced by cmake -#define PACKAGE "@CMAKE_PROJECT_NAME@" -#define VERSION "@CMAKE_PROJECT_VERSION@" +#define PACKAGE_NAME "@CMAKE_PROJECT_NAME@" +#define PACKAGE_VERSION "@CMAKE_PROJECT_VERSION@" #define PACKAGE_PKGDATA_DIR "@CMAKE_INSTALL_DATADIR@/gsmartcontrol" #define PACKAGE_SYSCONF_DIR "@CMAKE_INSTALL_SYSCONFDIR@" #define PACKAGE_LOCALE_DIR "@CMAKE_INSTALL_LOCALEDIR@" #define PACKAGE_DOC_DIR "@CMAKE_INSTALL_DOCDIR@" +#ifdef DEBUG_BUILD + #define PACKAGE_TOP_SOURCE_DIR "@CMAKE_SOURCE_DIR@" +#endif + +#cmakedefine CONFIG_KERNEL_WINDOWS32 +#cmakedefine CONFIG_KERNEL_WINDOWS64 +#cmakedefine CONFIG_KERNEL_LINUX +#cmakedefine CONFIG_KERNEL_FREEBSD +#cmakedefine CONFIG_KERNEL_OPENBSD +#cmakedefine CONFIG_KERNEL_NETBSD +#cmakedefine CONFIG_KERNEL_DRAGONFLY +#cmakedefine CONFIG_KERNEL_SOLARIS +#cmakedefine CONFIG_KERNEL_DARWIN +#cmakedefine CONFIG_KERNEL_QNX + +#if defined CONFIG_KERNEL_WINDOWS32 || defined CONFIG_KERNEL_WINDOWS64 + #define CONFIG_KERNEL_FAMILY_WINDOWS +#endif diff --git a/src/build_config/compiler_options.cmake b/src/build_config/compiler_options.cmake index 869f3e7..2e4f61a 100644 --- a/src/build_config/compiler_options.cmake +++ b/src/build_config/compiler_options.cmake @@ -6,15 +6,28 @@ # This file is included from root CMakeLists.txt -# Set the default C++ standard +# --- Set the default C++ standard set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -# We need OS/compiler extensions, if available. +# Enable PIC, required on many systems +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + + +# --- OS / compiler extensions + +# These extensions are useful to enable OS-specific functionality like 64-bit file offsets. + +# Enable compiler extensions (like -std=gnu++17 instead of -std=c++17) +set(CMAKE_CXX_EXTENSIONS ON) # glibc: all-extensions macro: _GNU_SOURCE. # Defined automatically when used with glibc, but not others. +# We define it for all gcc systems. +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + add_compile_definitions(_GNU_SOURCE) +endif() # Solaris: The problem with solaris is that it has too many incompatible # feature test macros, and there is no enable-all macro. Autoconf @@ -30,32 +43,58 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # by default if one of the usual macros are encountered (_XOPEN_SOURCE, # _GNU_SOURCE, etc...). # See _mingw.h for details. -# TODO -# -D__USE_MINGW_ANSI_STDIO=1 -DWINVER=0x0600 +if (WIN32) + # No effect in MSVC, doesn't hurt. + add_compile_definitions(__USE_MINGW_ANSI_STDIO=1) + + # Enable Vista winapi + add_compile_definitions(WINVER=0x0600) +endif() # Darwin: Enable large file support -# -D_DARWIN_USE_64_BIT_INODE=1 +if ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") + add_compile_definitions(_DARWIN_USE_64_BIT_INODE=1) +endif() -# In many environments this enables large file support -# -D_FILE_OFFSET_BITS=64 - -set(CMAKE_CXX_EXTENSIONS ON) - -#set(CMAKE_POSITION_INDEPENDENT_CODE ON) +# In many environments this enables large file support. For others, it's harmless. +add_compile_definitions(_FILE_OFFSET_BITS=64) -# Add various OS/compiler-specific options that should always be there -# regardless of the machine. -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - add_compile_definitions(_GNU_SOURCE) + +# --- Compiler flags + +# Note: Some operating systems / compilers have built-in defines. +# For gcc, check with +# $ gcc -dM -E - < /dev/null + + +# MT flags +# -pthread -D_MT -D_THREAD_SAFE (linux/gcc, linux/clang, freebsd, dragonfly) +# -mthreads -D_THREAD_SAFE (win/gcc, win/clang) +# -pthread -D_REENTRANT (openbsd, netbsd) +# -pthreads -D_MT -D_THREAD_SAFE -D_REENTRANT (solaris) +# darwin, qnx - MT enabled by default. + + +# Enable compiler warnings +if (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang + OR ${CMAKE_CXX_COMPILER_ID} STREQUAL GNU + OR ${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang) + add_compile_options(-Wall -Wextra + -Wcast-qual -Wconversion -Wfloat-equal -Wnon-virtual-dtor -Woverloaded-virtual + -Wpointer-arith -Wshadow -Wsign-compare -Wsign-promo -Wundef -Wwrite-strings + ) +elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) + add_compile_options(/W4) endif() -# Enable warnings -add_library(compiler_warnings INTERFACE) -target_compile_options(compiler_warnings INTERFACE - $<$,$,$>: - -Wall -Wextra> - $<$: - /W4> -) +# GTK uses MS bitfields, so we need this in mingw +if (MINGW) + add_compile_options(-mms-bitfields) +endif() + +# Define macros to check the debug build +add_compile_definitions("$<$:DEBUG>") +add_compile_definitions("$<$:DEBUG_BUILD>") + diff --git a/src/gsc_about_dialog.cpp b/src/gsc_about_dialog.cpp index d7f2adb..84c53c9 100644 --- a/src/gsc_about_dialog.cpp +++ b/src/gsc_about_dialog.cpp @@ -9,8 +9,6 @@ Copyright: /// \weakgroup gsc /// @{ -#include "config.h" // VERSION - #include #include "hz/debug.h" @@ -21,6 +19,8 @@ Copyright: #include "gsc_about_dialog.h" +#include "build_config.h" // VERSION + // GtkBuilder needs this constructor @@ -31,35 +31,36 @@ GscAboutDialog::GscAboutDialog(BaseObjectType* gtkcobj, Glib::RefPtr")); + set_copyright(Glib::ustring::compose("Copyright (C) %1", + "2008 - 2021 Alexander Shaduri ")); - std::string authors_str = hz::data_file_get_contents("doc", "AUTHORS.txt", 1*1024*1024); // 1M - hz::string_any_to_unix(authors_str); + // std::string authors_str = hz::data_file_get_contents("doc", "AUTHORS.txt", 1*1024*1024); // 1M + // hz::string_any_to_unix(authors_str); - std::vector authors; - hz::string_split(authors_str, '\n', authors, true); + // std::vector authors; + // hz::string_split(authors_str, '\n', authors, true); + // + // for (auto& author : authors) { + // std::string s = author; + // hz::string_replace(s, " '@' ", "@"); // despammer + // hz::string_replace(s, " 'at' ", "@"); // despammer + // author = s; + // } + // set_authors(authors); - for (auto& author : authors) { - std::string s = author; - hz::string_replace(s, " '@' ", "@"); // despammer - hz::string_replace(s, " 'at' ", "@"); // despammer - author = s; - } - set_authors(authors); + // set_documenters(authors); - set_documenters(authors); - - std::string translators_str = hz::data_file_get_contents("doc", "TRANSLATORS.txt", 10*1024*1024); // 10M - set_translator_credits(translators_str); + // std::string translators_str = hz::data_file_get_contents("doc", "TRANSLATORS.txt", 10*1024*1024); // 10M + // set_translator_credits(translators_str); // run(); // don't use run - it's difficult to exit it manually. // show(); // shown by the caller to enable setting the parent window. diff --git a/src/gsc_add_device_window.cpp b/src/gsc_add_device_window.cpp index 1b41d6d..a1eca5b 100644 --- a/src/gsc_add_device_window.cpp +++ b/src/gsc_add_device_window.cpp @@ -23,6 +23,7 @@ Copyright: #include "gsc_add_device_window.h" #include "gsc_main_window.h" +#include "build_config.h" diff --git a/src/gsc_init.cpp b/src/gsc_init.cpp index c598b7d..7c73f7f 100644 --- a/src/gsc_init.cpp +++ b/src/gsc_init.cpp @@ -30,8 +30,6 @@ Copyright: #include #endif -#include "config.h" // VERSION, *PACKAGE* - #include "libdebug/libdebug.h" // include full libdebug here (to add domains, etc...) #include "rconfig/rconfig.h" #include "rconfig/loadsave.h" @@ -43,6 +41,7 @@ Copyright: #include "hz/win32_tools.h" // win32_get_registry_value_string() #include "hz/env_tools.h" #include "hz/string_num.h" +#include "build_config.h" // VERSION, *PACKAGE*, ... #include "gsc_main_window.h" #include "gsc_executor_log_window.h" @@ -228,7 +227,7 @@ namespace { { "gdk-dpi-scale", 'l', 0, G_OPTION_ARG_DOUBLE, &(args.arg_gdk_dpi_scale), N_("The value of GDK_DPI_SCALE environment variable (useful when executing with pkexec)"), nullptr }, #endif - { nullptr } + { nullptr, '\0', 0, G_OPTION_ARG_NONE, nullptr, nullptr, nullptr } }; GError* error = nullptr; @@ -270,12 +269,13 @@ namespace { /// Print application version information inline void app_print_version_info() { - std::string versiontext = "\n" + Glib::ustring::compose(_("GSmartControl version %1"), VERSION) + "\n"; + std::string versiontext = "\n" + Glib::ustring::compose(_("GSmartControl version %1"), PACKAGE_VERSION) + "\n"; std::string warningtext = std::string("\n") + _("Warning: GSmartControl comes with ABSOLUTELY NO WARRANTY.\n" - "See LICENSE_gsmartcontrol.txt file for details.") + "\n\n"; + "See LICENSE.txt file for details.") + "\n\n"; /// %1 is years, %2 is email address - warningtext += Glib::ustring::compose(_("Copyright (C) %1 Alexander Shaduri %2"), "2008 - 2018", "") + "\n\n"; + warningtext += Glib::ustring::compose(_("Copyright (C) %1 Alexander Shaduri %2"), "2008 - 2021", + "") + "\n\n"; std::fprintf(stdout, "%s%s", versiontext.c_str(), warningtext.c_str()); } @@ -293,9 +293,9 @@ bool app_init_and_loop(int& argc, char**& argv) #endif // Set up gettext. This has to be before gtk is initialized. - bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR); - bind_textdomain_codeset(PACKAGE, "UTF-8"); - textdomain(PACKAGE); + bindtextdomain(PACKAGE_NAME, PACKAGE_LOCALE_DIR); + bind_textdomain_codeset(PACKAGE_NAME, "UTF-8"); + textdomain(PACKAGE_NAME); // Glib needs the C locale set to system locale for command line args. // We will reset it later if needed. @@ -448,9 +448,9 @@ bool app_init_and_loop(int& argc, char**& argv) // Paths in source tree #ifdef DEBUG_BUILD - hz::data_file_add_search_directory("icons", hz::fs::u8path(TOP_SOURCE_DIR) / "data"); - hz::data_file_add_search_directory("ui", hz::fs::u8path(TOP_SOURCE_DIR) / "src/ui"); - hz::data_file_add_search_directory("doc", hz::fs::u8path(TOP_SOURCE_DIR) / "doc"); + hz::data_file_add_search_directory("icons", hz::fs::u8path(PACKAGE_TOP_SOURCE_DIR) / "data"); + hz::data_file_add_search_directory("ui", hz::fs::u8path(PACKAGE_TOP_SOURCE_DIR) / "src/ui"); + hz::data_file_add_search_directory("doc", hz::fs::u8path(PACKAGE_TOP_SOURCE_DIR) / "doc"); #endif diff --git a/src/gsc_preferences_window.cpp b/src/gsc_preferences_window.cpp index 1f5f101..613d574 100644 --- a/src/gsc_preferences_window.cpp +++ b/src/gsc_preferences_window.cpp @@ -18,6 +18,7 @@ Copyright: #include #include // GDK_KEY_Escape +#include "build_config.h" #include "hz/fs_ns.h" #include "hz/string_sprintf.h" #include "hz/scoped_ptr.h" diff --git a/src/hz/examples/CMakeLists.txt b/src/hz/examples/CMakeLists.txt index 6d22092..1d314ed 100644 --- a/src/hz/examples/CMakeLists.txt +++ b/src/hz/examples/CMakeLists.txt @@ -17,7 +17,6 @@ target_sources(format_unit_example PRIVATE ) target_link_libraries(format_unit_example PRIVATE hz - compiler_warnings ) @@ -27,7 +26,6 @@ target_sources(string_algo_example PRIVATE ) target_link_libraries(string_algo_example PRIVATE hz - compiler_warnings ) @@ -37,5 +35,4 @@ target_sources(string_num_example PRIVATE ) target_link_libraries(string_num_example PRIVATE hz - compiler_warnings ) diff --git a/src/libdebug/CMakeLists.txt b/src/libdebug/CMakeLists.txt index 216abe7..6e76844 100644 --- a/src/libdebug/CMakeLists.txt +++ b/src/libdebug/CMakeLists.txt @@ -25,10 +25,12 @@ target_sources(libdebug PRIVATE libdebug_mini.h ) +target_include_directories(libdebug INTERFACE "${CMAKE_SOURCE_DIR}/src") + target_link_libraries(libdebug PRIVATE hz - compiler_warnings + app_gtkmm_interface # .cpp only ) diff --git a/src/libdebug/dcmdarg.cpp b/src/libdebug/dcmdarg.cpp index 9aa2f1c..6adeaae 100644 --- a/src/libdebug/dcmdarg.cpp +++ b/src/libdebug/dcmdarg.cpp @@ -206,7 +206,7 @@ GOptionGroup* debug_get_option_group() &(args->debug_colorize), "Enable colored output", nullptr }, { "debug-no-colorize", '\0', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &(args->debug_colorize), "Disable colored output", nullptr }, - { nullptr } + { nullptr, '\0', 0, G_OPTION_ARG_NONE, nullptr, nullptr, nullptr } }; g_option_group_add_entries(group, entries); diff --git a/src/libdebug/examples/CMakeLists.txt b/src/libdebug/examples/CMakeLists.txt index 3fc9526..0e6753c 100644 --- a/src/libdebug/examples/CMakeLists.txt +++ b/src/libdebug/examples/CMakeLists.txt @@ -17,6 +17,5 @@ target_sources(libdebug_example PRIVATE ) target_link_libraries(libdebug_example PRIVATE libdebug - compiler_warnings ) diff --git a/src/rconfig/CMakeLists.txt b/src/rconfig/CMakeLists.txt index 4b962c6..81e9656 100644 --- a/src/rconfig/CMakeLists.txt +++ b/src/rconfig/CMakeLists.txt @@ -12,10 +12,13 @@ target_sources(rconfig INTERFACE rconfig.h ) +target_include_directories(rconfig INTERFACE "${CMAKE_SOURCE_DIR}/src") + target_link_libraries(rconfig INTERFACE hz json + app_gtkmm_interface ) diff --git a/src/rconfig/examples/CMakeLists.txt b/src/rconfig/examples/CMakeLists.txt index 0fc390f..3a96e7c 100644 --- a/src/rconfig/examples/CMakeLists.txt +++ b/src/rconfig/examples/CMakeLists.txt @@ -17,6 +17,5 @@ target_sources(rconfig_example PRIVATE ) target_link_libraries(rconfig_example PRIVATE rconfig - compiler_warnings ) diff --git a/toolchains/win32-prod-gcc-release.cmake b/toolchains/win32-prod-gcc-release.cmake index e9687fe..730ccbd 100644 --- a/toolchains/win32-prod-gcc-release.cmake +++ b/toolchains/win32-prod-gcc-release.cmake @@ -8,6 +8,15 @@ # Use with: # cmake -DCMAKE_TOOLCHAIN_FILE=... +# TODO +# # optimized builds (target mingw32): +## -g0 -O3 -s -march=i686 +# +## optimized builds (target mingw64, cygwin): +## -g0 -O3 -s + +# -mtune=generic + set(CMAKE_SYSTEM_NAME Windows) # Specify the compiler