I've written a ( not so ) small bash script to generate my generic makefiles. These makefiles detect the host architecture at the beginning, and create all objects and outputs in a folder with the arch as name.
it goes like this:
uname_m = $(shell uname -m)
DETECTED_ARCHITECTURE=$(uname_m)
ifeq ($(ARCH), x86_64)
CFLAGS += -m64
LDFLAGS += -m64
endif
ifeq ($(ARCH), x86)
CFLAGS += -m32
LDFLAGS += -m32
endif
OUTPUT_DIR = $(DETECTED_ARCHITECTURE)/
OBJ_PREFIX_DIR = $(OUTPUT_DIR)objs/
So for example, if i run make for my code in my work pc, it outputs everything to a folder named i686, at home to a folder x86_64, and on my raspberry, to armv6l. Also, if i do something like ARCH=i686 make, it correctly overrides the detected architecture so that it sets the correct compiler options, and output directory. The final output goes into OUTPUT_DIR, and all the generated .o files go into OUTPUT_DIR/objs.
I'm trying to do something similar with cmake. I've looked at CMake add_custom_command/_target in different directories for cross-compilation and CMAKE output directory depending on generator architecture, but i do not want the architecture to be dependent on the generator. I want it to be dependent on the compiling machine.
For example, i code in my pc, and compile it. if all goes well, i ssh to my raspberry, mount the code folder from my pc to the raspberry thru sshfs, and compile it there. Since everything goes to a different folder ( armv6l vs x86_64 ), there are no collisions, and i don't have to re-generate the makefile, or clean, or whatever.
So, basically, is it possible to tell cmake to make a makefile architecture aware? Thanks