Skip to content
Merged

Gtest #378

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
18ba8b6
update for gtest and a few other tweaks
phlptp Apr 3, 2025
5a8a245
update to use boost in newer cmake on windows, fix some examples
phlptp Apr 3, 2025
a58fe55
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 3, 2025
812fcd4
update some tests
phlptp Apr 3, 2025
69b5d2f
Merge branch 'gtest' of https://github.com/LLNL/units into gtest
phlptp Apr 3, 2025
9b63af3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 3, 2025
457c2b8
fix cmake to use proper include variable
phlptp Apr 3, 2025
e6fd069
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 3, 2025
a58c511
use ${PROJECT_NAME} in variable test
phlptp Apr 3, 2025
594d0dc
Merge branch 'gtest' of https://github.com/LLNL/units into gtest
phlptp Apr 3, 2025
920c68a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 3, 2025
8b59383
try different name in variable
phlptp Apr 3, 2025
3d0e1ed
add tests for external gtest
phlptp Apr 3, 2025
f781781
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 3, 2025
6db7ee8
add install gtest step
phlptp Apr 3, 2025
1e2e168
Merge branch 'gtest' of https://github.com/LLNL/units into gtest
phlptp Apr 3, 2025
5b4dd18
make the GTEST an option
phlptp Apr 4, 2025
abe4750
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 4, 2025
f66fc57
install gmock
phlptp Apr 4, 2025
34ce1cc
clean up warning in tests
phlptp Apr 4, 2025
5944edc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 4, 2025
5b9b132
change the cmake variable name to be consistent with other libraries …
phlptp Apr 4, 2025
bba4fe4
Merge branch 'gtest' of https://github.com/LLNL/units into gtest
phlptp Apr 4, 2025
8fd21fb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 4, 2025
f159067
fix defaults
phlptp Apr 4, 2025
f0f3327
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 4, 2025
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
6 changes: 3 additions & 3 deletions .github/workflows/pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ jobs:
run: |
mkdir -p build
cd build
cmake .. -DUNITS_BUILD_SHARED_LIBRARY=ON -DUNITS_BUILD_STATIC_LIBRARY=OFF -DUNITS_INSTALL=ON
cmake .. -DBUILD_SHARED_LIBS=ON -DUNITS_INSTALL=ON -DUNITS_ENABLE_TESTS=OFF
make -j 4
sudo make install
cd ..
python -m pip install pytest
pip install -vv -C cmake.define.UNITS_BUILD_SHARED_LIBRARY:BOOL=ON -C cmake.define.UNITS_BUILD_STATIC_LIBRARY:BOOL=OFF .
pip install -vv -C cmake.define.BUILD_SHARED_LIBS:BOOL=ON .

- name: Test
run: |
Expand All @@ -91,7 +91,7 @@ jobs:
- name: Build and install
run: |
python -m pip install pytest
pip install -vv -C cmake.define.UNITS_BUILD_SHARED_LIBRARY:BOOL=ON -C cmake.define.UNITS_BUILD_STATIC_LIBRARY:BOOL=OFF -C cmake.define.UNITS_PYTHON_INSTALL_SHARED_LIBRARY:BOOL=ON .
pip install -vv -C cmake.define.BUILD_SHARED_LIBS:BOOL=ON -C cmake.define.UNITS_PYTHON_INSTALL_SHARED_LIBRARY:BOOL=ON .

- name: Test
run: python -m pytest ./test/python
34 changes: 27 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,36 @@ add_subdirectory(units)
if(UNITS_BUILD_FUZZ_TARGETS)
add_subdirectory(FuzzTargets)
elseif(UNITS_ENABLE_TESTS AND NOT CMAKE_VERSION VERSION_LESS 3.13)
include(updateGitSubmodules)
if(UNITS_ENABLE_SUBMODULE_UPDATE)
enable_testing()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/ThirdParty/googletest/CMakeLists.txt")
submod_update(ThirdParty/googletest)
endif()
else()
enable_testing()
option(
UNITS_USE_EXTERNAL_GTEST
"use an installed or external version of GTest instead of the included submodule"
OFF
)
mark_as_advanced(UNITS_USE_EXTERNAL_GTEST)

if(UNITS_USE_EXTERNAL_GTEST)
include(FindPkgConfig)
find_package(GTest REQUIRED)
pkg_check_modules(GMock gmock REQUIRED)
else()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/ThirdParty/googletest/CMakeLists.txt")
include(updateGitSubmodules)
if(${UNITS_CMAKE_PROJECT_NAME}_ENABLE_SUBMODULE_UPDATE)
submod_update(ThirdParty/googletest)
else()
include(FindPkgConfig)
find_package(GTest REQUIRED)
pkg_check_modules(GMock gmock REQUIRED)
if(NOT GTest_FOUND)
message(
ERROR
"GTest not found, and submodule not found and unable to update install gtest or enable submodule updating to build a local copy of gtest"
)
endif()
endif()
endif()

