Use indentations

This commit is contained in:
olszomal 2023-04-28 15:55:18 +02:00 committed by Michał Trojnara
parent eec5a0755d
commit fb731f2b5e
5 changed files with 187 additions and 142 deletions

View File

@ -4,16 +4,16 @@ cmake_minimum_required(VERSION 3.17)
# autodetect vcpkg CMAKE_TOOLCHAIN_FILE if VCPKG_ROOT is defined # autodetect vcpkg CMAKE_TOOLCHAIN_FILE if VCPKG_ROOT is defined
# this needs to be configured before the project() directive # 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) 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) 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 set(BUILTIN_SOCKET ON CACHE BOOL "") # for static Python
# configure basic project information # configure basic project information
project(osslsigncode project(osslsigncode
VERSION 2.6 VERSION 2.6
DESCRIPTION "OpenSSL based Authenticode signing for PE, CAB, CAT and MSI files" DESCRIPTION "OpenSSL based Authenticode signing for PE, CAB, CAT and MSI files"
HOMEPAGE_URL "https://github.com/mtrojnar/osslsigncode" HOMEPAGE_URL "https://github.com/mtrojnar/osslsigncode"
LANGUAGES C) LANGUAGES C)
# force nonstandard version format for development packages # force nonstandard version format for development packages
set(DEV "-dev") set(DEV "-dev")
@ -49,7 +49,7 @@ target_compile_definitions(osslsigncode PRIVATE HAVE_CONFIG_H=1)
# set sources # set sources
target_sources(osslsigncode PRIVATE osslsigncode.c helpers.c msi.c pe.c cab.c cat.c) target_sources(osslsigncode PRIVATE osslsigncode.c helpers.c msi.c pe.c cab.c cat.c)
if(NOT UNIX) if(NOT UNIX)
target_sources(osslsigncode PRIVATE applink.c) target_sources(osslsigncode PRIVATE applink.c)
endif(NOT UNIX) endif(NOT UNIX)
# set include directories # set include directories
@ -57,19 +57,19 @@ target_include_directories(osslsigncode PRIVATE "${PROJECT_BINARY_DIR}")
# set OpenSSL includes/libraries # set OpenSSL includes/libraries
if(NOT OPENSSL_FOUND) if(NOT OPENSSL_FOUND)
message(FATAL_ERROR "OpenSSL library not found") message(FATAL_ERROR "OpenSSL library not found")
endif(NOT OPENSSL_FOUND) endif(NOT OPENSSL_FOUND)
target_include_directories(osslsigncode PRIVATE ${OPENSSL_INCLUDE_DIR}) target_include_directories(osslsigncode PRIVATE ${OPENSSL_INCLUDE_DIR})
target_link_libraries(osslsigncode PRIVATE ${OPENSSL_LIBRARIES}) target_link_libraries(osslsigncode PRIVATE ${OPENSSL_LIBRARIES})
# set cURL includes/libraries # set cURL includes/libraries
if(CURL_FOUND) if(CURL_FOUND)
target_compile_definitions(osslsigncode PRIVATE ENABLE_CURL=1) target_compile_definitions(osslsigncode PRIVATE ENABLE_CURL=1)
target_include_directories(osslsigncode PRIVATE ${CURL_INCLUDE_DIRS}) target_include_directories(osslsigncode PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(osslsigncode PRIVATE ${CURL_LIBRARIES}) target_link_libraries(osslsigncode PRIVATE ${CURL_LIBRARIES})
message(STATUS "cURL support enabled") message(STATUS "cURL support enabled")
else(CURL_FOUND) else(CURL_FOUND)
message(STATUS "cURL support disabled (library not found)") message(STATUS "cURL support disabled (library not found)")
endif(CURL_FOUND) endif(CURL_FOUND)
# add paths to linker search and installed rpath # add paths to linker search and installed rpath
@ -82,14 +82,22 @@ include(CMakeTest)
set(BINDIR "${CMAKE_INSTALL_PREFIX}/bin") set(BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
install(TARGETS osslsigncode RUNTIME DESTINATION ${BINDIR}) install(TARGETS osslsigncode RUNTIME DESTINATION ${BINDIR})
if(UNIX) if(UNIX)
include(CMakeDist) include(CMakeDist)
else(UNIX) else(UNIX)
install( install(
DIRECTORY ${PROJECT_BINARY_DIR}/ DESTINATION ${BINDIR} DIRECTORY ${PROJECT_BINARY_DIR}/ DESTINATION ${BINDIR}
FILES_MATCHING FILES_MATCHING
PATTERN "*.dll" PATTERN "*.dll"
PATTERN "vcpkg_installed" EXCLUDE PATTERN "vcpkg_installed" EXCLUDE
PATTERN "CMakeFiles" EXCLUDE PATTERN "CMakeFiles" EXCLUDE
PATTERN "Testing" EXCLUDE PATTERN "Testing" EXCLUDE)
)
endif(UNIX) endif(UNIX)
#[[
Local Variables:
c-basic-offset: 4
tab-width: 4
indent-tabs-mode: nil
End:
vim: set ts=4 expandtab:
]]

