From 9cbc397ed62024f630b8bc2c338b03f7726aa8e4 Mon Sep 17 00:00:00 2001 From: Thomas Nilefalk Date: Tue, 31 May 2022 18:10:08 +0200 Subject: [PATCH] [build][runner] Add option to build (or not) runner (CGREEN_BUILD_RUNNER) --- DefineOptions.cmake | 1 + tools/CMakeLists.txt | 78 +++++++++++++++++++++++--------------------- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/DefineOptions.cmake b/DefineOptions.cmake index fdbc3d6a..62489e5c 100644 --- a/DefineOptions.cmake +++ b/DefineOptions.cmake @@ -1,4 +1,5 @@ option(CGREEN_WITH_STATIC_LIBRARY "Build with a static library" OFF) option(CGREEN_WITH_UNIT_TESTS "Build unit tests" ON) +option(CGREEN_BUILD_RUNNER "Build auto-discovering cgreen-runner using libbfd" ON) option(CGREEN_INTERNAL_WITH_GCOV "Build with test coverage instrumentation" OFF) mark_as_advanced(CGREEN_INTERNAL_WITH_GCOV) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index e44d054f..0f8ce1dd 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,46 +1,48 @@ -find_package(LibBfd) +if(CGREEN_BUILD_RUNNER) + find_package(LibBfd) -if(LibBfd_FOUND) - include_directories(${CGREEN_PUBLIC_INCLUDE_DIRS} ${PROJECT_BINARY_DIR} ${LIBBFD_INCLUDE_DIRS}) + if(LibBfd_FOUND) + include_directories(${CGREEN_PUBLIC_INCLUDE_DIRS} ${PROJECT_BINARY_DIR} ${LIBBFD_INCLUDE_DIRS}) - # Need to explicitly add libintl - Cygwin issue with binutils-2.37-2 - if (CYGWIN) - find_library(EXPLICIT_INTLIB_ONLY_REQUIRED_FOR_CYGWIN NAMES intl libintl) - else () - set(EXPLICIT_INTLIB_ONLY_REQUIRED_FOR_CYGWIN "") - endif() + # Need to explicitly add libintl - Cygwin issue with binutils-2.37-2 + if (CYGWIN) + find_library(EXPLICIT_INTLIB_ONLY_REQUIRED_FOR_CYGWIN NAMES intl libintl) + else () + set(EXPLICIT_INTLIB_ONLY_REQUIRED_FOR_CYGWIN "") + endif() - set(RUNNER_SRCS - ${CMAKE_CURRENT_SOURCE_DIR}/cgreen-runner.c - ${CMAKE_CURRENT_SOURCE_DIR}/gopt.c - ${CMAKE_CURRENT_SOURCE_DIR}/gopt-errors.c - ${CMAKE_CURRENT_SOURCE_DIR}/runner.c - ${CMAKE_CURRENT_SOURCE_DIR}/discoverer.c - ${CMAKE_CURRENT_SOURCE_DIR}/test_item.c - ${CMAKE_CURRENT_SOURCE_DIR}/bfd_adapter.c - ) - set_source_files_properties(${RUNNER_SRCS} PROPERTIES LANGUAGE C) + set(RUNNER_SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/cgreen-runner.c + ${CMAKE_CURRENT_SOURCE_DIR}/gopt.c + ${CMAKE_CURRENT_SOURCE_DIR}/gopt-errors.c + ${CMAKE_CURRENT_SOURCE_DIR}/runner.c + ${CMAKE_CURRENT_SOURCE_DIR}/discoverer.c + ${CMAKE_CURRENT_SOURCE_DIR}/test_item.c + ${CMAKE_CURRENT_SOURCE_DIR}/bfd_adapter.c + ) + set_source_files_properties(${RUNNER_SRCS} PROPERTIES LANGUAGE C) - include(DefineRelativeFilePaths) - cmake_define_relative_file_paths ("${RUNNER_SRCS}") + include(DefineRelativeFilePaths) + cmake_define_relative_file_paths ("${RUNNER_SRCS}") - add_executable(cgreen-runner ${RUNNER_SRCS}) - target_link_libraries(cgreen-runner PRIVATE - ${CGREEN_LIBRARY} - ${CMAKE_DL_LIBS} - ${LIBBFD_LIBRARIES} - ${EXPLICIT_INTLIB_ONLY_REQUIRED_FOR_CYGWIN} - ) + add_executable(cgreen-runner ${RUNNER_SRCS}) + target_link_libraries(cgreen-runner PRIVATE + ${CGREEN_LIBRARY} + ${CMAKE_DL_LIBS} + ${LIBBFD_LIBRARIES} + ${EXPLICIT_INTLIB_ONLY_REQUIRED_FOR_CYGWIN} + ) - install(TARGETS cgreen-runner - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - DESTINATION ${CMAKE_INSTALL_BINDIR} - ) + install(TARGETS cgreen-runner + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + DESTINATION ${CMAKE_INSTALL_BINDIR} + ) - install(PROGRAMS cgreen-debug - DESTINATION ${CMAKE_INSTALL_BINDIR}) -else() - message(WARNING "libbfd not found, cgreen-runner will not be built") + install(PROGRAMS cgreen-debug + DESTINATION ${CMAKE_INSTALL_BINDIR}) + else() + message(WARNING "libbfd not found, cgreen-runner will not be built") + endif() endif()