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 · May be fixed by #4884
Open

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

floatingbit opened this issue Nov 16, 2024 · 3 comments · May be fixed by #4884
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.

iguessthislldo added a commit to iguessthislldo/OpenDDS that referenced this issue Feb 7, 2025
Fixes OpenDDS#4849

Changes from OpenDDS#4487 require C++
language to be enabled in CMake, which it basically is all the time
through `project(... LANGUAGES CXX)` expect in ishapes. There
`find_project(OpenDDS)` was used to get the OpenDDS version before
`project` enabled C++ which results in `try_compile` failing fatally.
These changes both make sure C and C++ are enabled early in CMake
initialization and switch the `project` and `find_package` to
comply with
https://cmake.org/cmake/help/latest/policy/CMP0165.html#policy:CMP0165

Also changed the C++ standard checks to include the min C++ standard
(currently C++98/03), so it would never mistake a broken compiler setup
with a compiler that only supports the min standard.
@iguessthislldo iguessthislldo linked a pull request Feb 7, 2025 that will close this issue
@jrw972 jrw972 moved this from Done to Todo in CMake Support Feb 12, 2025
@jrw972 jrw972 moved this from Todo to In Progress in CMake Support Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

2 participants