From fb731f2b5e770de9a0197810480f10738adf8bd7 Mon Sep 17 00:00:00 2001 From: olszomal Date: Fri, 28 Apr 2023 15:55:18 +0200 Subject: [PATCH] Use indentations --- CMakeLists.txt | 50 ++++---- cmake/CMakeDist.cmake | 9 ++ cmake/FindHeaders.cmake | 25 ++-- cmake/SetBashCompletion.cmake | 31 +++-- cmake/SetCompilerFlags.cmake | 214 ++++++++++++++++++---------------- 5 files changed, 187 insertions(+), 142 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3564423..2f4cb3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,16 +4,16 @@ cmake_minimum_required(VERSION 3.17) # autodetect vcpkg CMAKE_TOOLCHAIN_FILE if VCPKG_ROOT is defined # this needs to be configured before the project() directive if(DEFINED ENV{VCPKG_ROOT} AND NOT $ENV{VCPKG_ROOT} STREQUAL "" AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) - set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "") + set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "") endif(DEFINED ENV{VCPKG_ROOT} AND NOT $ENV{VCPKG_ROOT} STREQUAL "" AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) set(BUILTIN_SOCKET ON CACHE BOOL "") # for static Python # configure basic project information project(osslsigncode - VERSION 2.6 - DESCRIPTION "OpenSSL based Authenticode signing for PE, CAB, CAT and MSI files" - HOMEPAGE_URL "https://github.com/mtrojnar/osslsigncode" - LANGUAGES C) + VERSION 2.6 + DESCRIPTION "OpenSSL based Authenticode signing for PE, CAB, CAT and MSI files" + HOMEPAGE_URL "https://github.com/mtrojnar/osslsigncode" + LANGUAGES C) # force nonstandard version format for development packages set(DEV "-dev") @@ -49,7 +49,7 @@ target_compile_definitions(osslsigncode PRIVATE HAVE_CONFIG_H=1) # set sources target_sources(osslsigncode PRIVATE osslsigncode.c helpers.c msi.c pe.c cab.c cat.c) if(NOT UNIX) - target_sources(osslsigncode PRIVATE applink.c) + target_sources(osslsigncode PRIVATE applink.c) endif(NOT UNIX) # set include directories @@ -57,19 +57,19 @@ target_include_directories(osslsigncode PRIVATE "${PROJECT_BINARY_DIR}") # set OpenSSL includes/libraries if(NOT OPENSSL_FOUND) - message(FATAL_ERROR "OpenSSL library not found") + message(FATAL_ERROR "OpenSSL library not found") endif(NOT OPENSSL_FOUND) target_include_directories(osslsigncode PRIVATE ${OPENSSL_INCLUDE_DIR}) target_link_libraries(osslsigncode PRIVATE ${OPENSSL_LIBRARIES}) # set cURL includes/libraries if(CURL_FOUND) - target_compile_definitions(osslsigncode PRIVATE ENABLE_CURL=1) - target_include_directories(osslsigncode PRIVATE ${CURL_INCLUDE_DIRS}) - target_link_libraries(osslsigncode PRIVATE ${CURL_LIBRARIES}) - message(STATUS "cURL support enabled") + target_compile_definitions(osslsigncode PRIVATE ENABLE_CURL=1) + target_include_directories(osslsigncode PRIVATE ${CURL_INCLUDE_DIRS}) + target_link_libraries(osslsigncode PRIVATE ${CURL_LIBRARIES}) + message(STATUS "cURL support enabled") else(CURL_FOUND) - message(STATUS "cURL support disabled (library not found)") + message(STATUS "cURL support disabled (library not found)") endif(CURL_FOUND) # add paths to linker search and installed rpath @@ -82,14 +82,22 @@ include(CMakeTest) set(BINDIR "${CMAKE_INSTALL_PREFIX}/bin") install(TARGETS osslsigncode RUNTIME DESTINATION ${BINDIR}) if(UNIX) - include(CMakeDist) + include(CMakeDist) else(UNIX) - install( - DIRECTORY ${PROJECT_BINARY_DIR}/ DESTINATION ${BINDIR} - FILES_MATCHING - PATTERN "*.dll" - PATTERN "vcpkg_installed" EXCLUDE - PATTERN "CMakeFiles" EXCLUDE - PATTERN "Testing" EXCLUDE - ) + install( + DIRECTORY ${PROJECT_BINARY_DIR}/ DESTINATION ${BINDIR} + FILES_MATCHING + PATTERN "*.dll" + PATTERN "vcpkg_installed" EXCLUDE + PATTERN "CMakeFiles" EXCLUDE + PATTERN "Testing" EXCLUDE) endif(UNIX) + +#[[ +Local Variables: + c-basic-offset: 4 + tab-width: 4 + indent-tabs-mode: nil +End: + vim: set ts=4 expandtab: +]] diff --git a/cmake/CMakeDist.cmake b/cmake/CMakeDist.cmake index 5e7688f..b773846 100644 --- a/cmake/CMakeDist.cmake +++ b/cmake/CMakeDist.cmake @@ -25,3 +25,12 @@ list(APPEND CPACK_SOURCE_IGNORE_FILES "/build/") include(CPack) add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source) + +#[[ +Local Variables: + c-basic-offset: 4 + tab-width: 4 + indent-tabs-mode: nil +End: + vim: set ts=4 expandtab: +]] diff --git a/cmake/FindHeaders.cmake b/cmake/FindHeaders.cmake index 046490a..4d4f1d7 100644 --- a/cmake/FindHeaders.cmake +++ b/cmake/FindHeaders.cmake @@ -2,16 +2,25 @@ include(CheckIncludeFile) include(CheckFunctionExists) if(UNIX) - check_function_exists(getpass HAVE_GETPASS) - check_include_file(termios.h HAVE_TERMIOS_H) - check_include_file(sys/mman.h HAVE_SYS_MMAN_H) - if(HAVE_SYS_MMAN_H) - check_function_exists(mmap HAVE_MMAP) - endif(HAVE_SYS_MMAN_H) + check_function_exists(getpass HAVE_GETPASS) + check_include_file(termios.h HAVE_TERMIOS_H) + check_include_file(sys/mman.h HAVE_SYS_MMAN_H) + if(HAVE_SYS_MMAN_H) + check_function_exists(mmap HAVE_MMAP) + endif(HAVE_SYS_MMAN_H) else(UNIX) - check_include_file(windows.h HAVE_MAPVIEWOFFILE) + check_include_file(windows.h HAVE_MAPVIEWOFFILE) endif(UNIX) if(NOT (HAVE_MMAP OR HAVE_MAPVIEWOFFILE)) - message(FATAL_ERROR "Error: Need file mapping function to build.") + message(FATAL_ERROR "Error: Need file mapping function to build.") endif(NOT (HAVE_MMAP OR HAVE_MAPVIEWOFFILE)) + +#[[ +Local Variables: + c-basic-offset: 4 + tab-width: 4 + indent-tabs-mode: nil +End: + vim: set ts=4 expandtab: +]] diff --git a/cmake/SetBashCompletion.cmake b/cmake/SetBashCompletion.cmake index 8aa33cf..59e66b8 100644 --- a/cmake/SetBashCompletion.cmake +++ b/cmake/SetBashCompletion.cmake @@ -8,16 +8,25 @@ # https://github.com/scop/bash-completion/blob/master/bash-completion-config.cmake.in if(NOT MSVC) - if(BASH_COMPLETION_USER_DIR) - set(BASH_COMPLETION_COMPLETIONSDIR "${BASH_COMPLETION_USER_DIR}/bash-completion/completions") - else(BASH_COMPLETION_USER_DIR) - find_package(bash-completion QUIET) - if(NOT BASH_COMPLETION_FOUND) - set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share") - set(BASH_COMPLETION_COMPLETIONSDIR "${SHAREDIR}/bash-completion/completions") - endif(NOT BASH_COMPLETION_FOUND) - endif(BASH_COMPLETION_USER_DIR) + if(BASH_COMPLETION_USER_DIR) + set(BASH_COMPLETION_COMPLETIONSDIR "${BASH_COMPLETION_USER_DIR}/bash-completion/completions") + else(BASH_COMPLETION_USER_DIR) + find_package(bash-completion QUIET) + if(NOT BASH_COMPLETION_FOUND) + set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share") + set(BASH_COMPLETION_COMPLETIONSDIR "${SHAREDIR}/bash-completion/completions") + endif(NOT BASH_COMPLETION_FOUND) + endif(BASH_COMPLETION_USER_DIR) - message(STATUS "Using bash completions dir ${BASH_COMPLETION_COMPLETIONSDIR}") - install(FILES "osslsigncode.bash" DESTINATION ${BASH_COMPLETION_COMPLETIONSDIR}) + message(STATUS "Using bash completions dir ${BASH_COMPLETION_COMPLETIONSDIR}") + install(FILES "osslsigncode.bash" DESTINATION ${BASH_COMPLETION_COMPLETIONSDIR}) endif(NOT MSVC) + +#[[ +Local Variables: + c-basic-offset: 4 + tab-width: 4 + indent-tabs-mode: nil +End: + vim: set ts=4 expandtab: +]] diff --git a/cmake/SetCompilerFlags.cmake b/cmake/SetCompilerFlags.cmake index d729876..1440222 100644 --- a/cmake/SetCompilerFlags.cmake +++ b/cmake/SetCompilerFlags.cmake @@ -3,111 +3,121 @@ include(CheckCCompilerFlag) set(CMAKE_REQUIRED_QUIET ON) function(add_debug_flag_if_supported flagname targets) - check_c_compiler_flag("${flagname}" HAVE_FLAG_${flagname}) - if (HAVE_FLAG_${flagname}) - foreach(target ${targets}) - target_compile_options(${target} PRIVATE $<$:${flagname}>) - endforeach() - endif() -endfunction() + check_c_compiler_flag("${flagname}" HAVE_FLAG_${flagname}) + if (HAVE_FLAG_${flagname}) + foreach(target ${targets}) + target_compile_options(${target} PRIVATE $<$:${flagname}>) + endforeach(target ${targets}) + endif(HAVE_FLAG_${flagname}) +endfunction(add_debug_flag_if_supported flagname targets) function(add_compile_flag_to_targets targets) - set(CHECKED_DEBUG_FLAGS - "-ggdb" - "-g" - "-O2" - "-pedantic" - "-Wall" - "-Wextra" - "-Wno-long-long" - "-Wconversion" - "-D_FORTIFY_SOURCE=2" - "-Wformat=2" - "-Wredundant-decls" - "-Wcast-qual" - "-Wnull-dereference" - "-Wno-deprecated-declarations" - "-Wmissing-declarations" - "-Wmissing-prototypes" - "-Wmissing-noreturn" - "-Wmissing-braces" - "-Wparentheses" - "-Wstrict-aliasing=3" - "-Wstrict-overflow=2" - "-Wlogical-op" - "-Wwrite-strings" - "-Wcast-align=strict" - "-Wdisabled-optimization" - "-Wshift-overflow=2" - "-Wundef" - "-Wshadow" - "-Wmisleading-indentation" - "-Wabsolute-value" - "-Wunused-parameter" - "-Wunused-function" - ) - foreach(flag ${CHECKED_DEBUG_FLAGS}) - add_debug_flag_if_supported(${flag} ${targets}) - endforeach() -endfunction() + set(CHECKED_DEBUG_FLAGS + "-ggdb" + "-g" + "-O2" + "-pedantic" + "-Wall" + "-Wextra" + "-Wno-long-long" + "-Wconversion" + "-D_FORTIFY_SOURCE=2" + "-Wformat=2" + "-Wredundant-decls" + "-Wcast-qual" + "-Wnull-dereference" + "-Wno-deprecated-declarations" + "-Wmissing-declarations" + "-Wmissing-prototypes" + "-Wmissing-noreturn" + "-Wmissing-braces" + "-Wparentheses" + "-Wstrict-aliasing=3" + "-Wstrict-overflow=2" + "-Wlogical-op" + "-Wwrite-strings" + "-Wcast-align=strict" + "-Wdisabled-optimization" + "-Wshift-overflow=2" + "-Wundef" + "-Wshadow" + "-Wmisleading-indentation" + "-Wabsolute-value" + "-Wunused-parameter" + "-Wunused-function") + foreach(flag ${CHECKED_DEBUG_FLAGS}) + add_debug_flag_if_supported(${flag} ${targets}) + endforeach(flag ${CHECKED_DEBUG_FLAGS}) +endfunction(add_compile_flag_to_targets targets) function(add_compile_flags target) - if(MSVC) - # Enable parallel builds - target_compile_options(${target} PRIVATE /MP) - # Use address space layout randomization, generate PIE code for ASLR (default on) - target_link_options(${target} PRIVATE /DYNAMICBASE) - # Create terminal server aware application (default on) - target_link_options(${target} PRIVATE /TSAWARE) - # Mark the binary as compatible with Intel Control-flow Enforcement Technology (CET) Shadow Stack - target_link_options(${target} PRIVATE /CETCOMPAT) - # Enable compiler generation of Control Flow Guard security checks - target_compile_options(${target} PRIVATE /guard:cf) - target_link_options(${target} PRIVATE /guard:cf) - # Buffer Security Check - target_compile_options(${target} PRIVATE /GS) - # Suppress startup banner - target_link_options(${target} PRIVATE /NOLOGO) - # Generate debug info - target_link_options(${target} PRIVATE /DEBUG) - if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") - # High entropy ASLR for 64 bits targets (default on) - target_link_options(${target} PRIVATE /HIGHENTROPYVA) - # Enable generation of EH Continuation (EHCONT) metadata by the compiler - #target_compile_options(${target} PRIVATE /guard:ehcont) - #target_link_options(${target} PRIVATE /guard:ehcont) - else() - # Can handle addresses larger than 2 gigabytes - target_link_options(${target} PRIVATE /LARGEADDRESSAWARE) - # Safe structured exception handlers (x86 only) - target_link_options(${target} PRIVATE /SAFESEH) - endif() - target_compile_options(${target} PRIVATE $<$:/D_FORTIFY_SOURCE=2>) - # Unrecognized compiler options are errors - target_compile_options(${target} PRIVATE $<$:/options:strict>) - else(MSVC) - check_c_compiler_flag("-fstack-protector-all" HAVE_STACK_PROTECTOR_ALL) - if(HAVE_STACK_PROTECTOR_ALL) - target_link_options(${target} PRIVATE -fstack-protector-all) - else() - check_c_compiler_flag("-fstack-protector" HAVE_STACK_PROTECTOR) - if(HAVE_STACK_PROTECTOR) - target_link_options(${target} PRIVATE -fstack-protector) - else() - message(WARNING "No stack protection supported") - endif() - endif() - # Support address space layout randomization (ASLR) - if(NOT (MINGW OR CYGWIN OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang" OR ((CMAKE_SYSTEM_NAME MATCHES Darwin) AND (CMAKE_C_COMPILER_ID MATCHES Clang)))) - target_compile_options(${target} PRIVATE -fPIE) - target_link_options(${target} PRIVATE -fPIE -pie) - target_link_options(${target} PRIVATE -Wl,-z,relro) - target_link_options(${target} PRIVATE -Wl,-z,now) - target_link_options(${target} PRIVATE -Wl,-z,noexecstack) - endif(NOT (MINGW OR CYGWIN OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang" OR ((CMAKE_SYSTEM_NAME MATCHES Darwin) AND (CMAKE_C_COMPILER_ID MATCHES Clang)))) - target_link_options(${target} PRIVATE -fstack-check) - add_compile_flag_to_targets(${target}) - endif(MSVC) -endfunction() + if(MSVC) + # Enable parallel builds + target_compile_options(${target} PRIVATE /MP) + # Use address space layout randomization, generate PIE code for ASLR (default on) + target_link_options(${target} PRIVATE /DYNAMICBASE) + # Create terminal server aware application (default on) + target_link_options(${target} PRIVATE /TSAWARE) + # Mark the binary as compatible with Intel Control-flow Enforcement Technology (CET) Shadow Stack + target_link_options(${target} PRIVATE /CETCOMPAT) + # Enable compiler generation of Control Flow Guard security checks + target_compile_options(${target} PRIVATE /guard:cf) + target_link_options(${target} PRIVATE /guard:cf) + # Buffer Security Check + target_compile_options(${target} PRIVATE /GS) + # Suppress startup banner + target_link_options(${target} PRIVATE /NOLOGO) + # Generate debug info + target_link_options(${target} PRIVATE /DEBUG) + if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") + # High entropy ASLR for 64 bits targets (default on) + target_link_options(${target} PRIVATE /HIGHENTROPYVA) + # Enable generation of EH Continuation (EHCONT) metadata by the compiler + #target_compile_options(${target} PRIVATE /guard:ehcont) + #target_link_options(${target} PRIVATE /guard:ehcont) + else("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") + # Can handle addresses larger than 2 gigabytes + target_link_options(${target} PRIVATE /LARGEADDRESSAWARE) + # Safe structured exception handlers (x86 only) + target_link_options(${target} PRIVATE /SAFESEH) + endif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") + target_compile_options(${target} PRIVATE $<$:/D_FORTIFY_SOURCE=2>) + # Unrecognized compiler options are errors + target_compile_options(${target} PRIVATE $<$:/options:strict>) + else(MSVC) + check_c_compiler_flag("-fstack-protector-all" HAVE_STACK_PROTECTOR_ALL) + if(HAVE_STACK_PROTECTOR_ALL) + target_link_options(${target} PRIVATE -fstack-protector-all) + else(HAVE_STACK_PROTECTOR_ALL) + check_c_compiler_flag("-fstack-protector" HAVE_STACK_PROTECTOR) + if(HAVE_STACK_PROTECTOR) + target_link_options(${target} PRIVATE -fstack-protector) + else(HAVE_STACK_PROTECTOR) + message(WARNING "No stack protection supported") + endif(HAVE_STACK_PROTECTOR) + endif(HAVE_STACK_PROTECTOR_ALL) + # Support address space layout randomization (ASLR) + if(NOT (MINGW OR CYGWIN OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang" + OR ((CMAKE_SYSTEM_NAME MATCHES Darwin) AND (CMAKE_C_COMPILER_ID MATCHES Clang)))) + target_compile_options(${target} PRIVATE -fPIE) + target_link_options(${target} PRIVATE -fPIE -pie) + target_link_options(${target} PRIVATE -Wl,-z,relro) + target_link_options(${target} PRIVATE -Wl,-z,now) + target_link_options(${target} PRIVATE -Wl,-z,noexecstack) + endif(NOT (MINGW OR CYGWIN OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang" + OR ((CMAKE_SYSTEM_NAME MATCHES Darwin) AND (CMAKE_C_COMPILER_ID MATCHES Clang)))) + target_link_options(${target} PRIVATE -fstack-check) + add_compile_flag_to_targets(${target}) + endif(MSVC) +endfunction(add_compile_flags target) add_compile_flags(osslsigncode) + +#[[ +Local Variables: + c-basic-offset: 4 + tab-width: 4 + indent-tabs-mode: nil +End: + vim: set ts=4 expandtab: +]]