2

I have a project that shall be configured/built differently when either using cmake or emcmake cmake (followed by make or emmake make respectively). For example, I don't need to build a test executable if it is run by emcmake cmake as the result will be WebAssembly.

So, is there any variable available when run by emcmake cmake, that I could query? Are there other approaches?

stackprotector
  • 10,498
  • 4
  • 35
  • 64
  • How are you calling these commands? Wouldn't a wrapper script work for you with setting the environment variable for the respective command that you can access later in the CMake to identify the source of invocation? – Azeem Aug 02 '20 at 01:53
  • @Azeem `emcmake` is already such a wrapper script (by emscripten). Of course, I could write my own wrapper script that wraps `emcmake` or I could call one of the commands (`cmake` or `emcmake cmake`) with additional parameters, but as I am already using different commands, I was hoping to be able to detect that, without additional "surroundings". – stackprotector Aug 02 '20 at 06:05
  • Right. That could be a solution just to get things done. And, it could be suggested as an improvement/feature to `emscripten`'s codebase for future support. – Azeem Aug 02 '20 at 07:59

1 Answers1

6

You can detect if emcmake cmake or emconfigure cmake are used with the EMSCRIPTEN variable:

if(EMSCRIPTEN)
    message("Using emscripten!")
else()
    message("Not using emscripten!")
endif()
cajomar
  • 428
  • 5
  • 9