Toolchain file for TI in CMake 3.10: how do I override compiler options and specify tools?

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

Toolchain file for TI in CMake 3.10: how do I override compiler options and specify tools?

Jason Heeris
I am trying to use CMake (3.10) to build an ANSI C project that may be compiled on PC with eg. GCC, but also needs to compile with Texas Instruments' compilers for their microprocessors. So I have about a million questions.

According to[1] it seems like the way to do this is via a toolchain file. So I'm trying to write a toolchain file to use TI's compiler/linker/etc, which do not (always) take the same arguments as eg. GCC or Clang.

Is there a complete list of tools I can override in a toolchain file? Specifically, I want to set the C compiler, C++ compiler, assembler and linker. I know about CMAKE_C(XX)_COMPILER, but what about the others? Are they documented anywhere? (I could guess, but I don't think that's wise.)

As I mentioned, TI's tools aren't the same as GCC, so I need to pare back a lot of options and start from almost-scratch (there are some commonalities). Options like "-D" and "-I" are fine, which is good because then eg. target_include_directories() still works. But certain other flags are just going to cause errors. How do I completely remove all compile flags from the generated Makefiles and replace them with my own? I can do this:

set(CMAKE_C_FLAGS ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_DEBUG ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_RELEASE ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_RELWITHDEBINFO ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_MINSIZEREL ${MINIMAL_FLAGS} CACHE STRING "" FORCE)

