diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dd65bf..1056860 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,5 @@ +project(InnoExtract) + cmake_minimum_required(VERSION 2.8) # For custom cmake modules. @@ -8,17 +10,19 @@ option(USE_LZMA "Build lzma decompression support." ON) include(CompileCheck) include(VersionString) include(CheckSymbolExists) +include(BuildType) +include(StyleCheck) # Force re-checking libraries if the compiler or compiler flags change. if((NOT LAST_CMAKE_CXX_FLAGS STREQUAL CMAKE_CXX_FLAGS) OR (NOT LAST_CMAKE_CXX_COMPILER STREQUAL CMAKE_CXX_COMPILER)) + force_recheck_library(LZMA) force_recheck_library(Boost) unset(Boost_INCLUDE_DIR CACHE) set(LAST_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE INTERNAL "The last C++ compiler flags.") set(LAST_CMAKE_CXX_COMPILER "${CMAKE_CXX_COMPILER}" CACHE INTERNAL "The last C++ compiler.") endif() - unset(LIBRARIES) if(USE_LZMA) @@ -33,32 +37,18 @@ else() set(HAVE_LZMA 0) endif() -find_package(Boost REQUIRED COMPONENTS iostreams filesystem date_time system program_options) +find_package(Boost REQUIRED COMPONENTS + iostreams + filesystem + date_time + system + program_options +) check_link_library(Boost Boost_LIBRARIES) list(APPEND LIBRARIES "${Boost_LIBRARIES}") link_directories("${Boost_LIBRARY_DIRS}") include_directories(SYSTEM "${Boost_INCLUDE_DIR}") -if(CMAKE_BUILD_TYPE STREQUAL "") - set(CMAKE_BUILD_TYPE "Release") -endif() - -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - - add_definitions(-DDEBUG) - - check_compiler_flag(RESULT "-g3") - if(NOT RESULT STREQUAL "") - string(REGEX REPLACE "-g(|[0-9]|gdb)" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${RESULT}") - endif() - - check_compiler_flag(RESULT "-O0") - string(REGEX REPLACE "-O[0-9]" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${RESULT}") - -endif() - add_cxxflag("-Wall") add_cxxflag("-Wextra") add_cxxflag("-Wformat=2") @@ -77,7 +67,6 @@ add_cxxflag("-Wmissing-declarations") add_cxxflag("-Wredundant-decls") if(DEBUG_EXTRA) - add_definitions(-D_GLIBCXX_DEBUG) # Runtime checks for STL containers. add_cxxflag("-ftrapv") # to add checks for (undefined) signed integer overflow add_cxxflag("-fbounds-checking") add_cxxflag("-fcatch-undefined-behavior") @@ -89,10 +78,6 @@ else() add_cxxflag("-Wno-constant-logical-operand") endif() -if(UNITY_BUILD) - add_cxxflag("-fwhole-program") -endif() - check_symbol_exists(isatty "unistd.h" HAVE_ISATTY) check_symbol_exists(ioctl "sys/ioctl.h" HAVE_IOCTL) @@ -160,43 +145,4 @@ install(TARGETS innoextract RUNTIME DESTINATION bin) # Additional targets. -find_package(PythonInterp) - -if(PYTHONINTERP_FOUND) - - unset(STYLE_FILTER) - - # Complains about any c-style cast -> too annoying. - set(STYLE_FILTER ${STYLE_FILTER},-readability/casting) - - # Insists on including evrything in the .cpp file even if it is included in the header. - # This behaviour conflicts with orther tools. - set(STYLE_FILTER ${STYLE_FILTER},-build/include_what_you_use) - - # Too many false positives and not very helpful error messages. - set(STYLE_FILTER ${STYLE_FILTER},-build/include_order) - - # No thanks. - set(STYLE_FILTER ${STYLE_FILTER},-readability/streams) - - # Ugh! - set(STYLE_FILTER ${STYLE_FILTER},-whitespace/tab) - - # Yes it is! - set(STYLE_FILTER ${STYLE_FILTER},-whitespace/blank_line) - - # Suggessts excessive indentation. - set(STYLE_FILTER ${STYLE_FILTER},-whitespace/labels) - - # Don't tell me how to name my variables. - set(STYLE_FILTER ${STYLE_FILTER},-runtime/arrays) - - # Why? - set(STYLE_FILTER ${STYLE_FILTER},-whitespace/todo) - set(STYLE_FILTER ${STYLE_FILTER},-readability/todo) - - add_custom_target(style - COMMAND cmake -E chdir "${CMAKE_SOURCE_DIR}" "${PYTHON_EXECUTABLE}" "${CMAKE_MODULE_PATH}/cpplint.py" "--filter=${STYLE_FILTER}" ${INNOEXTRACT_SOURCES} ${ALL_INCLUDES} - ) - -endif() +add_style_check_target(style "${INNOEXTRACT_SOURCES}" "${ALL_INCLUDES}") diff --git a/cmake/BuildType.cmake b/cmake/BuildType.cmake new file mode 100644 index 0000000..96a7b27 --- /dev/null +++ b/cmake/BuildType.cmake @@ -0,0 +1,22 @@ + +include(CompileCheck) + +if(CMAKE_BUILD_TYPE STREQUAL "") + set(CMAKE_BUILD_TYPE "Release") +endif() + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + + add_definitions(-DDEBUG) + + check_compiler_flag(RESULT "-g3") + if(NOT RESULT STREQUAL "") + string(REGEX REPLACE "-g(|[0-9]|gdb)" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${RESULT}") + endif() + + check_compiler_flag(RESULT "-O0") + string(REGEX REPLACE "-O[0-9]" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${RESULT}") + +endif() diff --git a/cmake/StyleCheck.cmake b/cmake/StyleCheck.cmake new file mode 100644 index 0000000..e9fb11b --- /dev/null +++ b/cmake/StyleCheck.cmake @@ -0,0 +1,51 @@ + +find_package(PythonInterp) + +unset(STYLE_FILTER) + +# Complains about any c-style cast -> too annoying. +set(STYLE_FILTER ${STYLE_FILTER},-readability/casting) + +# Insists on including evrything in the .cpp file even if it is included in the header. +# This behaviour conflicts with orther tools. +set(STYLE_FILTER ${STYLE_FILTER},-build/include_what_you_use) + +# Too many false positives and not very helpful error messages. +set(STYLE_FILTER ${STYLE_FILTER},-build/include_order) + +# No thanks. +set(STYLE_FILTER ${STYLE_FILTER},-readability/streams) + +# Ugh! +set(STYLE_FILTER ${STYLE_FILTER},-whitespace/tab) + +# Yes it is! +set(STYLE_FILTER ${STYLE_FILTER},-whitespace/blank_line) + +# Suggessts excessive indentation. +set(STYLE_FILTER ${STYLE_FILTER},-whitespace/labels) + +# Don't tell me how to name my variables. +set(STYLE_FILTER ${STYLE_FILTER},-runtime/arrays) + +# Why? +set(STYLE_FILTER ${STYLE_FILTER},-whitespace/todo) +set(STYLE_FILTER ${STYLE_FILTER},-readability/todo) + +function(add_style_check_target TARGET_NAME SOURCES_LIST INCLUDES_LIST) + + if(PYTHONINTERP_FOUND) + + add_custom_target(${TARGET_NAME} + COMMAND cmake -E chdir + "${CMAKE_SOURCE_DIR}" + "${PYTHON_EXECUTABLE}" + "${CMAKE_MODULE_PATH}/cpplint.py" + "--filter=${STYLE_FILTER}" + ${INCLUDES_LIST} + ${INCLUDES_LIST} + ) + + endif() + +endfunction(add_style_check_target) \ No newline at end of file diff --git a/src/cli/main.cpp b/src/cli/main.cpp index 5673e8e..b91bf8b 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -65,7 +65,11 @@ namespace fs = boost::filesystem; namespace po = boost::program_options; static void print_version() { - std::cout << color::white << innoextract_version << color::reset << '\n'; + std::cout << color::white << innoextract_version << color::reset +#ifdef DEBUG + << " (with debug output)" +#endif + << '\n'; std::cout << "Extracts installers created by " << color::cyan << innosetup_versions << color::reset << '\n'; } @@ -161,7 +165,7 @@ static void process_file(const fs::path & file, const options & o) { debug("[starting " << chunk.first.compression << " chunk @ " << chunk.first.first_slice << " + " << print_hex(offsets.data_offset) << " + " << print_hex(chunk.first.offset) - << ']' << std::endl); + << ']'); stream::chunk_reader::pointer chunk_source; chunk_source = stream::chunk_reader::get(*slice_reader, chunk.first);