Skip to content
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
12 changes: 12 additions & 0 deletions cmake/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ if(TARGET test_bitcoin)

add_all_test_targets()
endif()

if(TARGET unitester)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why are these defined here rather than inline with the build rules?

Specifically here, why not do the add_test in src/univalue/CMakeLists.txt ?

I don't have any objection, I just keep forgetting to ask.

Copy link
Copy Markdown
Owner Author

@hebasto hebasto Feb 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ctest executable looks for tests in the current directory, which can be specified explicitly using the --test-dir option in CTest >=3.20. When using the add_test command in CMake, a new test is placed into the build tree with the same relative path as the location of the file, which executes the command, in the source tree. This behavior is consistent with how the add_executable and add_library commands work.

Therefore, the purpose of the cmake/tests.cmake file is to collect all add_test commands, ensuring that all tests are discoverable by ctest within a single directory.

EDIT. Please ignore this comment.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theuni

My previous comment is not correct. It was based on the buggy behavior that has been fixed in bfe7c4d.

Please see #275.

add_test(NAME univalue_test
COMMAND unitester
)
endif()

if(TARGET object)
add_test(NAME univalue_object_test
COMMAND object
)
endif()
24 changes: 20 additions & 4 deletions src/univalue/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
# Copyright (c) 2023 The Bitcoin Core developers
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
# file COPYING or https://opensource.org/license/mit/.

add_library(univalue STATIC EXCLUDE_FROM_ALL
lib/univalue.cpp
lib/univalue_get.cpp
lib/univalue_read.cpp
lib/univalue_write.cpp
)

target_include_directories(univalue
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

target_link_libraries(univalue PRIVATE core_interface)

add_executable(unitester test/unitester.cpp)
target_compile_definitions(unitester
PRIVATE
JSON_TEST_SRC=\"${CMAKE_CURRENT_SOURCE_DIR}/test\"
)
target_link_libraries(unitester
PRIVATE
core_interface
univalue
)

add_executable(object test/object.cpp)
target_link_libraries(object
PRIVATE
core_interface
univalue
)