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

[bug] additional cmake args after CMAKE_TOOLCHAIN_FILE will clear it #599

Open
HRXWEB opened this issue Nov 24, 2023 · 2 comments
Open

[bug] additional cmake args after CMAKE_TOOLCHAIN_FILE will clear it #599

HRXWEB opened this issue Nov 24, 2023 · 2 comments

Comments

@HRXWEB
Copy link

HRXWEB commented Nov 24, 2023

env

ROS2: humble
ubuntu 20.04

I test the bug used the following CMakeLists.txt file

cmake_minimum_required(VERSION 3.12)
project(OpenMPTest)


if(CMAKE_TOOLCHAIN_FILE)
  message(AUTHOR_WARNING TOOLCHAINFILE: ${CMAKE_TOOLCHAIN_FILE})
else()
  message(AUTHOR_WARNING TOOLCHAINFILE: ${CMAKE_TOOLCHAIN_FILE})
endif()

if(COUT_INFO)
  message(AUTHOR_WARNING COUT_INFO: ON)
else()
  message(AUTHOR_WARNING COUT_INFO: OFF)
endif()
find_package(OpenMP REQUIRED)
find_package(backward_ros REQUIRED)

colcon

when I typed the command:

colcon build --cmake-force-configure --cmake-args -DCMAKE_VERBOSE_MAKEFILE=ON --cmake-args -DCMAKE_TOOLCHAIN_FILE="/root/cross_compile/cmake-toolchains/generic_linux.cmake"

it will output:

Starting >>> OpenMPTest
[2.695s] WARNING:colcon.colcon_cmake.task.cmake.build:Could not run installation step for package 'OpenMPTest' because it has no 'install' target
--- stderr: OpenMPTest
CMake Warning (dev) at CMakeLists.txt:6 (message):
  TOOLCHAINFILE:/root/cross_compile/cmake-toolchains/generic_linux.cmake
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:14 (message):
  COUT_INFO:OFF
This warning is for project developers.  Use -Wno-dev to suppress it.

---
Finished <<< OpenMPTest [2.37s]

Summary: 1 package finished [2.50s]
  1 package had stderr output: OpenMPTest

When I typed the command:

colcon build --cmake-force-configure --cmake-args -DCMAKE_VERBOSE_MAKEFILE=ON --cmake-args -DCMAKE_TOOLCHAIN_FILE="/root/cross_compile/cmake-toolchains/generic_linux.cmake" --cmake-args -DCOUT_INFO=ON

it will output:

Starting >>> OpenMPTest
[2.673s] WARNING:colcon.colcon_cmake.task.cmake.build:Could not run installation step for package 'OpenMPTest' because it has no 'install' target
--- stderr: OpenMPTest                         
CMake Warning (dev) at CMakeLists.txt:8 (message):
  TOOLCHAINFILE:
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:12 (message):
  COUT_INFO:ON
This warning is for project developers.  Use -Wno-dev to suppress it.

---
Finished <<< OpenMPTest [2.34s]

Summary: 1 package finished [2.48s]
  1 package had stderr output: OpenMPTest

cmake

When I typed the command:

cmake -DCMAKE_TOOLCHAIN_FILE="/root/cross_compile/cmake-toolchains/generic_linux.cmake"

it will output:

CMake Warning:
  No source or binary directory provided.  Both will be assumed to be the
  same as the current working directory, but note that this warning will
  become a fatal error in future CMake releases.


