Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving to submodules, adding sanitizer #111

Merged
merged 1 commit into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ branches:
- master

install:
- git submodule update --init --recursive
- set PATH=C:\Python36;%PATH%
- cmake --version
- pip install conan
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "extern/googletest"]
path = extern/googletest
url = ../../google/googletest.git
[submodule "extern/sanitizers"]
path = extern/sanitizers
url = ../../arsenm/sanitizers-cmake
44 changes: 2 additions & 42 deletions cmake/AddGoogletest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,8 @@
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF)

if(CMAKE_VERSION VERSION_LESS 3.11)
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
include(DownloadProject)
download_project(PROJ googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.0
UPDATE_DISCONNECTED 1
QUIET
)

# CMake warning suppression will not be needed in version 1.9
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "")
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_SOURCE_DIR} EXCLUDE_FROM_ALL)
else()
include(FetchContent)
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.0)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "")
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endif()



if(CMAKE_CONFIGURATION_TYPES)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
--force-new-ctest-process --output-on-failure
--build-config "$<CONFIGURATION>")
else()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
--force-new-ctest-process --output-on-failure)
endif()
set_target_properties(check PROPERTIES FOLDER "Scripts")

#include_directories(${gtest_SOURCE_DIR}/include)

# More modern way to do the last line, less messy but needs newish CMake:
# target_include_directories(gtest INTERFACE ${gtest_SOURCE_DIR}/include)
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "")
add_subdirectory("${CLI11_SOURCE_DIR}/extern/googletest" "${CLI11_BINARY_DIR}/extern/googletest" EXCLUDE_FROM_ALL)


if(GOOGLE_TEST_INDIVIDUAL)
Expand Down
17 changes: 0 additions & 17 deletions cmake/DownloadProject.CMakeLists.cmake.in

This file was deleted.

164 changes: 0 additions & 164 deletions cmake/DownloadProject.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class HelloConan(ConanFile):
license = "BSD 3 clause"
description = "Command Line Interface toolkit for C++11"

exports_sources = "LICENSE", "README.md", "include/*", "cmake/*", "CMakeLists.txt", "tests/*"
exports_sources = "LICENSE", "README.md", "include/*", "extern/*", "cmake/*", "CMakeLists.txt", "tests/*"

def build(self): # this is not building a library, just tests
cmake = CMake(self)
Expand Down
1 change: 1 addition & 0 deletions extern/googletest
Submodule googletest added at ec44c6
1 change: 1 addition & 0 deletions extern/sanitizers
Submodule sanitizers added at 6947cf
20 changes: 20 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
if(NOT EXISTS "${CLI11_SOURCE_DIR}/extern/googletest/CMakeLists.txt")
message(FATAL_ERROR "You have requested tests be built, but googletest is not downloaded. Please run:
git submodule update --init")
endif()

# If submodule is available, add sanitizers
# Set SANITIZE_ADDRESS, SANITIZE_MEMORY, SANITIZE_THREAD or SANITIZE_UNDEFINED
if(EXISTS "${CLI11_SOURCE_DIR}/extern/sanitizers/cmake/FindSanitizers.cmake")
set(CMAKE_MODULE_PATH "${CLI11_SOURCE_DIR}/extern/sanitizers/cmake" ${CMAKE_MODULE_PATH})
find_package(Sanitizers)
if(SANITIZE_ADDRESS)
message(STATUS "You might want to use \"${ASan_WRAPPER}\" to run your program")
endif()
else()
macro(add_sanitizers)
endmacro()
endif()

set(GOOGLE_TEST_INDIVIDUAL OFF)
include(AddGoogletest)

Expand All @@ -23,6 +41,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
foreach(T ${CLI11_TESTS})

add_executable(${T} ${T}.cpp ${CLI11_headers})
add_sanitizers(${T})
target_link_libraries(${T} PUBLIC CLI11)
add_gtest(${T})

Expand All @@ -40,6 +59,7 @@ endforeach()
foreach(T ${CLI11_MULTIONLY_TESTS})

add_executable(${T} ${T}.cpp ${CLI11_headers})
add_sanitizers(${T})
target_link_libraries(${T} PUBLIC CLI11)
add_gtest(${T})

Expand Down