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

Reorganize and Add to CMake Tests #4374

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12565,6 +12565,91 @@ jobs:
cat "$GITHUB_WORKSPACE/OpenDDS/${{ github.job }}_autobuild_workspace/latest.txt"
grep -q 'Failures: 0' "$GITHUB_WORKSPACE/OpenDDS/${{ github.job }}_autobuild_workspace/latest.txt"

build_cmake_m12:

runs-on: macos-12

steps:
- name: Checkout OpenDDS
uses: actions/checkout@v4
with:
path: OpenDDS
submodules: true
- name: Checkout MPC
uses: actions/checkout@v4
with:
repository: DOCGroup/MPC
path: MPC
- name: Checkout ACE/TAO
uses: actions/checkout@v4
with:
repository: DOCGroup/ACE_TAO
path: OpenDDS/build/ACE_TAO
- name: Install xerces
run: brew install xerces-c
- name: Configure
run: |
cd OpenDDS
cmake -B build \
-DCMAKE_UNITY_BUILD=TRUE \
-DBUILD_SHARED_LIBS=TRUE \
-DCMAKE_BUILD_TYPE=Debug \
-DOPENDDS_SECURITY=TRUE \
-DOPENDDS_ACE_TAO_SRC=$GITHUB_WORKSPACE/OpenDDS/build/ACE_TAO \
-DOPENDDS_MPC=$GITHUB_WORKSPACE/MPC \
-DOPENDDS_BUILD_TESTS=TRUE \
-DOPENDDS_CMAKE_VERBOSE=all
- uses: ammaraskar/gcc-problem-matcher@0.2.0
- name: Build
run: |
cd OpenDDS
cmake --build build -- -j $(getconf _NPROCESSORS_ONLN)
- name: Run Tests
run: |
cd OpenDDS/build
ctest

build_cmake_m12_stat:

runs-on: macos-12

steps:
- name: Checkout OpenDDS
uses: actions/checkout@v4
with:
path: OpenDDS
submodules: true
- name: Checkout MPC
uses: actions/checkout@v4
with:
repository: DOCGroup/MPC
path: MPC
- name: Checkout ACE/TAO
uses: actions/checkout@v4
with:
repository: DOCGroup/ACE_TAO
path: OpenDDS/build/ACE_TAO
- name: Configure
run: |
cd OpenDDS
cmake -B build \
-DCMAKE_UNITY_BUILD=TRUE \
-DBUILD_SHARED_LIBS=FALSE \
-DCMAKE_BUILD_TYPE=Debug \
-DOPENDDS_ACE_TAO_SRC=$GITHUB_WORKSPACE/OpenDDS/build/ACE_TAO \
-DOPENDDS_MPC=$GITHUB_WORKSPACE/MPC \
-DOPENDDS_BUILD_TESTS=TRUE \
-DOPENDDS_CMAKE_VERBOSE=all
- uses: ammaraskar/gcc-problem-matcher@0.2.0
- name: Build
run: |
cd OpenDDS
cmake --build build -- -j $(getconf _NPROCESSORS_ONLN)
- name: Run Tests
run: |
cd OpenDDS/build
ctest

build_u14_gcc4:

runs-on: ubuntu-22.04
Expand Down
48 changes: 3 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ if(NOT DEFINED OPENDDS_RAPIDJSON)
FetchContent_Populate(rapidjson)
set(OPENDDS_RAPIDJSON "${rapidjson_SOURCE_DIR}")
endif()
set(OPENDDS_INSTALL_RAPIDJSON TRUE)
endif()

