Get compiler command line (or json compilation database) for a target

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Get compiler command line (or json compilation database) for a target

Roman Popov
Hi all,

How can I get a full compiler command line for a given target in CMakeLists project? I want to run Clang-based tool on some targets (using CTest), and it requires same options as used during compilation. 

I know there is CMAKE_EXPORT_COMPILE_COMMANDS but it is not taget-specific.

Here author suggets to use get_target_property on a target.  I've tried this, but it does not work when some properties are inherited from libraries (for example include paths).

Do you have any ideas?

Thanks,
Roman

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Get compiler command line (or json compilation database) for a target

Roman Popov
After day of googling I've found a solution that almost works for me. 

There is a CXX_CLANG_TIDY property that enables clang-tidy on a target. https://cmake.org/cmake/help/v3.12/prop_tgt/LANG_CLANG_TIDY.html
But I can replace clang-tidy with my own Clang-based tool:

set(CLANG_TIDY_EXE  ${MY_CLANG_BASED_TOOL} )
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" " --my-additional-options")

set_target_properties(
        my_exe_target PROPERTIES
        CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
)

The only drawback is that my tool will be run together with my_exe_target build.  And I want to run it as a separate build target. 


пн, 30 июл. 2018 г. в 0:12, Roman Popov <[hidden email]>:
Hi all,

How can I get a full compiler command line for a given target in CMakeLists project? I want to run Clang-based tool on some targets (using CTest), and it requires same options as used during compilation. 

I know there is CMAKE_EXPORT_COMPILE_COMMANDS but it is not taget-specific.

Here author suggets to use get_target_property on a target.  I've tried this, but it does not work when some properties are inherited from libraries (for example include paths).

Do you have any ideas?

Thanks,
Roman

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Get compiler command line (or json compilation database) for a target

Roman Popov
In general I don't understand why CMake provides a separate integration for each tool (<LANG>_CLANG_TIDY <LANG>_COMPILER_LAUNCHER <LANG>_CPPCHECK <LANG>_CPPLINT <LANG>_INCLUDE_WHAT_YOU_USE),

But a generic solution is not provided  (or not documented clearly? )

вт, 31 июл. 2018 г. в 9:47, Roman Popov <[hidden email]>:
After day of googling I've found a solution that almost works for me. 

There is a CXX_CLANG_TIDY property that enables clang-tidy on a target. https://cmake.org/cmake/help/v3.12/prop_tgt/LANG_CLANG_TIDY.html
But I can replace clang-tidy with my own Clang-based tool:

set(CLANG_TIDY_EXE  ${MY_CLANG_BASED_TOOL} )
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" " --my-additional-options")

set_target_properties(
        my_exe_target PROPERTIES
        CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
)

The only drawback is that my tool will be run together with my_exe_target build.  And I want to run it as a separate build target. 


пн, 30 июл. 2018 г. в 0:12, Roman Popov <[hidden email]>:
Hi all,

How can I get a full compiler command line for a given target in CMakeLists project? I want to run Clang-based tool on some targets (using CTest), and it requires same options as used during compilation. 

I know there is CMAKE_EXPORT_COMPILE_COMMANDS but it is not taget-specific.

Here author suggets to use get_target_property on a target.  I've tried this, but it does not work when some properties are inherited from libraries (for example include paths).

Do you have any ideas?

Thanks,
Roman

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake