Browse Source

CMake: Don't rely on SOURCE_GLOB to find headers

coverity_scan
Daniel Scharrer 13 years ago
parent
commit
32eba667ea
  1. 89
      CMakeLists.txt
  2. 15
      cmake/CreateSourceGroups.cmake
  3. 140
      cmake/FilterList.cmake
  4. 12
      cmake/StyleCheck.cmake

89
CMakeLists.txt

@ -57,8 +57,10 @@ include(CheckSymbolExists)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") # For custom cmake modules
include(BuildType)
include(CompileCheck)
include(CreateSourceGroups)
include(CXX11Check)
include(Doxygen)
include(FilterList)
include(PrintConfiguration)
include(StyleCheck)
include(UseStaticLibs)
@ -222,70 +224,115 @@ check_symbol_exists(bswap_64 "byteswap.h" INNOEXTRACT_HAVE_BSWAP_64)
set(INNOEXTRACT_SOURCES
src/release.hpp
${VERSION_FILE}
src/cli/debug.hpp
src/cli/debug.cpp if DEBUG
src/cli/main.cpp
src/crypto/adler32.hpp
src/crypto/adler32.cpp
src/crypto/checksum.hpp
src/crypto/checksum.cpp
src/crypto/crc32.hpp
src/crypto/crc32.cpp
src/crypto/hasher.cpp
src/crypto/hasher.cpp
src/crypto/iteratedhash.hpp
src/crypto/md5.hpp
src/crypto/md5.cpp
src/crypto/sha1.hpp
src/crypto/sha1.cpp
src/loader/exereader.hpp
src/loader/exereader.cpp
src/loader/offsets.hpp
src/loader/offsets.cpp
src/setup/component.hpp
src/setup/component.cpp
src/setup/data.hpp
src/setup/data.cpp
src/setup/delete.hpp
src/setup/delete.cpp
src/setup/directory.hpp
src/setup/directory.cpp
src/setup/expression.hpp
src/setup/expression.cpp
src/setup/file.hpp
src/setup/file.cpp
src/setup/filename.hpp
src/setup/filename.cpp
src/setup/header.hpp
src/setup/header.cpp
src/setup/icon.hpp
src/setup/icon.cpp
src/setup/info.hpp
src/setup/info.cpp
src/setup/ini.hpp
src/setup/ini.cpp
src/setup/item.hpp
src/setup/item.cpp
src/setup/language.hpp
src/setup/language.cpp
src/setup/message.hpp
src/setup/message.cpp
src/setup/permission.hpp
src/setup/permission.cpp
src/setup/registry.hpp
src/setup/registry.cpp
src/setup/run.hpp
src/setup/run.cpp
src/setup/task.hpp
src/setup/task.cpp
src/setup/type.hpp
src/setup/type.cpp
src/setup/version.hpp
src/setup/version.cpp
src/setup/windows.hpp
src/setup/windows.cpp
src/stream/block.hpp
src/stream/block.cpp
src/stream/checksum.hpp
src/stream/chunk.hpp
src/stream/chunk.cpp
src/stream/exefilter.hpp
src/stream/file.hpp
src/stream/file.cpp
src/stream/lzma.hpp
src/stream/lzma.cpp if INNOEXTRACT_HAVE_LZMA
src/stream/restrict.hpp
src/stream/slice.hpp
src/stream/slice.cpp
src/util/boostfs_compat.hpp
src/util/console.hpp
src/util/console.cpp
src/util/endian.hpp
src/util/enum.hpp
src/util/flags.hpp
src/util/fstream.hpp
src/util/load.hpp
src/util/load.cpp
src/util/log.hpp
src/util/log.cpp
src/util/output.hpp
src/util/storedenum.hpp
src/util/time.hpp
src/util/time.cpp
src/util/types.hpp
src/util/unique_ptr.hpp
src/util/util.hpp
src/util/windows.hpp
src/util/windows.cpp if WIN32
)
if(DEBUG)
list(APPEND INNOEXTRACT_SOURCES src/cli/debug.cpp)
endif()
if(LZMA_FOUND)
list(APPEND INNOEXTRACT_SOURCES src/stream/lzma.cpp)
endif()
if(WIN32)
list(APPEND INNOEXTRACT_SOURCES src/util/windows.cpp)
endif()
file(GLOB_RECURSE ALL_INCLUDES "${CMAKE_SOURCE_DIR}/src/*.hpp")
list(SORT INNOEXTRACT_SOURCES)
list(SORT ALL_INCLUDES)
filter_list(INNOEXTRACT_SOURCES ALL_INNOEXTRACT_SOURCES)
list(APPEND CHECKED_SOURCES ${INNOEXTRACT_SOURCES})
create_source_groups(ALL_INNOEXTRACT_SOURCES)
# Prepare generated files
@ -297,12 +344,12 @@ configure_file("src/configure.hpp.in" "configure.hpp")
set(VERSION_FILE "${CMAKE_BINARY_DIR}/release.cpp")
set(VERSION_SOURCES VERSION "VERSION" LICENSE "LICENSE")
version_file("src/release.cpp.in" "${VERSION_FILE}" "${VERSION_SOURCES}" ".git")
list(APPEND INNOEXTRACT_SOURCES "${VERSION_FILE}")
list(APPEND INNOEXTRACT_SOURCES ${VERSION_FILE})
# Main targets
add_executable(innoextract ${INNOEXTRACT_SOURCES} ${ALL_INCLUDES})
add_executable(innoextract ${INNOEXTRACT_SOURCES})
target_link_libraries(innoextract ${LIBRARIES})
install(TARGETS innoextract RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
@ -312,7 +359,7 @@ install(FILES doc/innoextract.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 OPTIONA
# Additional targets.
add_style_check_target(style "${CHECKED_SOURCES}" "${ALL_INCLUDES}")
add_style_check_target(style "${ALL_INNOEXTRACT_SOURCES}")
add_doxygen_target(doc "doc/Doxyfile.in" "VERSION" ".git" "${CMAKE_BINARY_DIR}/doc")

15
cmake/CreateSourceGroups.cmake

@ -0,0 +1,15 @@
# Accepts a variable holding the source files
# and creates source groups (for VS, Xcode etc)
# that replicate the folder hierarchy on disk
function(create_source_groups source_files_variable)
foreach(source_file ${${source_files_variable}})
string( REGEX REPLACE ${CMAKE_CURRENT_SOURCE_DIR} "" relative_directory "${source_file}")
string( REGEX REPLACE "[\\\\/][^\\\\/]*$" "" relative_directory "${relative_directory}")
string( REGEX REPLACE "^[\\\\/]" "" relative_directory "${relative_directory}")
if( WIN32 )
string( REGEX REPLACE "/" "\\\\" relative_directory "${relative_directory}" )
endif( WIN32 )
source_group( "${relative_directory}" FILES ${source_file} )
endforeach()
endfunction()

140
cmake/FilterList.cmake

@ -0,0 +1,140 @@
# Copyright (C) 2013 Daniel Scharrer
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the author(s) be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
# Filter a list with conditional ites
#
# Supported syntax:
#
# item
#
# item if CONDITION_VARIABLE
#
# CONDITION_VARIABLE {
# item1
# item2
# }
#
# Conditions cannot be nested.
#
# The list specified by LIST_NAM Ewill be modifed in place.
# An optional second parameter can be given to specify the name of a list that
# should receive all items, even those whose conditions evaluated to false,
# but not syntactic elements such as 'if', '{', '}' and condition variables.
#
function(filter_list LIST_NAME)
set(filtered)
set(all)
# the item from the previous iteration
set(last_item)
# current syntax state:
# 0 - start
# 1 - after 'if', expected condition variable
# 2 - inside block (true)
# 3 - inside block (false)
set(mode 0)
foreach(item IN LISTS ${LIST_NAME})
if(mode EQUAL 1)
# Handle condition variables
set(condition ${${item}})
if(condition)
list(APPEND filtered ${last_item})
endif()
set(mode 0)
set(last_item)
elseif("${item}" STREQUAL "if")
if(NOT mode EQUAL 0)
message(FATAL_ERROR "bad filter_list syntax: IF inside { } block is forbidden")
endif()
# Handle condition start
if("${last_item}" STREQUAL "")
message(FATAL_ERROR "bad filter_list syntax: IF without preceding item")
endif()
set(mode 1)
elseif("${item}" STREQUAL "{")
if(NOT mode EQUAL 0)
message(FATAL_ERROR "bad filter_list syntax: cannot nest { } blocks")
endif()
if("${last_item}" STREQUAL "")
message(FATAL_ERROR "bad filter_list syntax: { without preceding item")
endif()
set(condition ${${last_item}})
if(condition)
set(mode 2)
else()
set(mode 3)
endif()
set(last_item)
else()
# Handle unconditional items
if(NOT "${last_item}" STREQUAL "" AND NOT mode EQUAL 3)
list(APPEND filtered ${last_item})
endif()
if("${item}" STREQUAL "}")
if(mode EQUAL 0)
message(FATAL_ERROR "bad filter_list syntax: } without open block")
endif()
set(mode 0)
set(last_item)
else()
list(APPEND all ${item})
set(last_item ${item})
endif()
endif()
endforeach()
if(mode EQUAL 1)
message(FATAL_ERROR "bad filter_list syntax: unexpected end, expected condition")
elseif(mode EQUAL 2 OR mode EQUAL 3)
message(FATAL_ERROR "bad filter_list syntax: unexpected end, expected }")
endif()
list(SORT filtered)
list(REMOVE_DUPLICATES filtered)
set(${LIST_NAME} ${filtered} PARENT_SCOPE)
if(${ARGC} GREATER 1)
list(SORT all)
list(REMOVE_DUPLICATES all)
set(${ARGV1} ${all} PARENT_SCOPE)
endif()
endfunction()

12
cmake/StyleCheck.cmake

@ -57,22 +57,24 @@ set(STYLE_FILTER ${STYLE_FILTER},-whitespace/semicolon)
#
# Parameters:
# - TARGET_NAME the name of the target to add
# - SOURCES_LIST a complete list of source files to check
# - INCLUDES_LIST a complete list of include files to check
function(add_style_check_target TARGET_NAME SOURCES_LIST INCLUDES_LIST)
# - SOURCES_LIST a complete list of source and include files to check
function(add_style_check_target TARGET_NAME SOURCES_LIST)
if(NOT PYTHONINTERP_FOUND)
return()
endif()
list(SORT SOURCES_LIST)
list(REMOVE_DUPLICATES SOURCES_LIST)
add_custom_target(${TARGET_NAME}
COMMAND "${CMAKE_COMMAND}" -E chdir
"${CMAKE_SOURCE_DIR}"
"${PYTHON_EXECUTABLE}"
"${CMAKE_MODULE_PATH}/cpplint.py"
"--filter=${STYLE_FILTER}"
${SOURCES_LIST} ${INCLUDES_LIST}
DEPENDS ${SOURCES_LIST} ${INCLUDES_LIST}
${SOURCES_LIST}
DEPENDS ${SOURCES_LIST}
COMMENT "Checking code style."
VERBATIM
)

Loading…
Cancel
Save