-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc
-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/aarch64-linux-gnu-g++
-- Check for working CXX compiler: /usr/bin/aarch64-linux-gnu-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) at CMakeLists.txt:6 (message):
  TOOLCHAINFILE:/root/cross_compile/cmake-toolchains/generic_linux.cmake
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:14 (message):
  COUT_INFO:OFF
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP_CXX: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5")  
-- Found backward_ros: 1.0.1 (/root/sysroot/opt/ros3rd/share/backward_ros/cmake)
-- Found Python3: /usr/bin/python3.8 (found version "3.8.10") found components: Interpreter 
-- Could NOT find libdw (missing: LIBDW_LIBRARY LIBDW_INCLUDE_DIR) 
-- Could NOT find libbfd (missing: LIBBFD_LIBRARY LIBBFD_INCLUDE_DIR) 
-- BACKWARD_HAS_UNWIND=1
-- BACKWARD_HAS_BACKTRACE=0
-- BACKWARD_HAS_BACKTRACE_SYMBOL=1
-- BACKWARD_HAS_DW=0
-- BACKWARD_HAS_BFD=0
-- Could NOT find Backward (missing: BACKWARD_LIBRARIES) 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/huangruixin/ws/src/OpenMPTest

When I typed the command:

cmake -DCMAKE_TOOLCHAIN_FILE="/root/cross_compile/cmake-toolchains/generic_linux.cmake" -DCOUT_INFO=ON

it will output:

CMake Warning:
  No source or binary directory provided.  Both will be assumed to be the
  same as the current working directory, but note that this warning will
  become a fatal error in future CMake releases.


-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc
-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/aarch64-linux-gnu-g++
-- Check for working CXX compiler: /usr/bin/aarch64-linux-gnu-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) at CMakeLists.txt:6 (message):
  TOOLCHAINFILE:/root/cross_compile/cmake-toolchains/generic_linux.cmake
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:12 (message):
  COUT_INFO:ON
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP_CXX: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5")  
-- Found backward_ros: 1.0.1 (/root/sysroot/opt/ros3rd/share/backward_ros/cmake)
-- Found Python3: /usr/bin/python3.8 (found version "3.8.10") found components: Interpreter 
-- Could NOT find libdw (missing: LIBDW_LIBRARY LIBDW_INCLUDE_DIR) 
-- Could NOT find libbfd (missing: LIBBFD_LIBRARY LIBBFD_INCLUDE_DIR) 
-- BACKWARD_HAS_UNWIND=1
-- BACKWARD_HAS_BACKTRACE=0
-- BACKWARD_HAS_BACKTRACE_SYMBOL=1
-- BACKWARD_HAS_DW=0
-- BACKWARD_HAS_BFD=0
-- Could NOT find Backward (missing: BACKWARD_LIBRARIES) 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/huangruixin/ws/src/OpenMPTest

Compare

By comparing the following two keywords, it can be observed that the issue lies with colcon rather than cmake.

  1. TOOLCHAINFILE:XXX
  2. COUT_INFO:XXX
@cottsay
Copy link
Member

cottsay commented Nov 30, 2023

The syntax of the invocation should be:

colcon build --cmake-force-configure --cmake-args -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_TOOLCHAIN_FILE="/root/cross_compile/cmake-toolchains/generic_linux.cmake" -DCOUT_INFO=ON

You should not specify --cmake-args multiple times like this.

@HRXWEB
Copy link
Author

HRXWEB commented Dec 1, 2023

The syntax of the invocation should be:

colcon build --cmake-force-configure --cmake-args -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_TOOLCHAIN_FILE="/root/cross_compile/cmake-toolchains/generic_linux.cmake" -DCOUT_INFO=ON

You should not specify --cmake-args multiple times like this.

Wow, thanks a lot.

But there is a natural use case for colcon --cmake-args -DCMAKE_TOOLCHAIN_FILE=fixed.cmake --packages-select <package> [--cmake-args *[*]], where the final cmake-args is optional and placed at the end for convenience of modification. Is it worth supporting this usage?

A note: after specify some --cmake-args in cc.mixin, the --cmake-args after it will not disable the args in cc.mixin. like,
colcon build --mixin cc --packages-select <package_name> --cmake-args -DCOUT_INFO=ON
The CMAKE_TOOLCHAIN_FILE will keep the value in cc.mixin:

{
    "build": {
        "cc": {
            "cmake-args": [
                "-DCMAKE_VERBOSE_MAKEFILE=ON",
                "-DCMAKE_TOOLCHAIN_FILE='/root/sysroot/toolchain.cmake'"
            ]
        }
    }
}

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

No branches or pull requests

2 participants