View File

@ -25,3 +25,12 @@ list(APPEND CPACK_SOURCE_IGNORE_FILES "/build/")
include(CPack) include(CPack)
add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source) 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:
]]

View File

@ -2,16 +2,25 @@ include(CheckIncludeFile)
include(CheckFunctionExists) include(CheckFunctionExists)
if(UNIX) if(UNIX)
check_function_exists(getpass HAVE_GETPASS) check_function_exists(getpass HAVE_GETPASS)
check_include_file(termios.h HAVE_TERMIOS_H) check_include_file(termios.h HAVE_TERMIOS_H)
check_include_file(sys/mman.h HAVE_SYS_MMAN_H) check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
if(HAVE_SYS_MMAN_H) if(HAVE_SYS_MMAN_H)
check_function_exists(mmap HAVE_MMAP) check_function_exists(mmap HAVE_MMAP)
endif(HAVE_SYS_MMAN_H) endif(HAVE_SYS_MMAN_H)
else(UNIX) else(UNIX)
check_include_file(windows.h HAVE_MAPVIEWOFFILE) check_include_file(windows.h HAVE_MAPVIEWOFFILE)
endif(UNIX) endif(UNIX)
if(NOT (HAVE_MMAP OR HAVE_MAPVIEWOFFILE)) 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)) 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:
]]

View File

@ -8,16 +8,25 @@
# https://github.com/scop/bash-completion/blob/master/bash-completion-config.cmake.in # https://github.com/scop/bash-completion/blob/master/bash-completion-config.cmake.in
if(NOT MSVC) if(NOT MSVC)
if(BASH_COMPLETION_USER_DIR) if(BASH_COMPLETION_USER_DIR)
set(BASH_COMPLETION_COMPLETIONSDIR "${BASH_COMPLETION_USER_DIR}/bash-completion/completions") set(BASH_COMPLETION_COMPLETIONSDIR "${BASH_COMPLETION_USER_DIR}/bash-completion/completions")
else(BASH_COMPLETION_USER_DIR) else(BASH_COMPLETION_USER_DIR)
find_package(bash-completion QUIET) find_package(bash-completion QUIET)
if(NOT BASH_COMPLETION_FOUND) if(NOT BASH_COMPLETION_FOUND)
set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share") set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share")
set(BASH_COMPLETION_COMPLETIONSDIR "${SHAREDIR}/bash-completion/completions") set(BASH_COMPLETION_COMPLETIONSDIR "${SHAREDIR}/bash-completion/completions")
endif(NOT BASH_COMPLETION_FOUND) endif(NOT BASH_COMPLETION_FOUND)
endif(BASH_COMPLETION_USER_DIR) endif(BASH_COMPLETION_USER_DIR)
message(STATUS "Using bash completions dir ${BASH_COMPLETION_COMPLETIONSDIR}") message(STATUS "Using bash completions dir ${BASH_COMPLETION_COMPLETIONSDIR}")
install(FILES "osslsigncode.bash" DESTINATION ${BASH_COMPLETION_COMPLETIONSDIR}) install(FILES "osslsigncode.bash" DESTINATION ${BASH_COMPLETION_COMPLETIONSDIR})
endif(NOT MSVC) endif(NOT MSVC)
#[[
Local Variables:
c-basic-offset: 4
tab-width: 4
indent-tabs-mode: nil
End:
vim: set ts=4 expandtab:
]]

View File

