As part of my compilation process I need to run a custom build tool that parses XML files and generates a C++ header and source file, which are in turn included and compiled by the main executable. My build tool is an executable target within my CMake setup that the main executable references via
This works great not only because my build tool gets automatically built and executed at the right time (i.e. before the generated source files are needed by the main executable’s build process), making iteration a breeze, but also because both my build tool and the main executable share the same libraries, which avoids building them twice.
Is this setup incompatible with cross-compilation?
Let’s say I am on a Windows host machine and want to cross-compile the main executable for Linux. My build tool needs to be built for Windows, as it will be executed on the host machine during the compilation process. But my main executable is being built for Linux, so it pulls in Linux-specific libraries (e.g. a system IO abstraction library that is used by both executables).
Now the sharing of libraries between the executables is problematic, as I would want to pull in different versions of each library (i.e.
SystemIO_Windows for my build tool and
SystemIO_Linux for the main executable; see “Library Setup” below).
I am aware of
CMAKE_SYSTEM_NAME, CMake toolchains, etc., but as far as I can tell neither addresses the issue of needing to pull in the same target multiple times with different build settings.
Is my only option removing my build tool from the build process and using it as a pre-built executable?
The “System” library’s
CMakeLists.txt includes different files depending on which platform is being targeted, i.e. on Windows “System” would add only the
Windows_IO.cpp file and on Linux the
Linux_IO.cpp file. I cannot have both files added at the same time because when I am not cross-compiling,
Linux_IO.cpp would fail to compile on Windows.