Skip to content

Commit

Permalink
Set Minimum C++ Standard on CMake Targets
Browse files Browse the repository at this point in the history
  • Loading branch information
iguessthislldo committed Feb 20, 2024
1 parent 9495d63 commit a1631e4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmake/import_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ 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
9 changes: 9 additions & 0 deletions cmake/init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ if(NOT DEFINED ACE_ROOT)
set(ACE_BIN_DIR "${ACE_ROOT}/bin")
endif()
_opendds_get_version(OPENDDS_ACE_VERSION ACE "${ACE_ROOT}")
if(NOT DEFINED OPENDDS_CXX_STD)
if(NOT OPENDDS_ACE_VERSION VERSION_LESS "7.0.0")
set(OPENDDS_CXX_STD 14)
elseif(OPENDDS_CXX11)
set(OPENDDS_CXX_STD 11)
else()
set(OPENDDS_CXX_STD 98)
endif()
endif()

if(NOT DEFINED TAO_ROOT)
if(OPENDDS_USE_PREFIX_PATH)
Expand Down
8 changes: 8 additions & 0 deletions cmake/opendds_build_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ function(_opendds_library target)

_opendds_alias(${target})

if(OPENDDS_CXX_STD)
target_compile_features(${target} PUBLIC "cxx_std_${OPENDDS_CXX_STD}")
endif()

# Put library in BINARY_DIR/lib
set_target_properties(${target} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${OPENDDS_LIB_DIR}"
Expand Down Expand Up @@ -84,6 +88,10 @@ function(_opendds_executable target)
_opendds_alias(${target})
set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${OPENDDS_BIN_DIR}")

if(OPENDDS_CXX_STD)
target_compile_features(${target} PRIVATE "cxx_std_${OPENDDS_CXX_STD}")
endif()

if(NOT arg_NO_INSTALL)
install(TARGETS ${target}
EXPORT opendds_targets
Expand Down
10 changes: 10 additions & 0 deletions docs/devguide/building/cmake.rst
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,16 @@ Features
Default depends on the compiler being used.
Has no effect when building OpenDDS using CMake.

.. cmake:var:: OPENDDS_CXX_STD
.. versionadded:: 3.28

If defined, then this value is prefixed with ``cxx_std_`` and passed to `target_compile_features <https://cmake.org/cmake/help/latest/command/target_compile_features.html>`__ for all targets.
The valid values are the standards in `CMAKE_CXX_KNOWN_FEATURES <https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#high-level-meta-features-indicating-c-standard-support>`__ without the leading ``cxx_std_``.
This is the minimum C++ standard required to use the ACE, TAO, and OpenDDS libraries.
When building OpenDDS using CMake, it's also the minimum C++ standard used to build OpenDDS.
The default depends on the version of ACE being used.

.. cmake:var:: OPENDDS_DEBUG
:no-contents-entry:

Expand Down
2 changes: 1 addition & 1 deletion docs/devguide/building/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ A few things to note:

- Native-built host tools, like :term:`opendds_idl`, have to be configured and built separately and provided to the target build using :cmake:var:`OPENDDS_HOST_TOOLS`.
- The host tools will build its own ACE/TAO for the host system, but this can be overridden using :cmake:var:`OPENDDS_ACE` on the host build and :cmake:var:`OPENDDS_ACE_TAO_HOST_TOOLS` on the target build.
- If the target platform isn't automatically supported, then ACE/TAO will have to be :ref:`built serperatly <cmake-ace-tao-manual>`.
- If the target platform isn't automatically supported, then ACE/TAO will have to be :ref:`built separately <cmake-ace-tao-manual>`.

Android
^^^^^^^
Expand Down
7 changes: 7 additions & 0 deletions docs/news.d/cmake-cxx-std.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. news-prs: 4481
.. news-start-section: Fixes
.. news-start-section: Building with CMake
- Fixed :ghissue:`building with CMake and Apple Clang on macOS <4478>` without setting ``-DCMAKE_CXX_STANDARD=14`` or using ACE 6 by setting :cmake:var:`OPENDDS_CXX_STD` when ACE 7 is used.
.. news-end-section
.. news-end-section

0 comments on commit a1631e4

Please sign in to comment.