bareflank-hypervisor/scripts/cmake/targets.cmake
Rian Quinn aab477a590
Build System Bug Fixes (#575)
This patch addresses several bugs with the build system:
- Lack of Windows support
- Clang Tidy was not working properly
- Making modifications to the source code would compile, but would not
re-link resulting in issues
- Removed excess file copying
- Make clean now works
- Removed unused or confusing folders in the build folder as part of the
build process. It is now much easier to traverse the build folder for
dependencies
- The targets didn't work with extensions. This has been fixed.

In addition, the following was also done under this patch
- Intrinsics was moved to the top level and out of the VMM
- Platform files are now in a folder called "platform" instead of
"arch"
- All subprojects have the same include/src/tests files structure
- All intel specific code is properly organized to match intended
namespacing
- Removed dead code
- A small part of the VMCS was converted to use the delegate pattern
- All dependencies are now downloaded at configure time instead of
compile time.
- The cache directory is now cached by Travis CI
- CMake output better matches old build system
- Added make rebuild and separate clean targets to remove various parts
of the build depending on needs.
- Added targets for Clean, Tidy, Rebuild and Format for each subproject
- Re-organized the cmake logic so that macros are not spread out
- New validation removes unneeded complexity
- Removed the need for the compiler wrapper, and in doing so, we now
provide a simpilar set of toolchain files
- Removed the need for Git repos. All external dependencies are
downloaded using a zip or tarball
- Libcxx and Libcxxabi are now in their own files. Much similar logic
- Unit test CMake files have been greatly simplified
- Each subproject is unaware of it's prefix and no long use VMM,
USERSPACE or TEST variables in their cmake files
- Fixed bugs with the flags
- Renamed the varbiables in the default.cmake config to be more
consistent and easier to follow in the rest of the code

Signed-off-by: “rianquinn” <“rianquinn@gmail.com”>
2018-01-22 12:45:07 -07:00

279 lines
7.5 KiB
CMake

#
# Bareflank Hypervisor
# Copyright (C) 2015 Assured Information Security, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
if(NOT WIN32 AND NOT CYGWIN)
set(SUDO sudo)
else()
set(SUDO "")
endif()
# ------------------------------------------------------------------------------
# Target Prototypes
# ------------------------------------------------------------------------------
if(ENABLE_BUILD_TEST)
if(POLICY CMP0037)
cmake_policy(SET CMP0037 OLD)
endif()
add_custom_target(test)
add_custom_target(unittest)
endif()
if(ENABLE_TIDY)
add_custom_target(tidy)
add_custom_target(tidy-all)
endif()
if(ENABLE_FORMAT)
add_custom_target(format)
add_custom_target(format-all)
endif()
add_custom_target(clean-depends)
add_custom_target(clean-subprojects)
if(NOT WIN32)
add_custom_target(info)
endif()
# ------------------------------------------------------------------------------
# Driver
# ------------------------------------------------------------------------------
if(NOT WIN32)
add_custom_target_category("Bareflank Driver")
add_custom_target(driver_build
COMMAND ${SOURCE_UTIL_DIR}/driver_build.sh ${SOURCE_BFDRIVER_DIR}
USES_TERMINAL
)
add_custom_target_info(
TARGET driver_build
COMMENT "Build the Bareflank driver"
)
add_custom_target(driver_clean
COMMAND ${SOURCE_UTIL_DIR}/driver_clean.sh ${SOURCE_BFDRIVER_DIR}
USES_TERMINAL
)
add_custom_target_info(
TARGET driver_clean
COMMENT "Clean the Bareflank driver"
)
add_custom_target(driver_load
COMMAND ${SOURCE_UTIL_DIR}/driver_load.sh ${SOURCE_BFDRIVER_DIR}
USES_TERMINAL
)
add_custom_target_info(
TARGET driver_load
COMMENT "Load the Bareflank driver"
)
add_custom_target(driver_unload
COMMAND ${SOURCE_UTIL_DIR}/driver_unload.sh ${SOURCE_BFDRIVER_DIR}
USES_TERMINAL
)
add_custom_target_info(
TARGET driver_unload
COMMENT "Unload the Bareflank driver"
)
add_custom_target(
driver_quick
COMMAND ${CMAKE_COMMAND} --build . --target driver_unload
COMMAND ${CMAKE_COMMAND} --build . --target driver_clean
COMMAND ${CMAKE_COMMAND} --build . --target driver_build
COMMAND ${CMAKE_COMMAND} --build . --target driver_load
USES_TERMINAL
)
add_custom_target_info(
TARGET driver_quick
COMMENT "Unload, clean, build, and load the Bareflank driver"
)
endif()
# ------------------------------------------------------------------------------
# BFM
# ------------------------------------------------------------------------------
if(NOT WIN32 AND ENABLE_BUILD_VMM AND ENABLE_BUILD_USERSPACE)
add_custom_target_category("Bareflank Manager")
add_custom_target(
quick
COMMAND ${SUDO} ${USERSPACE_PREFIX_PATH}/bin/bfm load ${BFM_VMM_BIN_PATH}/${BFM_VMM}
COMMAND ${SUDO} ${USERSPACE_PREFIX_PATH}/bin/bfm start
USES_TERMINAL
)
add_custom_target_info(
TARGET quick
COMMENT "Load and start the VMM"
)
add_custom_target(
load
COMMAND ${SUDO} ${USERSPACE_PREFIX_PATH}/bin/bfm load ${BFM_VMM_BIN_PATH}/${BFM_VMM}
USES_TERMINAL
)
add_custom_target_info(
TARGET load
COMMENT "Load the VMM"
)
add_custom_target(
start
COMMAND ${SUDO} ${USERSPACE_PREFIX_PATH}/bin/bfm start
USES_TERMINAL
)
add_custom_target_info(
TARGET start
COMMENT "Start the VMM"
)
add_custom_target(
stop
COMMAND ${SUDO} ${USERSPACE_PREFIX_PATH}/bin/bfm stop
USES_TERMINAL
)
add_custom_target_info(
TARGET stop
COMMENT "Stop the VMM"
)
add_custom_target(
unload
COMMAND ${SUDO} ${USERSPACE_PREFIX_PATH}/bin/bfm unload
USES_TERMINAL
)
add_custom_target_info(
TARGET unload
COMMENT "Unload the VMM"
)
add_custom_target(
dump
COMMAND ${SUDO} ${USERSPACE_PREFIX_PATH}/bin/bfm dump
USES_TERMINAL
)
add_custom_target_info(
TARGET dump
COMMENT "Print the contents of the VMMs debug ring"
)
add_custom_target(
status
COMMAND ${SUDO} ${USERSPACE_PREFIX_PATH}/bin/bfm status
USES_TERMINAL
)
add_custom_target_info(
TARGET status
COMMENT "Display the status of the VMM"
)
endif()
# ------------------------------------------------------------------------------
# Build / Clean
# ------------------------------------------------------------------------------
add_custom_target_category("Clean / Rebuild")
add_custom_target(
clean-prefixes
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PREFIXES_DIR}
)
add_custom_target(
clean-all
COMMAND ${CMAKE_COMMAND} --build . --target clean
COMMAND ${CMAKE_COMMAND} -E remove_directory ${PREFIXES_DIR}
USES_TERMINAL
)
add_custom_target_info(
TARGET clean-all
COMMENT "Clean the build tree, dependencies, prefixes, and subprojects"
)
add_custom_target(
rebuild
COMMAND ${CMAKE_COMMAND} --build . --target clean-subprojects
COMMAND ${CMAKE_COMMAND} --build .
USES_TERMINAL
)
add_custom_target_info(
TARGET rebuild
COMMENT "Clean the subprojects and rebuild"
)
# ------------------------------------------------------------------------------
# Test
# ------------------------------------------------------------------------------
if(ENABLE_BUILD_TEST)
add_custom_target_category("Unit Testing")
add_custom_target_info(
TARGET test
COMMENT "Run Bareflank unit tests"
)
endif()
# ------------------------------------------------------------------------------
# Clang Tidy
# ------------------------------------------------------------------------------
if(ENABLE_TIDY)
add_custom_target_category("Clang Tidy Static Analysis")
add_custom_target_info(
TARGET tidy
COMMENT "Statically analyze modified files"
)
add_custom_target_info(
TARGET tidy-all
COMMENT "Statically analyze all files"
)
endif()
# ------------------------------------------------------------------------------
# Astyle
# ------------------------------------------------------------------------------
if(ENABLE_FORMAT)
add_custom_target_category("Asyle Code Formatting")
add_custom_target_info(
TARGET format
COMMENT "Format modified files"
)
add_custom_target_info(
TARGET format-all
COMMENT "Format all files"
)
endif()
# ------------------------------------------------------------------------------
# Cleanup
# ------------------------------------------------------------------------------
if(NOT WIN32)
add_custom_command(TARGET info COMMAND ${CMAKE_COMMAND} -E cmake_echo_color " ")
endif()