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 accordingly.

Also:
- Added `OPENDDS_CXX_STD_YEAR` CMake variable for easy checking of C++
  standard support.
- In addition to passing `CMAKE_CXX_STANDARD` to the ACE/TAO MPC build,
  it will also now pass `CMAKE_CXX_COMPILER`.
- 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 Feb 23, 2024
1 parent a1631e4 commit 9b522e3
Show file tree
Hide file tree
Showing 12 changed files with 334 additions and 298 deletions.
47 changes: 2 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,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 @@ -137,48 +137,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()
4 changes: 4 additions & 0 deletions cmake/build_ace_tao.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ 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}"
--std "${OPENDDS_CXX_STD}"
)
execute_process(
COMMAND
"${PERL_EXECUTABLE}" "${_OPENDDS_CMAKE_DIR}/configure_ace_tao.pl"
Expand Down
10 changes: 10 additions & 0 deletions cmake/configure_ace_tao.pl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
workspace-file
platform-macros-file
static
compiler
std
/;
my %is_value_required = map {$_ => 1} @required_values;
my %values = ();
Expand Down Expand Up @@ -100,6 +102,14 @@ 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");
}
}
if ($values{std}) {
print $platform_macros_file ("CCFLAGS += -std=c++$values{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 @@ -352,6 +352,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 @@ -360,10 +361,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 9b522e3

Please sign in to comment.