Skip to content

Commit d708393

Browse files
authored
Cmake updates (#224)
* some minor cmake tweaks * updated pybind dependency, a bit more monkeying with cmake and actions * still messing with actions * still messing with actions * skipping image processing pytest for now as the runners don't like it for some reason
1 parent ceafb84 commit d708393

39 files changed

+2746
-886
lines changed

.github/actions/BuildTestInstall/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ runs:
4040
working-directory: ${{github.workspace}}/test/pytest
4141
run: pytest
4242

43-
- name: gtest
43+
- name: ctest
4444
shell: ${{inputs.shell}}
4545
working-directory: ${{github.workspace}}/build
46-
run: ctest
46+
run: ctest -R BinaryLoggerTestSuite -R LoggerTestSuite
4747

4848
- name: Install
4949
shell: ${{inputs.shell}}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ __pycache__/
2222
*.so
2323

2424
*.tar
25+
Testing/

CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ project("NumCpp"
1313
LANGUAGES CXX
1414
)
1515

16-
enable_testing()
17-
1816
message(STATUS "Building ${PROJECT_NAME} version ${VERSION_STRING}")
1917

2018
if(NOT CMAKE_BUILD_TYPE)
@@ -30,10 +28,12 @@ message(STATUS "Compiling with C++ standard: ${CMAKE_CXX_STANDARD}")
3028
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "") # works
3129

3230
option(BUILD_ALL "Build All targets" OFF)
31+
option(BUILD_ALL_NON_PYTHON "Build All targets except the python bindings for pytest" OFF)
3332
option(BUILD_DOCS "Build the doxygen documentation" OFF)
3433
option(BUILD_TESTS "Build the unit tests" OFF)
3534
option(BUILD_MULTIPLE_TEST "Build the multiple translation unit test" OFF)
3635
option(BUILD_CPPCHECK_TEST "Build the cppcheck test" OFF)
36+
option(BUILD_GTEST "Build the gtest tests" OFF)
3737
option(BUILD_EXAMPLE_ALL "Build all of the examples" OFF)
3838
option(BUILD_EXAMPLE_GAUSS_NEWTON_NLLS "Build the Gauss-Newton NLLS example" OFF)
3939
option(BUILD_EXAMPLE_INTERFACE_WITH_EIGEN "Build the Interface with Eigen example" OFF)
@@ -44,10 +44,15 @@ option(NUMCPP_NO_USE_BOOST "Don't use the boost libraries" OFF)
4444
option(NUMCPP_USE_MULTITHREAD "Enable multithreading" OFF)
4545

4646
if(BUILD_ALL)
47-
set(BUILD_DOCS ON)
47+
set(BUILD_ALL_NON_PYTHON ON)
4848
set(BUILD_TESTS ON)
49+
endif()
50+
51+
if(BUILD_ALL_NON_PYTHON)
52+
set(BUILD_DOCS ON)
4953
set(BUILD_MULTIPLE_TEST ON)
5054
set(BUILD_CPPCHECK_TEST ON)
55+
set(BUILD_GTEST ON)
5156
set(BUILD_EXAMPLE_ALL ON)
5257
endif()
5358

@@ -134,6 +139,7 @@ get_filename_component(NUMCPP_INCLUDES ./include ABSOLUTE)
134139
set(OUTPUT_BINARY_DIR ${PROJECT_SOURCE_DIR}/bin/$<0:>)
135140

136141
if (BUILD_TESTS OR BUILD_MULTIPLE_TEST OR BUILD_CPPCHECK_TEST)
142+
enable_testing()
137143
add_subdirectory(test)
138144
endif()
139145

test/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ if(BUILD_CPPCHECK_TEST)
1313
message(STATUS "Configuring CPPCheck Test")
1414
add_subdirectory(cppcheck)
1515
endif()
16+
17+
if(BUILD_GTEST)
18+
message(STATUS "Configuring GTest")
19+
add_subdirectory(gtest)
20+
endif()

test/cppcheck/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ add_executable(${TARGET_NAME}
44
CppCheck.cpp
55
)
66

7+
set_target_properties(${TARGET_NAME}
8+
PROPERTIES
9+
RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_BINARY_DIR}
10+
)
11+
712
target_include_directories(${TARGET_NAME} PRIVATE
813
${NUMCPP_INCLUDES}
914
)
1015

