cmake: Add include-what-you-use integration.
Change-Id: Ifcfd15e0b7b81c013116ad770985a3fe4911391a
This commit is contained in:
@@ -17,6 +17,7 @@ set(LIBWEBM_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
# Build/test configuration flags. Defined here for visibility.
|
||||
option(ENABLE_WEBMTS "Enables WebM PES/TS support." ON)
|
||||
option(ENABLE_TESTS "Enables tests." OFF)
|
||||
option(ENABLE_IWYU "Enables include-what-you-use support." OFF)
|
||||
set(GTEST_SRC_DIR "${LIBWEBM_SRC_DIR}/../googletest" CACHE PATH
|
||||
"Path to Googletest git repository.")
|
||||
|
||||
@@ -199,3 +200,34 @@ if (ENABLE_TESTS)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# Include-what-you-use section.
|
||||
if (ENABLE_IWYU)
|
||||
# Make sure all the tools necessary for IWYU are present.
|
||||
find_program(iwyu_path NAMES include-what-you-use)
|
||||
find_program(iwyu_tool_path NAMES iwyu_tool.py)
|
||||
|
||||
# Some odd behavior on cmake's part: PYTHON_EXECUTABLE and PYTHON_VERSION_*
|
||||
# are set by cmake when it does its internal python check, but
|
||||
# PYTHONINTERP_FOUND is empty without explicitly looking for it.
|
||||
find_package(PythonInterp)
|
||||
|
||||
if (iwyu_path AND iwyu_tool_path AND PYTHONINTERP_FOUND)
|
||||
# Enable compilation command export (needed for iwyu_tool.py)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
# Add a custom target to run iwyu across all targets.
|
||||
add_custom_target(iwyu
|
||||
ALL
|
||||
COMMAND "${PYTHON_EXECUTABLE}" "${iwyu_tool_path}" -p
|
||||
"${CMAKE_BINARY_DIR}"
|
||||
COMMENT "Running include-what-you-use..."
|
||||
VERBATIM)
|
||||
else ()
|
||||
message(STATUS "Ignoring ENABLE_IWYU because reasons:")
|
||||
message(STATUS " iwyu_path=" ${iwyu_path})
|
||||
message(STATUS " iwyu_tool_path=" ${iwyu_tool_path})
|
||||
message(STATUS " PYTHONINTERP_FOUND=" ${PYTHONINTERP_FOUND})
|
||||
message(STATUS " See README.libwebm for more information.")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
|
||||
@@ -81,3 +81,41 @@ Note: Libwebm Googletest integration was built with googletest from
|
||||
https://github.com/google/googletest.git at git revision
|
||||
ddb8012eb48bc203aa93dcc2b22c1db516302b29.
|
||||
|
||||
|
||||
CMake Include-what-you-use integration
|
||||
|
||||
Include-what-you-use is an analysis tool that helps ensure libwebm includes the
|
||||
C/C++ header files actually in use. To enable the integration support
|
||||
ENABLE_IWYU must be turned on at cmake run time:
|
||||
|
||||
$ cmake path/to/libwebm -G "Unix Makefiles" -DENABLE_IWYU=ON
|
||||
|
||||
This adds the iwyu target to the build. To run include-what-you-use:
|
||||
|
||||
$ make iwyu
|
||||
|
||||
The following requirements must be met for ENABLE_IWYU to enable the iwyu
|
||||
target:
|
||||
|
||||
1. include-what-you-use and iwyu_tool.py must be in your PATH.
|
||||
2. A python interpreter must be on the system and available to CMake.
|
||||
|
||||
The values of the following variables are used to determine if the requirements
|
||||
have been met. Values to the right of the equals sign are what a successful run
|
||||
might look like:
|
||||
iwyu_path=/path/to/iwyu_tool.py
|
||||
iwyu_tool_path=/path/to/include-what-you-use
|
||||
PYTHONINTERP_FOUND=TRUE
|
||||
|
||||
An empty PYTHONINTERP_FOUND, or iwyu_path/iwyu_tool_path suffixed with NOTFOUND
|
||||
are failures.
|
||||
|
||||
For Include-what-you-use setup instructions, see:
|
||||
https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/InstructionsForUsers.md
|
||||
|
||||
If, when building the iwyu target, compile errors reporting failures loading
|
||||
standard include files occur, one solution can be found here:
|
||||
https://github.com/include-what-you-use/include-what-you-use/issues/100
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user