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

Add CMakeLists for C++ tests #123

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,21 @@ information on using pull requests.

This project follows
[Google's Open Source Community Guidelines](https://opensource.google/conduct/).

## Testing

To test your changes, you will need to install abseil:
```
cd ml_dtypes/test
git clone https://github.com/abseil/abseil-cpp.git
cd ../../third_party
ln -s ../ml_dtypes/tests/abseil-cpp/absl
```

Run pytest and cmake test as follows:
```
pip install -e .
pytest .
cmake -B build ml_dtypes/tests
cmake --build build -- all test
```
42 changes: 42 additions & 0 deletions ml_dtypes/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.14)
project(my_project)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(GOOGLETEST_DOWNLOAD_URL https://github.com/google/googletest/archive/refs/tags/v1.12.0.zip)

include(FetchContent)
FetchContent_Declare(
googletest
URL ${GOOGLETEST_DOWNLOAD_URL}
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

set(ABSL_PROPAGATE_CXX_STD ON)
set(ABSL_GOOGLETEST_DOWNLOAD_URL ${GOOGLETEST_DOWNLOAD_URL})
add_subdirectory(abseil-cpp)

enable_testing()

add_executable(
float8_test
float8_test.cc
)
target_include_directories(float8_test PUBLIC
..
../..
../../third_party/eigen
)

target_link_libraries(
float8_test
GTest::gtest_main
GTest::gmock_main
absl::strings
)

include(GoogleTest)
gtest_discover_tests(float8_test)