Skip to content

Commit

Permalink
Allow Compiling with CMake and C++03
Browse files Browse the repository at this point in the history
This continues the work started in
OpenDDS#4481 and tries to correctly
handle C++ standards in all CMake support. Previously the CMake support
was agnostic towards C++ standards, but this meant that building with
CMake didn't have a way of differentiating C++ standards. Now we can
detect C++ standard support and should be able to build ACE/TAO
accordingly.

Also:
- Added `OPENDDS_CXX_STD_YEAR` CMake variable for easy checking of C++
  standard support.
- Passing C++ standard to the ACE/TAO MPC builds and
  `CMAKE_CXX_COMPILER` for gnuace builds.
- Removed need for `cmake/detect_ace.pl`
- Some of the changes originally in OpenDDS#4374
  - MPC location message will now say when it wasn't set.
  - Split adding of tests between different directories.
  • Loading branch information
iguessthislldo committed Mar 27, 2024
1 parent 3c813b5 commit 16e6f29
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 308 deletions.
47 changes: 2 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ if(OPENDDS_XERCES3)
endif()
if(OPENDDS_SECURITY)
add_subdirectory(dds/DCPS/security)
if(OPENDDS_BUILT_IN_TOPICS)
if(OPENDDS_BUILT_IN_TOPICS AND NOT OPENDDS_CXX_STD_YEAR LESS 2011)
add_subdirectory(tools/dds/rtpsrelaylib)
add_subdirectory(tools/rtpsrelay)
endif()
Expand Down Expand Up @@ -158,48 +158,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()
12 changes: 11 additions & 1 deletion cmake/build_ace_tao.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ find_package(Perl REQUIRED)
if(OPENDDS_STATIC)
list(APPEND _OPENDDS_CONFIGURE_ACE_TAO_ARGS --static=1)
endif()
list(APPEND _OPENDDS_CONFIGURE_ACE_TAO_ARGS
--compiler "${CMAKE_CXX_COMPILER}"
)
execute_process(
COMMAND
"${PERL_EXECUTABLE}" "${_OPENDDS_CMAKE_DIR}/configure_ace_tao.pl"
Expand All @@ -35,6 +38,12 @@ execute_process(
COMMAND_ERROR_IS_FATAL ANY
)

# Get the C++ standard OpenDDS is going to be built with. We are going to force
# the ACE/TAO build to use the same standard.
set(opendds_idl_std "$<TARGET_PROPERTY:opendds_idl,CXX_STANDARD>")
set(dcps_std "$<TARGET_PROPERTY:OpenDDS_Dcps,CXX_STANDARD>")
set(std "$<IF:$<TARGET_EXISTS:OpenDDS_Dcps>,${dcps_std},${opendds_idl_std}>")

if(_OPENDDS_MPC_TYPE STREQUAL gnuace)
execute_process(
COMMAND
Expand Down Expand Up @@ -78,7 +87,7 @@ if(_OPENDDS_MPC_TYPE STREQUAL gnuace)
SOURCE_DIR "${OPENDDS_ACE_TAO_SRC}"
CONFIGURE_COMMAND "${CMAKE_COMMAND}" -E echo "Already configured"
BUILD_IN_SOURCE TRUE
BUILD_COMMAND ${make_cmd}
BUILD_COMMAND ${make_cmd} "$<IF:$<BOOL:${std}>,opendds_cmake_std=-std=c++${std},>"
BUILD_BYPRODUCTS ${byproducts}
USES_TERMINAL_BUILD TRUE # Needed for Ninja to show the ACE/TAO build
INSTALL_COMMAND "${CMAKE_COMMAND}" -E echo "No install step"
Expand Down Expand Up @@ -131,6 +140,7 @@ elseif(_OPENDDS_MPC_TYPE MATCHES "^vs")
"${CMAKE_COMMAND}" -E env "ACE_ROOT=${OPENDDS_ACE}" "TAO_ROOT=${OPENDDS_TAO}"
MSBuild "${sln}"
"-property:Configuration=$<CONFIG>,Platform=${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}"
"$<IF:$<BOOL:${std}>,-property:LanguageStandard=stdcpp${std},>"
"-maxcpucount"
BUILD_BYPRODUCTS ${byproducts}
USES_TERMINAL_BUILD TRUE # Needed for Ninja to show the ACE/TAO build
Expand Down
7 changes: 7 additions & 0 deletions cmake/configure_ace_tao.pl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
workspace-file
platform-macros-file
static
compiler
/;
my %is_value_required = map {$_ => 1} @required_values;
my %values = ();
Expand Down Expand Up @@ -100,6 +101,12 @@ sub read_file {
my $platform_macros_path = "$values{ace}/include/makeinclude/platform_macros.GNU";
open(my $platform_macros_file, '>', $platform_macros_path)
or die("Failed to open $platform_macros_path: $!");
if ($values{compiler}) {
for my $var ('CC', 'CXX', 'LD') {
print $platform_macros_file ("$var = $values{compiler}\n");
}
}
print $platform_macros_file ("CCFLAGS += \$(opendds_cmake_std)\n");
if ($values{'macro-line'}) {
for my $line (@{$values{'macro-line'}}) {
print $platform_macros_file ("$line\n");
Expand Down
4 changes: 4 additions & 0 deletions cmake/cplusplus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#if __cplusplus < OPENDDS_TEST_CPLUSPLUS
# error "Less then requested value"
#endif
int main() {}
140 changes: 0 additions & 140 deletions cmake/detect_ace.pl

This file was deleted.

5 changes: 1 addition & 4 deletions cmake/import_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ function(_opendds_import_group_targets group libs exes)

if(NOT TARGET ${target} AND ${var_prefix}_LIBRARY_FOUND)
add_library(${target} ${OPENDDS_LIBRARY_TYPE} IMPORTED GLOBAL)
_opendds_cxx_std(${target} INTERFACE)
set_target_properties(${target}
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${include_dirs}"
Expand All @@ -368,10 +369,6 @@ function(_opendds_import_group_targets group libs exes)
INTERFACE_COMPILE_OPTIONS "${${var_prefix}_COMPILE_OPTIONS}"
)

if(NOT CMAKE_VERSION VERSION_LESS "3.11.0" AND OPENDDS_CXX_STD)
target_compile_features(${target} INTERFACE "cxx_std_${OPENDDS_CXX_STD}")
endif()

set(mpc_ext_proj_var "${group_prefix}_MPC_EXTERNAL_PROJECT")
if(DEFINED "${mpc_ext_proj_var}")
add_dependencies(${target} "${${mpc_ext_proj_var}}")
Expand Down

0 comments on commit 16e6f29

Please sign in to comment.