Skip to content

Commit

Permalink
test(cmake): add test for installable with C++17
Browse files Browse the repository at this point in the history
  • Loading branch information
XuehaiPan committed Oct 2, 2024
1 parent 6d59008 commit d286de2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
- name: clang-tidy
run: |
make clang-tidy
make clang-tidy CMAKE_CXX_STANDARD=17
- name: addlicense
run: |
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ jobs:
python -m pip install -r tests/requirements.txt
fi
- name: Test installable with C++17
shell: bash
run: |
CMAKE_CXX_STANDARD=17 python -m pip install -vvv --editable .
python -X dev -W 'always' -W 'error' -c 'import optree'
python -m pip uninstall -y optree
- name: Install OpTree
run: |
python -m pip install -vvv --editable '.[test]'
Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

set(CMAKE_CXX_STANDARD 20) # for likely/unlikely attributes
if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT "$ENV{CMAKE_CXX_STANDARD}" STREQUAL "")
set(CMAKE_CXX_STANDARD "$ENV{CMAKE_CXX_STANDARD}")
endif()
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20) # for likely/unlikely attributes
endif()
if (CMAKE_CXX_STANDARD VERSION_LESS 17)
message(FATAL_ERROR "C++17 or higher is required")
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "Use C++ standard: C++${CMAKE_CXX_STANDARD}")

set(CMAKE_POSITION_INDEPENDENT_CODE ON) # -fPIC
set(CMAKE_CXX_VISIBILITY_PRESET hidden) # -fvisibility=hidden
Expand Down
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ GOBIN ?= $(GOPATH)/bin
PATH := $(PATH):$(GOBIN)
PYTHON ?= $(shell command -v python3 || command -v python)
PYTESTOPTS ?=
OPTREE_CXX_WERROR ?= ON
CMAKE_CXX_STANDARD ?= 20
OPTREE_CXX_WERROR ?= ON

.PHONY: default
default: install
Expand All @@ -27,7 +28,8 @@ install-editable install-e:
$(PYTHON) -m pip install --upgrade pip
$(PYTHON) -m pip install --upgrade setuptools wheel
$(PYTHON) -m pip install --upgrade pybind11 cmake
OPTREE_CXX_WERROR="$(OPTREE_CXX_WERROR)" $(PYTHON) -m pip install -vvv --no-build-isolation --editable .
OPTREE_CXX_WERROR="$(OPTREE_CXX_WERROR)" CMAKE_CXX_STANDARD="$(CMAKE_CXX_STANDARD)" \
$(PYTHON) -m pip install -vvv --no-build-isolation --editable .

.PHONY: uninstall
uninstall:
Expand Down Expand Up @@ -198,6 +200,7 @@ cmake-configure: cmake-install
cmake --version
cmake -S . -B cmake-build-debug \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD="$(CMAKE_CXX_STANDARD)" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DPython_EXECUTABLE="$(PYTHON)" \
-DOPTREE_CXX_WERROR="$(OPTREE_CXX_WERROR)"
Expand Down Expand Up @@ -225,7 +228,8 @@ clang-tidy: clang-tidy-install cmake-configure

.PHONY: addlicense
addlicense: addlicense-install
addlicense -c $(COPYRIGHT) -ignore tests/coverage.xml -l apache -y 2022-$(shell date +"%Y") -check $(SOURCE_FOLDERS)
addlicense -c $(COPYRIGHT) -l apache -y 2022-$(shell date +"%Y") \
-ignore tests/coverage.xml -check $(SOURCE_FOLDERS)

.PHONY: docstyle
docstyle: docs-install
Expand Down Expand Up @@ -256,7 +260,8 @@ format: py-format-install ruff-install clang-format-install addlicense-install
$(PYTHON) -m black $(PYTHON_FILES)
$(PYTHON) -m ruff check --fix --exit-zero .
$(CLANG_FORMAT) -style=file -i $(CXX_FILES)
addlicense -c $(COPYRIGHT) -ignore tests/coverage.xml -l apache -y 2022-$(shell date +"%Y") $(SOURCE_FOLDERS)
addlicense -c $(COPYRIGHT) -l apache -y 2022-$(shell date +"%Y") \
-ignore tests/coverage.xml $(SOURCE_FOLDERS)

.PHONY: clean-py
clean-py:
Expand Down

0 comments on commit d286de2

Please sign in to comment.