endif()
if(BUILD_TESTING)
add_subdirectory(test)
Expand Down
20 changes: 17 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,28 @@ jobs:
- script: git diff --exit-code --color
displayName: Check tidy

- job: Native
- job: Native_gtest
strategy:
matrix:
Linux14:
vmImage: 'ubuntu-latest'
units.options: -DUNITS_USE_EXTERNAL_GTEST=ON
Linux14shared:
vmImage: 'ubuntu-latest'
units.options: -DUNITS_BUILD_SHARED_LBIRARY=ON
units.options: -DBUILD_SHARED_LIBS=ON -DUNITS_USE_EXTERNAL_GTEST=ON
pool:
vmImage: $(vmImage)
steps:
- script: |
sudo apt-get update -qq -y # It's good practice to update before installing
sudo apt-get install -qq -y libgtest-dev libgmock-dev
displayName: 'Install gtest' # Optional: Add a display name for the step
- template: .ci/azure-build.yml
- template: .ci/azure-test.yml

- job: Native
strategy:
matrix:
macOS17:
vmImage: 'macOS-latest'
units.std: 17
Expand All @@ -48,7 +62,7 @@ jobs:
units.std: 11
Windows17:
vmImage: 'windows-2019'
units.options: -DUNITS_BUILD_SHARED_LBIRARY=ON
units.options: -DUNITS_BUILD_SHARED_LIBRARY=ON -DUNITS_BUILD_STATIC_LIBRARY=OFF
units.std: 17
Windows32bit:
vmImage: 'windows-2019'
Expand Down
113 changes: 57 additions & 56 deletions config/AddGoogletest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,34 @@
# Add make check, as well, which gives output on failed tests without having to set an
# environment variable.
#

include(extraMacros)
set(CMAKE_WARN_DEPRECATED
OFF
CACHE INTERNAL "" FORCE
)
set(gtest_force_shared_crt
ON
CACHE INTERNAL ""
)

set(BUILD_SHARED_LIBS
OFF
CACHE INTERNAL ""
)
set(HAVE_STD_REGEX
ON
CACHE INTERNAL ""
)

set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS
1
CACHE INTERNAL ""
)

if(NOT GTest_FOUND)

if(NOT UNITS_USE_EXTERNAL_GTEST AND NOT GTest_FOUND)

set(CMAKE_WARN_DEPRECATED
OFF
CACHE INTERNAL "" FORCE
)
set(gtest_force_shared_crt
ON
CACHE INTERNAL ""
)

set(BUILD_SHARED_LIBS
OFF
CACHE INTERNAL ""
)
set(HAVE_STD_REGEX
ON
CACHE INTERNAL ""
)

set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS
1
CACHE INTERNAL ""
)

add_subdirectory(
${CMAKE_SOURCE_DIR}/ThirdParty/googletest
${CMAKE_BINARY_DIR}/ThirdParty/googletest EXCLUDE_FROM_ALL
Expand All @@ -55,6 +58,36 @@ if(NOT GTest_FOUND)
gmock_main PUBLIC "-Wno-undef" "-Wno-c++17-attribute-extensions"
)
endif()

hide_variable(gmock_build_tests)
hide_variable(gtest_build_samples)
hide_variable(gtest_build_tests)
hide_variable(gtest_disable_pthreads)
hide_variable(gtest_hide_internal_symbols)
hide_variable(BUILD_GMOCK)
hide_variable(BUILD_GTEST)
hide_variable(INSTALL_GTEST)
hide_variable(GTEST_HAS_ABSL)

set_target_properties(gtest gtest_main gmock gmock_main PROPERTIES FOLDER "Extern")

if(MSVC)
# add_compile_options( /wd4459)
if(MSVC_VERSION GREATER_EQUAL 1900)
target_compile_definitions(
gtest PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
)
target_compile_definitions(
gtest_main PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
)
target_compile_definitions(
gmock PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
)
target_compile_definitions(
gmock_main PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
)
endif()
endif()
endif()

if(GOOGLE_TEST_INDIVIDUAL)
Expand Down Expand Up @@ -85,35 +118,3 @@ macro(add_gtest TESTNAME)
endif()

endmacro()

hide_variable(gmock_build_tests)
hide_variable(gtest_build_samples)
hide_variable(gtest_build_tests)
hide_variable(gtest_disable_pthreads)
hide_variable(gtest_hide_internal_symbols)
hide_variable(BUILD_GMOCK)
hide_variable(BUILD_GTEST)
hide_variable(INSTALL_GTEST)
hide_variable(GTEST_HAS_ABSL)

if(NOT GTest_FOUND)
set_target_properties(gtest gtest_main gmock gmock_main PROPERTIES FOLDER "Extern")
endif()

if(MSVC)
# add_compile_options( /wd4459)
if(MSVC_VERSION GREATER_EQUAL 1900)
target_compile_definitions(
gtest PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
)
target_compile_definitions(
gtest_main PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
)
target_compile_definitions(
gmock PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
)
target_compile_definitions(
gmock_main PUBLIC _SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING
)
endif()
endif()
Loading
Loading