@ -3,111 +3,121 @@ include(CheckCCompilerFlag)
set(CMAKE_REQUIRED_QUIET ON) set(CMAKE_REQUIRED_QUIET ON)
function(add_debug_flag_if_supported flagname targets) function(add_debug_flag_if_supported flagname targets)
check_c_compiler_flag("${flagname}" HAVE_FLAG_${flagname}) check_c_compiler_flag("${flagname}" HAVE_FLAG_${flagname})
if (HAVE_FLAG_${flagname}) if (HAVE_FLAG_${flagname})
foreach(target ${targets}) foreach(target ${targets})
target_compile_options(${target} PRIVATE $<$<CONFIG:DEBUG>:${flagname}>) target_compile_options(${target} PRIVATE $<$<CONFIG:DEBUG>:${flagname}>)
endforeach() endforeach(target ${targets})
endif() endif(HAVE_FLAG_${flagname})
endfunction() endfunction(add_debug_flag_if_supported flagname targets)
function(add_compile_flag_to_targets targets) function(add_compile_flag_to_targets targets)
set(CHECKED_DEBUG_FLAGS set(CHECKED_DEBUG_FLAGS
"-ggdb" "-ggdb"
"-g" "-g"
"-O2" "-O2"
"-pedantic" "-pedantic"
"-Wall" "-Wall"
"-Wextra" "-Wextra"
"-Wno-long-long" "-Wno-long-long"
"-Wconversion" "-Wconversion"
"-D_FORTIFY_SOURCE=2" "-D_FORTIFY_SOURCE=2"
"-Wformat=2" "-Wformat=2"
"-Wredundant-decls" "-Wredundant-decls"
"-Wcast-qual" "-Wcast-qual"
"-Wnull-dereference" "-Wnull-dereference"
"-Wno-deprecated-declarations" "-Wno-deprecated-declarations"
"-Wmissing-declarations" "-Wmissing-declarations"
"-Wmissing-prototypes" "-Wmissing-prototypes"
"-Wmissing-noreturn" "-Wmissing-noreturn"
"-Wmissing-braces" "-Wmissing-braces"
"-Wparentheses" "-Wparentheses"
"-Wstrict-aliasing=3" "-Wstrict-aliasing=3"
"-Wstrict-overflow=2" "-Wstrict-overflow=2"
"-Wlogical-op" "-Wlogical-op"
"-Wwrite-strings" "-Wwrite-strings"
"-Wcast-align=strict" "-Wcast-align=strict"
"-Wdisabled-optimization" "-Wdisabled-optimization"
"-Wshift-overflow=2" "-Wshift-overflow=2"
"-Wundef" "-Wundef"
"-Wshadow" "-Wshadow"
"-Wmisleading-indentation" "-Wmisleading-indentation"
"-Wabsolute-value" "-Wabsolute-value"
"-Wunused-parameter" "-Wunused-parameter"
"-Wunused-function" "-Wunused-function")
) foreach(flag ${CHECKED_DEBUG_FLAGS})
foreach(flag ${CHECKED_DEBUG_FLAGS}) add_debug_flag_if_supported(${flag} ${targets})
add_debug_flag_if_supported(${flag} ${targets}) endforeach(flag ${CHECKED_DEBUG_FLAGS})
endforeach() endfunction(add_compile_flag_to_targets targets)
endfunction()
function(add_compile_flags target) function(add_compile_flags target)
if(MSVC) if(MSVC)
# Enable parallel builds # Enable parallel builds
target_compile_options(${target} PRIVATE /MP) target_compile_options(${target} PRIVATE /MP)
# Use address space layout randomization, generate PIE code for ASLR (default on) # Use address space layout randomization, generate PIE code for ASLR (default on)
target_link_options(${target} PRIVATE /DYNAMICBASE) target_link_options(${target} PRIVATE /DYNAMICBASE)
# Create terminal server aware application (default on) # Create terminal server aware application (default on)
target_link_options(${target} PRIVATE /TSAWARE) target_link_options(${target} PRIVATE /TSAWARE)
# Mark the binary as compatible with Intel Control-flow Enforcement Technology (CET) Shadow Stack # Mark the binary as compatible with Intel Control-flow Enforcement Technology (CET) Shadow Stack
target_link_options(${target} PRIVATE /CETCOMPAT) target_link_options(${target} PRIVATE /CETCOMPAT)
# Enable compiler generation of Control Flow Guard security checks # Enable compiler generation of Control Flow Guard security checks
target_compile_options(${target} PRIVATE /guard:cf) target_compile_options(${target} PRIVATE /guard:cf)
target_link_options(${target} PRIVATE /guard:cf) target_link_options(${target} PRIVATE /guard:cf)
# Buffer Security Check # Buffer Security Check
target_compile_options(${target} PRIVATE /GS) target_compile_options(${target} PRIVATE /GS)
# Suppress startup banner # Suppress startup banner
target_link_options(${target} PRIVATE /NOLOGO) target_link_options(${target} PRIVATE /NOLOGO)
# Generate debug info # Generate debug info
target_link_options(${target} PRIVATE /DEBUG) target_link_options(${target} PRIVATE /DEBUG)
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8") if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
# High entropy ASLR for 64 bits targets (default on) # High entropy ASLR for 64 bits targets (default on)
target_link_options(${target} PRIVATE /HIGHENTROPYVA) target_link_options(${target} PRIVATE /HIGHENTROPYVA)
# Enable generation of EH Continuation (EHCONT) metadata by the compiler # Enable generation of EH Continuation (EHCONT) metadata by the compiler
#target_compile_options(${target} PRIVATE /guard:ehcont) #target_compile_options(${target} PRIVATE /guard:ehcont)
#target_link_options(${target} PRIVATE /guard:ehcont) #target_link_options(${target} PRIVATE /guard:ehcont)
else() else("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
# Can handle addresses larger than 2 gigabytes # Can handle addresses larger than 2 gigabytes
target_link_options(${target} PRIVATE /LARGEADDRESSAWARE) target_link_options(${target} PRIVATE /LARGEADDRESSAWARE)
# Safe structured exception handlers (x86 only) # Safe structured exception handlers (x86 only)
target_link_options(${target} PRIVATE /SAFESEH) target_link_options(${target} PRIVATE /SAFESEH)
endif() endif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
target_compile_options(${target} PRIVATE $<$<CONFIG:DEBUG>:/D_FORTIFY_SOURCE=2>) target_compile_options(${target} PRIVATE $<$<CONFIG:DEBUG>:/D_FORTIFY_SOURCE=2>)
# Unrecognized compiler options are errors # Unrecognized compiler options are errors
target_compile_options(${target} PRIVATE $<$<CONFIG:DEBUG>:/options:strict>) target_compile_options(${target} PRIVATE $<$<CONFIG:DEBUG>:/options:strict>)
else(MSVC) else(MSVC)
check_c_compiler_flag("-fstack-protector-all" HAVE_STACK_PROTECTOR_ALL) check_c_compiler_flag("-fstack-protector-all" HAVE_STACK_PROTECTOR_ALL)
if(HAVE_STACK_PROTECTOR_ALL) if(HAVE_STACK_PROTECTOR_ALL)
target_link_options(${target} PRIVATE -fstack-protector-all) target_link_options(${target} PRIVATE -fstack-protector-all)
else() else(HAVE_STACK_PROTECTOR_ALL)
check_c_compiler_flag("-fstack-protector" HAVE_STACK_PROTECTOR) check_c_compiler_flag("-fstack-protector" HAVE_STACK_PROTECTOR)
if(HAVE_STACK_PROTECTOR) if(HAVE_STACK_PROTECTOR)
target_link_options(${target} PRIVATE -fstack-protector) target_link_options(${target} PRIVATE -fstack-protector)
else() else(HAVE_STACK_PROTECTOR)
message(WARNING "No stack protection supported") message(WARNING "No stack protection supported")
endif() endif(HAVE_STACK_PROTECTOR)
endif() endif(HAVE_STACK_PROTECTOR_ALL)
# Support address space layout randomization (ASLR) # 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)))) if(NOT (MINGW OR CYGWIN OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang"
target_compile_options(${target} PRIVATE -fPIE) OR ((CMAKE_SYSTEM_NAME MATCHES Darwin) AND (CMAKE_C_COMPILER_ID MATCHES Clang))))
target_link_options(${target} PRIVATE -fPIE -pie) target_compile_options(${target} PRIVATE -fPIE)
target_link_options(${target} PRIVATE -Wl,-z,relro) target_link_options(${target} PRIVATE -fPIE -pie)
target_link_options(${target} PRIVATE -Wl,-z,now) target_link_options(${target} PRIVATE -Wl,-z,relro)
target_link_options(${target} PRIVATE -Wl,-z,noexecstack) target_link_options(${target} PRIVATE -Wl,-z,now)
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 -Wl,-z,noexecstack)
target_link_options(${target} PRIVATE -fstack-check) endif(NOT (MINGW OR CYGWIN OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang"
add_compile_flag_to_targets(${target}) OR ((CMAKE_SYSTEM_NAME MATCHES Darwin) AND (CMAKE_C_COMPILER_ID MATCHES Clang))))
endif(MSVC) target_link_options(${target} PRIVATE -fstack-check)
endfunction() add_compile_flag_to_targets(${target})
endif(MSVC)
endfunction(add_compile_flags target)
add_compile_flags(osslsigncode) add_compile_flags(osslsigncode)
#[[
Local Variables:
c-basic-offset: 4
tab-width: 4
indent-tabs-mode: nil
End:
vim: set ts=4 expandtab:
]]