But I *still* see flags in the generated makefiles that I didn't put there such as "--compile_only" and "--c_file=...". How do I get rid of these and specify what's correct for my toolchain? (Also, why do I need the CACHE STRING "" FORCE options? I pulled that out of various Stackoverflow posts but I have no idea why it's necessary. Is that documented? What about the configurations... where are they listed? Do I have them all?)

(I keep asking "is this documented anywhere" because I like to provide references in code for future maintainers. I'm not trying to be unkind. Maybe once I know enough I can volunteer to write any missing docs myself.)

How do I add default flags that involve the source file name eg. for a file "main.c" I want to have a C compiler flag "--some_option='main.x'"?

Finally, this really seems like a lot of work despite the fact that toolchain files are (I thought) meant to be the way to define a different toolchain. It really feels like I'm swimming against the tide here. Is there another, more-CMake-ish way to accomplish what I'm trying to do?

Thanks for any help.

- Jason

--

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: Toolchain file for TI in CMake 3.10: how do I override compiler options and specify tools?

Patrick Griffiths

On Sat, Feb 23, 2019 at 12:49 AM Jason Heeris <[hidden email]> wrote:
I am trying to use CMake (3.10) to build an ANSI C project that may be compiled on PC with eg. GCC, but also needs to compile with Texas Instruments' compilers for their microprocessors. So I have about a million questions.

According to[1] it seems like the way to do this is via a toolchain file. So I'm trying to write a toolchain file to use TI's compiler/linker/etc, which do not (always) take the same arguments as eg. GCC or Clang.

Is there a complete list of tools I can override in a toolchain file? Specifically, I want to set the C compiler, C++ compiler, assembler and linker. I know about CMAKE_C(XX)_COMPILER, but what about the others? Are they documented anywhere? (I could guess, but I don't think that's wise.)

As I mentioned, TI's tools aren't the same as GCC, so I need to pare back a lot of options and start from almost-scratch (there are some commonalities). Options like "-D" and "-I" are fine, which is good because then eg. target_include_directories() still works. But certain other flags are just going to cause errors. How do I completely remove all compile flags from the generated Makefiles and replace them with my own? I can do this:

set(CMAKE_C_FLAGS ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_DEBUG ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_RELEASE ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_RELWITHDEBINFO ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_MINSIZEREL ${MINIMAL_FLAGS} CACHE STRING "" FORCE)

But I *still* see flags in the generated makefiles that I didn't put there such as "--compile_only" and "--c_file=...". How do I get rid of these and specify what's correct for my toolchain? (Also, why do I need the CACHE STRING "" FORCE options? I pulled that out of various Stackoverflow posts but I have no idea why it's necessary. Is that documented? What about the configurations... where are they listed? Do I have them all?)

(I keep asking "is this documented anywhere" because I like to provide references in code for future maintainers. I'm not trying to be unkind. Maybe once I know enough I can volunteer to write any missing docs myself.)

How do I add default flags that involve the source file name eg. for a file "main.c" I want to have a C compiler flag "--some_option='main.x'"?

Finally, this really seems like a lot of work despite the fact that toolchain files are (I thought) meant to be the way to define a different toolchain. It really feels like I'm swimming against the tide here. Is there another, more-CMake-ish way to accomplish what I'm trying to do?

Thanks for any help.

- Jason
--
  

I've written toolchain files for cross-compiling with gcc and/or clang, but not for for proprietary compilers, but maybe this brain dump can help:

In addition to CMAKE_<LANG>_COMPILER, you'll probably need to look at:

CMAKE_<LANG>_FLAGS_INIT
CMAKE_<LANG>_FLAGS_DEBUG_INIT 
etc ...

Sounds like you need to set them all explicitly since CMake doesn't know anything about your toolchain out of the box. The configurations (debug, release, etc) are handled by the variable naming. You should be able to set exactly what you want.  CMake glues the various flag variables together so you might need to experiment a little to see what the result is.

You might want to look at the CMAKE_TRY_COMPILE_* variable as it sounds like you're compiling for baremetal or an RTOS. 

Unfortunately, I think you're best best is  to dig through the documentation and trial and error. The variables and toolchain sections will be helpful: 


cmake has command line options you might find useful like --trace and --debug-trycompile. 

You can do make VERBOSE=1 to see what's executed.

FWIW, I suggest starting with a single .c file with an empty main. Once that compiles, start adding complexity. Good luck.

HTH
Patrick

 

--

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: Toolchain file for TI in CMake 3.10: how do I override compiler options and specify tools?

Cristian Adam
In reply to this post by Jason Heeris


On Sat, Feb 23, 2019 at 8:49 AM Jason Heeris <[hidden email]> wrote:
I am trying to use CMake (3.10) to build an ANSI C project that may be compiled on PC with eg. GCC, but also needs to compile with Texas Instruments' compilers for their microprocessors. So I have about a million questions.

According to[1] it seems like the way to do this is via a toolchain file. So I'm trying to write a toolchain file to use TI's compiler/linker/etc, which do not (always) take the same arguments as eg. GCC or Clang.

Is there a complete list of tools I can override in a toolchain file? Specifically, I want to set the C compiler, C++ compiler, assembler and linker. I know about CMAKE_C(XX)_COMPILER, but what about the others? Are they documented anywhere? (I could guess, but I don't think that's wise.)

As I mentioned, TI's tools aren't the same as GCC, so I need to pare back a lot of options and start from almost-scratch (there are some commonalities). Options like "-D" and "-I" are fine, which is good because then eg. target_include_directories() still works. But certain other flags are just going to cause errors. How do I completely remove all compile flags from the generated Makefiles and replace them with my own? I can do this:

set(CMAKE_C_FLAGS ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_DEBUG ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_RELEASE ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_RELWITHDEBINFO ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_MINSIZEREL ${MINIMAL_FLAGS} CACHE STRING "" FORCE)

But I *still* see flags in the generated makefiles that I didn't put there such as "--compile_only" and "--c_file=...". How do I get rid of these and specify what's correct for my toolchain? (Also, why do I need the CACHE STRING "" FORCE options? I pulled that out of various Stackoverflow posts but I have no idea why it's necessary. Is that documented? What about the configurations... where are they listed? Do I have them all?)


Regarding the CMAKE_<LANG>_FLAGS_<CONFIG> have a look at this blog post:

You "just" need to modify the CMAKE_<LANG>_FLAGS_<CONFIG>_INIT variables, no need to force the cache entries.

The "Modules" CMake folder is your friend, you can see how CMake handles other compilers. 
For debugging use CMake's "--trace-expand" command line parameter. 

Cheers,
Cristian.

--

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: Toolchain file for TI in CMake 3.10: how do I override compiler options and specify tools?

frodak17

On Sat, Feb 23, 2019 at 2:24 PM Cristian Adam <[hidden email]> wrote:


On Sat, Feb 23, 2019 at 8:49 AM Jason Heeris <[hidden email]> wrote:
I am trying to use CMake (3.10) to build an ANSI C project that may be compiled on PC with eg. GCC, but also needs to compile with Texas Instruments' compilers for their microprocessors. So I have about a million questions.

According to[1] it seems like the way to do this is via a toolchain file. So I'm trying to write a toolchain file to use TI's compiler/linker/etc, which do not (always) take the same arguments as eg. GCC or Clang.

Is there a complete list of tools I can override in a toolchain file? Specifically, I want to set the C compiler, C++ compiler, assembler and linker. I know about CMAKE_C(XX)_COMPILER, but what about the others? Are they documented anywhere? (I could guess, but I don't think that's wise.)

As I mentioned, TI's tools aren't the same as GCC, so I need to pare back a lot of options and start from almost-scratch (there are some commonalities). Options like "-D" and "-I" are fine, which is good because then eg. target_include_directories() still works. But certain other flags are just going to cause errors. How do I completely remove all compile flags from the generated Makefiles and replace them with my own? I can do this:

set(CMAKE_C_FLAGS ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_DEBUG ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_RELEASE ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_RELWITHDEBINFO ${MINIMAL_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_MINSIZEREL ${MINIMAL_FLAGS} CACHE STRING "" FORCE)

But I *still* see flags in the generated makefiles that I didn't put there such as "--compile_only" and "--c_file=...". How do I get rid of these and specify what's correct for my toolchain? (Also, why do I need the CACHE STRING "" FORCE options? I pulled that out of various Stackoverflow posts but I have no idea why it's necessary. Is that documented? What about the configurations... where are they listed? Do I have them all?)


Regarding the CMAKE_<LANG>_FLAGS_<CONFIG> have a look at this blog post:

You "just" need to modify the CMAKE_<LANG>_FLAGS_<CONFIG>_INIT variables, no need to force the cache entries.

The "Modules" CMake folder is your friend, you can see how CMake handles other compilers. 
For debugging use CMake's "--trace-expand" command line parameter. 

Cheers,
Cristian.


Take a look at Modules/CMakeCInformation.cmake.
Also CMAKE_USER_MAKE_RULES_OVERRIDE may be useful to you.
There are a few others that may also be used depending on what languages you are trying to use.

StackOverflow isn't always correct even if something is marked as answered and up-voted.

FYI, The "--compile_only" and "--c_file" probably come from the file Modules/Compiler/TI-C.cmake.  At some point TI compilers were using those options to build files but I guess in your case the compiler is no longer compatible with what it used to be.


--

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