CMake Lists
CMake Lists
CMake Lists
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
enable_testing()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Dependencies
find_package(Threads REQUIRED)
find_package(ZLIB REQUIRED)
find_package(Boost 1.75.0 REQUIRED
COMPONENTS system regex filesystem program_options iostreams thread)
# CMake's provided `FindGTest.cmake` does not define GMock.
# We use `CONFIG` to find the `GTestConfig.cmake` provided by gtest, which properly
defines GMock.
find_package(GTest 1.10.0 REQUIRED CONFIG)
find_package(JsonCpp 1.9.4 REQUIRED)
find_package(fmt 7.1.2 REQUIRED)
find_package(re2 REQUIRED)
find_package(Redex REQUIRED)
# Enable/disable warnings.
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options("-Wall" "-Wextra" "-Wno-nullability-completeness")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compile_options("-Wall" "-Wextra" "-Wno-nonnull-compare")
else()
message(WARNING "Compiler ${CMAKE_CXX_COMPILER_ID} is not currently supported.")
endif()
# Targets
file(GLOB library_sources
"source/*.def"
"source/*.cpp"
"source/constraints/*.cpp"
"source/shim-generator/*.cpp"
"source/model-generator/*.cpp")
list(FILTER library_sources EXCLUDE REGEX ".*/source/Main.cpp")
add_library(mariana-trench-library STATIC ${library_sources})
target_link_libraries(mariana-trench-library PUBLIC
Threads::Threads
ZLIB::ZLIB
Boost::system
Boost::regex
Boost::filesystem
Boost::program_options
Boost::iostreams
Boost::thread
GTest::gtest
JsonCpp::JsonCpp
fmt::fmt
re2::re2
Redex::LibTool)
target_include_directories(mariana-trench-library PUBLIC "$
{CMAKE_CURRENT_BINARY_DIR}/header-tree")
add_executable(mariana-trench-binary "source/Main.cpp")
target_link_libraries(mariana-trench-binary PUBLIC mariana-trench-library)
install(TARGETS mariana-trench-binary DESTINATION "bin")
function(generate_shim_wrapper)
set(REPOSITORY_ROOT "${CMAKE_SOURCE_DIR}")
set(BUILD_ROOT "${CMAKE_BINARY_DIR}")
configure_file("scripts/cmake_shim.py" "${CMAKE_CURRENT_BINARY_DIR}/mariana-
trench")
endfunction()
generate_shim_wrapper()
# Tests
include(GoogleTest)
add_custom_target(build-tests)
add_executable(mariana-trench-integration-test-models EXCLUDE_FROM_ALL
"source/tests/integration/models/IntegrationTest.cpp")
target_link_libraries(mariana-trench-integration-test-models PUBLIC
mariana-trench-test-library
GTest::gmock
GTest::gtest_main)
add_dependencies(build-tests mariana-trench-integration-test-models)
gtest_discover_tests(mariana-trench-integration-test-models)
find_package(Java)
find_package(AndroidSDK)
if (NOT Java_FOUND)
message(STATUS "Integration tests are disabled because Java could not be found.")
elseif (NOT AndroidSDK_FOUND)
message(STATUS "Integration tests are disable because Android SDK could not be
found.")
else()
include(UseJava)
function(generate_integration_test directory)
add_executable(mariana-trench-integration-test-${directory} EXCLUDE_FROM_ALL
"source/tests/integration/${directory}/IntegrationTest.cpp")
target_link_libraries(mariana-trench-integration-test-${directory} PUBLIC
mariana-trench-test-library
GTest::gmock
GTest::gtest_main)
add_dependencies(build-tests mariana-trench-integration-test-${directory})
set(test_properties "")
file(GLOB codes "source/tests/integration/${directory}/code/*")
foreach(path ${codes})
get_filename_component(name "${path}" NAME)
generate_integration_test_code("${path}" "${directory}-${name}")
add_dependencies(mariana-trench-integration-test-${directory} "java-dex-$
{directory}-${name}")
list(APPEND test_properties ENVIRONMENT "${name}=java-dex-${directory}-$
{name}.dex")
endforeach()
gtest_discover_tests(mariana-trench-integration-test-${directory} PROPERTIES "$
{test_properties}")
endfunction()
generate_integration_test(end-to-end)
generate_integration_test(json-model-generator)
endif()
# CMake's `test` target does not build the tests, so we define our own `check`
target.
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS build-tests)