1116
target_link_libraries(${TARGET_NAME} PRIVATE
1217
${ALL_INTERFACE_TARGET}
1318
)
19+
20+
add_test(NAME ${TARGET_NAME}
21+
COMMAND ${TARGET_NAME}
22+
)

test/cppcheck/CppCheck.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include "NumCpp.hpp"
22

3+
#include <iostream>
4+
35
int main()
46
{
7+
std::cout << "Dummy file to include all headers for CppCheck\n";
8+
59
return 0;
610
}

test/gtest/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11

2-
set(TARGET_NAME NumCpp_tests)
2+
set(TARGET_NAME LoggerTests)
33

44
add_executable(${TARGET_NAME}
55
test_BinaryLogger.cpp
66
test_Logger.cpp
77
)
88

9+
set_target_properties(${TARGET_NAME}
10+
PROPERTIES
11+
RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_BINARY_DIR}
12+
)
13+
914
target_include_directories(${TARGET_NAME} PRIVATE
1015
${NUMCPP_INCLUDES}
1116
)
@@ -18,4 +23,4 @@ target_link_libraries(${TARGET_NAME} PRIVATE
1823
)
1924

2025
include(GoogleTest)
21-
gtest_discover_tests(${TARGET_NAME})
26+
gtest_discover_tests(${TARGET_NAME})

test/multiple/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ target_include_directories(${TARGET_NAME} PRIVATE
1818
target_link_libraries(${TARGET_NAME} PRIVATE
1919
${ALL_INTERFACE_TARGET}
2020
)
21+
22+
add_test(NAME ${TARGET_NAME}
23+
COMMAND ${TARGET_NAME}
24+
)

test/pytest/src/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,19 @@ find_package(Python 3.11 REQUIRED
5353
Development.Module
5454
)
5555

56+
if(UNIX)
57+
execute_process(
58+
COMMAND
59+
python3-config --ldflags
60+
OUTPUT_VARIABLE
61+
PYTHON_LD_FLAGS
62+
OUTPUT_STRIP_TRAILING_WHITESPACE
63+
)
64+
endif()
65+
5666
target_link_libraries(${TARGET_NAME} PRIVATE
5767
Python::Module
68+
${PYTHON_LD_FLAGS}
5869
${ALL_INTERFACE_TARGET}
5970
)
6071

test/pytest/src/pybind11/pybind11/buffer_info.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,22 @@ struct buffer_info {
102102
template <typename T>
103103
buffer_info(const T *ptr, ssize_t size, bool readonly = true)
104104
: buffer_info(
105-
const_cast<T *>(ptr), sizeof(T), format_descriptor<T>::format(), size, readonly) {}
105+
const_cast<T *>(ptr), sizeof(T), format_descriptor<T>::format(), size, readonly) {}
106106

107107
explicit buffer_info(Py_buffer *view, bool ownview = true)
108108
: buffer_info(
109-
view->buf,
110-
view->itemsize,
111-
view->format,
112-
view->ndim,
113-
{view->shape, view->shape + view->ndim},
114-
/* Though buffer::request() requests PyBUF_STRIDES, ctypes objects
115-
* ignore this flag and return a view with NULL strides.
116-
* When strides are NULL, build them manually. */
117-
view->strides
118-
? std::vector<ssize_t>(view->strides, view->strides + view->ndim)
119-
: detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize),
120-
(view->readonly != 0)) {
109+
view->buf,
110+
view->itemsize,
111+
view->format,
112+
view->ndim,
113+
{view->shape, view->shape + view->ndim},
114+
/* Though buffer::request() requests PyBUF_STRIDES, ctypes objects
115+
* ignore this flag and return a view with NULL strides.
116+
* When strides are NULL, build them manually. */
117+
view->strides
118+
? std::vector<ssize_t>(view->strides, view->strides + view->ndim)
119+
: detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize),
120+
(view->readonly != 0)) {
121121
// NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
122122
this->m_view = view;
123123
// NOLINTNEXTLINE(cppcoreguidelines-prefer-member-initializer)
@@ -176,7 +176,7 @@ struct buffer_info {
176176
detail::any_container<ssize_t> &&strides_in,
177177
bool readonly)
178178
: buffer_info(
179-
ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) {}
179+
ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) {}
180180

181181
Py_buffer *m_view = nullptr;
182182
bool ownview = false;

0 commit comments

Comments
 (0)