1

I've written a small CMake module for, well, it doesn't matter what for. The point is that it acts as follows:

  • When the appropriate CMake function is invoked, a shell script with relative path scripts/whatever.sh (under the project directory) is invoked.
  • The shell script cat's a 'here-file' containing a C program to the C compiler found by CMake (with fallback to cc)
  • The program is compiled, linked and run, producing some text
  • The output text is saved as a CMake variable

This is relatively robust on Unix-like systems, where cat and bash are available and when the path separator is /. (There may be other assumptions I'm ignoring.) But - I want this to work on Windows, and other systems as well. How do I go about doing this?

Notes:

einpoklum
  • 118,144
  • 57
  • 340
  • 684

1 Answers1

1

You may use CMake scripts for being cross-platform. Many things may be performed directly in CMakeLists.txt and scripts included from it:

  • "Here in document" support in CMake is not the best, but it is not very difficult to store text of a small program into a CMake variable.

  • execute_process is able to run external programs from CMake script and store output of that program in CMake variable. Also, try_compile or try_run may be useful in some scenarios.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153