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

Issue compiling ishapes with CMake: try_compile() works only for enabled languages. #4849

Open
floatingbit opened this issue Nov 16, 2024 · 3 comments
Assignees

Comments

@floatingbit
Copy link

floatingbit commented Nov 16, 2024

I was able to successfully compile OpenDDS-DDS-3.30/OpenDDS-3.30 using Ubuntu 20.04/22.04 LTS, CMake 3.27/3.31, g++ 9/10 and run the messenger example.

However, while compiling OpenDDS-DDS-3.30/examples/DCPS/ishapes source, I get the following error:

/OpenDDS-DDS-3.30/examples/DCPS/ishapes$ cmake .
--   Using OpenDDS 3.30.0 at /OpenDDS-DDS-3.30
--   Using MPC at /OpenDDS-DDS-3.30/ACE_wrappers/MPC
--   Using ACE 6.5.21 at /OpenDDS-DDS-3.30/ACE_wrappers
--   Using TAO 2.5.21 at /OpenDDS-DDS-3.30/ACE_wrappers/TAO
CMake Error at /OpenDDS-DDS-3.30/cmake/init.cmake:181 (try_compile):
  Unknown extension ".cpp" for file

    /OpenDDS-DDS-3.30/cmake/test_cxx_std.cpp

  try_compile() works only for enabled languages.  Currently these are:

    

  See project() command to enable other languages.
Call Stack (most recent call first):
  /OpenDDS-DDS-3.30/cmake/init.cmake:313 (_opendds_set_cxx_std)
  /OpenDDS-DDS-3.30/cmake/OpenDDSConfig.cmake:17 (include)
  CMakeLists.txt:2 (find_package)


CMake Error at /OpenDDS-DDS-3.30/cmake/init.cmake:294 (message):
  ACE 6.5.21 (cxx11=TRUE) requires at least C++ 2011, but compiler only
  supports up to C++ 1998.
Call Stack (most recent call first):
  /OpenDDS-DDS-3.30/cmake/init.cmake:313 (_opendds_set_cxx_std)
  /OpenDDS-DDS-3.30/cmake/OpenDDSConfig.cmake:17 (include)
  CMakeLists.txt:2 (find_package)


-- Configuring incomplete, errors occurred!

TIA

@iguessthislldo iguessthislldo changed the title Issue compiling ishapes: ACE 6.5.21 (cxx11=TRUE) requires at least C++ 2011, but compiler only supports up to C++ 1998. Issue compiling ishapes with CMake: try_compile() works only for enabled languages. Nov 16, 2024
@iguessthislldo
Copy link
Member

This is the real issue: try_compile() works only for enabled languages.

Try switching around these two lines:

find_package(OpenDDS REQUIRED)
project(ishapes VERSION ${OpenDDS_VERSION} LANGUAGES CXX)

So it's:

project(ishapes VERSION ${OpenDDS_VERSION} LANGUAGES CXX)
find_package(OpenDDS REQUIRED) 

For me it gives a warning about the VERSION keyword, but it configured and built for me just fine.

For the real fix I think this has two parts to it:

  1. It obviously needs an explicit enable_language(CXX). I think I avoided doing things like this unless they were necessary, but we already need to do it for C, so maybe we should just do an enable_language(C CXX) at the start of init.cmake.
  2. try_compile code looks like this:

    OpenDDS/cmake/init.cmake

    Lines 173 to 191 in 1aa7ae0

    set(cplusplus_values 201103 201402 201703 202002 202302)
    set(test_cxx_std "${CMAKE_CURRENT_LIST_DIR}/test_cxx_std.cpp")
    set(temp_dir "${CMAKE_CURRENT_BINARY_DIR}/opendds_test_cxx_std")
    file(MAKE_DIRECTORY "${temp_dir}")
    # Get the latest known default compiler C++ standard
    set(default_cxx_std_year 1998)
    foreach(cplusplus IN LISTS cplusplus_values)
    try_compile(compiled
    "${temp_dir}/cplusplus_${cplusplus}"
    SOURCES "${test_cxx_std}"
    COMPILE_DEFINITIONS "-DOPENDDS_TEST_CPLUSPLUS=${cplusplus}L"
    )
    if(compiled)
    _opendds_cplusplus_to_year(default_cxx_std_year ${cplusplus})
    else()
    break()
    endif()
    endforeach()

    It's checking the C++ standard starting from C++11 up. The other issue I'm realizing is this should check if it can compile with the minimum C++ standard, in this case C++98/03. If it can't then it can give a different error.

@floatingbit
Copy link
Author

That worked! Thank you.

Would you like me to submit a PR with this change?

@iguessthislldo
Copy link
Member

Thanks for offering, but I'm not sure that's necessary. I wrote this code not too long ago in #4487.

Reopening though because the actual fix still needs to be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants