0

I have a project that have a client and a server, so i have a top level CMakeList.txt and 2 subdirectory containing each a CMakeList.txt. Now i want 2 build for thoses projects, one native that build client and server, and another one that build emscripten version of the client. For now i use a simple bash script that invoke cmake with no toolchain first and a second that specify the emscripten toolchain. Additionnaly i have some if(EMSCRIPTEN) to setup compile options in client/CMakeList.txt. I don't like this and i prefer not to have to invoke any shell script, so my question is : is there a better method to not go outside cmake ? something like :

add_subdirectory( server )
add_subdirectory( client )
add_subdirectory( client TOOLCHAIN=XXX )
  • You cannot configure a single CMake project for use different compiler for different targets. So you have no other choice than configure (and build) a project twice: once for "native" compiler, and once with emscripten toolchain. – Tsyvarev Mar 09 '22 at 14:00
  • If you are struggling to build a whole project tree that probably means that some leaves don't belong there and should spring their own tree. – ixSci Mar 09 '22 at 15:10
  • @tsyvarev so i have to stick to hand made build script ? – mystackoverflowpseudo Mar 09 '22 at 15:57
  • Yes, for package your project in **several configurations** you need to write a script which runs `cmake` **several times**. It could be shell script (`.sh`), CMake script (which is run via `cmake -P`) or whatever you want. – Tsyvarev Mar 09 '22 at 17:26

0 Answers0