einpoklum
einpoklum

Reputation: 131950

Making a Unix-specific CMake procedure cross-platform

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

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:

Upvotes: 1

Views: 99

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 66061

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.

Upvotes: 1

Related Questions