if(NOT CMAKE_CROSSCOMPILING)
Expand Down Expand Up @@ -119,7 +120,7 @@ install(
DESTINATION "${cmake_dest}"
)
install(FILES VERSION.txt DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/dds/")
if(OPENDDS_RAPIDJSON)
if(OPENDDS_INSTALL_RAPIDJSON)
install(DIRECTORY "${OPENDDS_RAPIDJSON}/include/rapidjson"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
Expand All @@ -137,48 +138,5 @@ if(OPENDDS_BUILD_EXAMPLES OR OPENDDS_BUILD_TESTS)
add_subdirectory(DevGuideExamples/DCPS/Messenger)
endif()
if(OPENDDS_BUILD_TESTS)
find_package(GTest QUIET PATHS "${OPENDDS_GTEST}")
if(NOT GTest_FOUND)
set(gtestsm "${OPENDDS_SOURCE_DIR}/tests/googletest")
if(EXISTS "${gtestsm}/CMakeLists.txt")
message("GTest not found, using submodule")
set(fetch_args SOURCE_DIR "${gtestsm}")
else()
message("GTest not found, using clone")
set(fetch_args
GIT_REPOSITORY "https://github.com/OpenDDS/googletest"
GIT_TAG "v1.8.x"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
USES_TERMINAL_DOWNLOAD TRUE
)
endif()
FetchContent_Declare(googletest ${fetch_args})
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()
if(TARGET GTest::gtest)
get_target_property(google_test_bin_dir GTest::gtest BINARY_DIR)
set(_OPENDDS_GOOGLE_TEST_DIR "${google_test_bin_dir}" CACHE INTERNAL "")
elseif(TARGET gtest)
get_target_property(google_test_bin_dir gtest BINARY_DIR)
set(_OPENDDS_GOOGLE_TEST_DIR "${google_test_bin_dir}" CACHE INTERNAL "")
endif()

add_subdirectory(tests/cmake/ace_tao_only)
if(OPENDDS_OWNERSHIP_PROFILE)
add_subdirectory(tests/cmake/Messenger)
endif()
add_subdirectory(tests/cmake/idl_compiler_tests)
add_subdirectory(tests/DCPS/Compiler/optional)
add_subdirectory(tests/cmake/include_subdir)
add_subdirectory(tests/DCPS/Compiler/char_literals)
add_subdirectory(tests/DCPS/HelloWorld)
# TODO: This test always builds shared libraries and linker complains about
# ACE/TAO libs lacking -fPIC when ACE is static.
if(OPENDDS_OWNERSHIP_PROFILE AND NOT OPENDDS_STATIC)
add_subdirectory(tests/cmake/generated_global)
endif()
add_subdirectory(tests)
endif()
5 changes: 2 additions & 3 deletions DevGuideExamples/DCPS/Messenger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ add_executable(subscriber
target_link_libraries(subscriber ${opendds_libs})

# Testing
configure_file(run_test.pl . COPYONLY)
configure_file(rtps.ini . COPYONLY)
opendds_add_test(NAME info_repo COMMAND perl run_test.pl)
opendds_add_test(NAME rtps COMMAND perl run_test.pl --rtps)
opendds_add_test(NAME info_repo)
opendds_add_test(NAME rtps ARGS --rtps)
3 changes: 2 additions & 1 deletion cmake/OpenDDSConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ if(NOT TARGET OpenDDS::OpenDDS)
endif()
endif()

if(NOT TARGET OpenDDS::TestUtils AND DEFINED OPENDDS_SOURCE_DIR)
if(NOT TARGET OpenDDS::TestUtils AND DEFINED OPENDDS_SOURCE_DIR
AND IS_DIRECTORY "${OPENDDS_SOURCE_DIR}")
add_library(OpenDDS::TestUtils INTERFACE IMPORTED)
target_include_directories(OpenDDS::TestUtils INTERFACE "${OPENDDS_SOURCE_DIR}")
endif()
Expand Down
1 change: 1 addition & 0 deletions cmake/import_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ function(_opendds_import_group_targets group libs exes)
"IMPORTED_LINK_INTERFACE_LANGUAGES_${config}" "CXX"
"IMPORTED_LOCATION_${config}" "${imploc}"
)
_opendds_target_compile_features(${target} INTERFACE)
endif()
endmacro()

Expand Down
22 changes: 21 additions & 1 deletion cmake/init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ _opendds_feature(TAO_OPTIMIZE_COLLOCATED_INVOCATIONS ON MPC)

# Make Sure CMake can use the Paths
file(TO_CMAKE_PATH "${OPENDDS_ACE}" OPENDDS_ACE)
file(TO_CMAKE_PATH "${OPENDDS_MPC}" OPENDDS_MPC)
if(OPENDDS_MPC)
file(TO_CMAKE_PATH "${OPENDDS_MPC}" OPENDDS_MPC)
endif()
file(TO_CMAKE_PATH "${OPENDDS_TAO}" OPENDDS_TAO)

option(OPENDDS_CMAKE_VERBOSE "Print verbose output when loading the OpenDDS Config Package" OFF)
Expand Down Expand Up @@ -237,6 +239,22 @@ function(_opendds_path_list path_list_var)
set("${path_list_var}" "${path_list}" PARENT_SCOPE)
endfunction()

function(_opendds_msvc_bigobj target)
if(MSVC)
target_compile_options(${target} PRIVATE /bigobj)
endif()
endfunction()

function(_opendds_target_compile_features target scope)
if(NOT CMAKE_VERSION VERSION_LESS "3.11.0")
if(OPENDDS_ACE_VERSION VERSION_GREATER_EQUAL "7.1.0")
target_compile_features(${target} ${scope} cxx_std_14)
elseif(OPENDDS_ACE_VERSION VERSION_GREATER_EQUAL "7.0.0")
target_compile_features(${target} ${scope} cxx_std_11)
endif()
endif()
endfunction()

if(NOT DEFINED OPENDDS_INSTALL_LIB)
set(OPENDDS_INSTALL_LIB "lib")
endif()
Expand Down Expand Up @@ -302,6 +320,8 @@ _opendds_get_version(OPENDDS_TAO_VERSION TAO "${TAO_ROOT}")
message(STATUS "Using OpenDDS ${OPENDDS_VERSION} at ${DDS_ROOT}")
if(DEFINED OPENDDS_MPC)
message(STATUS "Using MPC at ${OPENDDS_MPC}")
else()
message(STATUS "MPC isn't defined")
endif()
message(STATUS "Using ACE ${OPENDDS_ACE_VERSION} at ${ACE_ROOT}")
message(STATUS "Using TAO ${OPENDDS_TAO_VERSION} at ${TAO_ROOT}")
Expand Down
6 changes: 4 additions & 2 deletions cmake/opendds_build_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function(_opendds_library target)
"${no_value_options}" "${single_value_options}" "${multi_value_options}" ${ARGN})

_opendds_alias(${target})
_opendds_target_compile_features(${target} PUBLIC)

# Put library in BINARY_DIR/lib
set_target_properties(${target} PROPERTIES
Expand All @@ -54,8 +55,8 @@ function(_opendds_library target)
message(FATAL_ERROR "Target ${target} has unexpected type ${target_type}")
endif()

if(MSVC AND arg_MSVC_BIGOBJ)
target_compile_options(${target} PRIVATE /bigobj)
if(arg_MSVC_BIGOBJ)
_opendds_msvc_bigobj(${target})
endif()

if(NOT arg_NO_INSTALL)
Expand All @@ -82,6 +83,7 @@ function(_opendds_executable target)
"${no_value_options}" "${single_value_options}" "${multi_value_options}" ${ARGN})

_opendds_alias(${target})
_opendds_target_compile_features(${target} PRIVATE)
set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${OPENDDS_BIN_DIR}")

if(NOT arg_NO_INSTALL)
Expand Down
14 changes: 9 additions & 5 deletions cmake/opendds_testing.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function(opendds_add_test)
set(no_value_options)
set(no_value_options ASSUME_RUN_TEST)
set(single_value_options NAME)
set(multi_value_options COMMAND ARGS EXTRA_LIB_DIRS)
cmake_parse_arguments(arg
Expand All @@ -12,7 +12,11 @@ function(opendds_add_test)
set(test_name "${test_name}_${arg_NAME}")
endif()
if(NOT arg_COMMAND)
set(arg_COMMAND ${PERL_EXECUTABLE} run_test.pl)
set(rt "run_test.pl")
if(NOT arg_ASSUME_RUN_TEST)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${rt}" . COPYONLY)
endif()
set(arg_COMMAND "${PERL_EXECUTABLE}" "${rt}")
if(CMAKE_CONFIGURATION_TYPES)
list(APPEND arg_COMMAND $<$<BOOL:$<CONFIG>>:-ExeSubDir> $<CONFIG>)
endif()
Expand All @@ -28,11 +32,11 @@ function(opendds_add_test)
set(env_var_name LD_LIBRARY_PATH)
endif()
_opendds_path_list(lib_dir_list "$ENV{${env_var_name}}" "${TAO_LIB_DIR}")
if(DEFINED _OPENDDS_GOOGLE_TEST_DIR)
_opendds_path_list(lib_dir_list APPEND "${_OPENDDS_GOOGLE_TEST_DIR}")
if(DEFINED _OPENDDS_GOOGLETEST_DIR)
_opendds_path_list(lib_dir_list APPEND "${_OPENDDS_GOOGLETEST_DIR}")
if(CMAKE_CONFIGURATION_TYPES)
_opendds_path_list(lib_dir_list APPEND
"${_OPENDDS_GOOGLE_TEST_DIR}$<$<BOOL:$<CONFIG>>:/$<CONFIG>>")
"${_OPENDDS_GOOGLETEST_DIR}$<$<BOOL:$<CONFIG>>:/$<CONFIG>>")
endif()
endif()
foreach(lib_dir "${OPENDDS_LIB_DIR}" ${arg_EXTRA_LIB_DIRS})
Expand Down
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -2724,6 +2724,7 @@ sub write_cmake_file {
my $fh = shift();
my $buildEnv = shift();

print_cmake_config($fh, 'SOURCE_DIR', Cwd::abs_path($FindBin::RealBin));
print_cmake_config($fh, 'MPC', Cwd::abs_path($buildEnv->{'MPC_ROOT'}));
print_cmake_config($fh, 'ACE', Cwd::abs_path($buildEnv->{'ACE_ROOT'}));
print_cmake_config($fh, 'TAO', Cwd::abs_path($buildEnv->{'TAO_ROOT'}));
Expand Down
49 changes: 49 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
cmake_minimum_required(VERSION 3.3...3.27)
project(opendds_tests)
enable_testing()

find_package(OpenDDS REQUIRED)

find_package(GTest QUIET PATHS "${OPENDDS_GTEST}")
if(NOT GTest_FOUND)
set(gtestsm "${CMAKE_CURRENT_LIST_DIR}/googletest")
if(EXISTS "${gtestsm}/CMakeLists.txt")
message("GTest not found, using submodule")
set(fetch_args SOURCE_DIR "${gtestsm}")
else()
message("GTest not found, using clone")
set(fetch_args
GIT_REPOSITORY "https://github.com/OpenDDS/googletest"
GIT_TAG "v1.8.x"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
USES_TERMINAL_DOWNLOAD TRUE
)
endif()
FetchContent_Declare(googletest ${fetch_args})
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()

if(TARGET GTest::gtest)
set(_opendds_googletest GTest::gtest CACHE INTERNAL "" FORCE)
elseif(TARGET gtest)
set(_opendds_googletest gtest CACHE INTERNAL "" FORCE)
endif()

add_library(OpenDDS_GoogleTest INTERFACE)
target_link_libraries(OpenDDS_GoogleTest INTERFACE ${_opendds_googletest})
get_target_property(_opendds_googletest_type ${_opendds_googletest} TYPE)
if(_opendds_googletest_type STREQUAL "SHARED_LIBRARY")
target_compile_definitions(OpenDDS_GoogleTest INTERFACE GTEST_LINKED_AS_SHARED_LIBRARY=1)
endif()

get_target_property(_opendds_googletest_bin_dir ${_opendds_googletest} BINARY_DIR)
set(_OPENDDS_GOOGLETEST_DIR "${_opendds_googletest_bin_dir}" CACHE INTERNAL "")

add_subdirectory(cmake)
add_subdirectory(DCPS)
add_subdirectory(unit-tests)
11 changes: 11 additions & 0 deletions tests/DCPS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.3...3.27)
project(opendds_tests_dcps)
enable_testing()

find_package(OpenDDS REQUIRED)

add_subdirectory(Compiler)
add_subdirectory(HelloWorld)
if(OPENDDS_OWNERSHIP_PROFILE)
add_subdirectory(Messenger)
endif()
9 changes: 9 additions & 0 deletions tests/DCPS/Compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.3...3.27)
project(opendds_tests_dcps_compiler)
enable_testing()

find_package(OpenDDS REQUIRED)

add_subdirectory(char_literals)
add_subdirectory(optional)
add_subdirectory(xcdr)