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

GHI #18 Fix and polish CMake #19

Merged
merged 18 commits into from
Oct 21, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
GHI #18 Disable UTs unless PATOMIC_SOURCE_DIR set
- expected by `patomic-test`, but always set by `patomic` if tests are enabled
- if not set, UTs are disabled since we don't have access to required source files
doodspav committed Oct 21, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
doodspav doodspav
commit 6b0eb135a4c4c6708f7bef414679e79f148ebddb
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -98,7 +98,12 @@ endif()
# ---- Setup Tests ----

if(PATOMIC_BUILD_TESTING)

# tell unit tests where our source files are
set(PATOMIC_SOURCE_DIR "${PROJECT_SOURCE_DIR}")

# need to enable testing in case BUILD_TESTING is disabled
enable_testing()
add_subdirectory(test)

endif()
10 changes: 8 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -31,9 +31,15 @@ include(GoogleTest)

add_custom_target(patomic_test)

# add all test subdirectories
# add BTs unconditionally
add_subdirectory(bt)
add_subdirectory(ut)

# only add UTs if patomic source files are available
if(PATOMIC_SOURCE_DIR)
add_subdirectory(ut)
else()
message(STATUS "Variable 'PATOMIC_SOURCE_DIR' empty or not set; skipping unit tests")
endif()


# ---- Support Packaging Library ----
2 changes: 1 addition & 1 deletion test/cmake/CreateTest.cmake
Original file line number Diff line number Diff line change
@@ -272,7 +272,7 @@ function(create_ut)
UT ${ARG_NAME}
SOURCE ${ARG_SOURCE}
INCLUDE
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src/include>"
"$<BUILD_INTERFACE:${PATOMIC_SOURCE_DIR}/src/include>"
${ARG_INCLUDE}
)

31 changes: 30 additions & 1 deletion test/cmake/OptionVariables.cmake
Original file line number Diff line number Diff line change
@@ -5,11 +5,16 @@
# |======================================|==============|============|
# | CMAKE_INSTALL_TESTDIR (unofficial) | Always | share/test |
# |--------------------------------------|--------------|------------|
# | PATOMIC_SOURCE_DIR | Always | "" |
# | PATOMIC_CREATE_TEST_TARGETS_MATCHING | Always | ^(.*)$ |
# | PATOMIC_WINDOWS_SET_CTEST_PATH_ENV | Always | ON |
# | PATOMIC_WINDOWS_CREATE_PATH_ENV_FILE | Always | OFF |
# --------------------------------------------------------------------

# Note:
# PATOMIC_SOURCE_DIR is set by patomic and available through there if
# patomic-test is built as a subproject.


# ---- Test Install Directory ----

@@ -20,10 +25,33 @@
# It's not prefixed with PATOMIC_ because it's ok for it to be shared and
# overridden by parent projects.
# Note: this is not an official CMake variable
# The variable type is STRING rather than PATH, because otherwise passing
# -DCMAKE_INSTALL_TESTDIR=share/test on the command line would expand to an
# absolute path with the base being the current CMake directory, leading to
# unexpected errors.
set(
CMAKE_INSTALL_TESTDIR "share/test"
CACHE PATH "(unofficial) Default test install location"
CACHE STRING "(unofficial) Default test install location"
)


# ---- Library Source Directory

# Unit tests need access to the private header files not available from linking
# against the patomic::patomic target.
# This variable can be set to let unit tests know where to find these files.
# When building this as a subproject of patomic (as you would by just building
# patomic normally with tests enabled), this variable is set automatically.
# If this variable is empty or not set, no unit tests will be built.
# The variable type is STRING rather than PATH, because otherwise passing
# -PATOMIC_SOURCE_DIR=relative/patomic on the command line would expand to an
# absolute path with the base being the current CMake directory, leading to
# unexpected errors.
set(
PATOMIC_SOURCE_DIR ""
CACHE STRING "Path to source files of patomic::patomic target for unit tests"
)
mark_as_advanced(PATOMIC_SOURCE_DIR)


# ---- Test Build Selection ----
@@ -36,6 +64,7 @@ set(
PATOMIC_CREATE_TEST_TARGETS_MATCHING "^(.*)$"
CACHE STRING "Only test targets matching regex are created and registered with CTest"
)
mark_as_advanced(PATOMIC_CREATE_TEST_TARGETS_MATCHING)


# ---- Windows Tests Path ----