This is possible, but with important limitations. Let's assume we have master.tex and secondary.tex.
First of all, how should \setmaster be defined? It's quite easy:
\makeatletter \newcommand{\setmaster}[1]{% % Make all later \setmaster commands to be no-ops \global\let\setmaster\@gobble % Start reading the master file \input{#1}% % When it's finished, don't read from this file any more \endinput} \makeatother
But where should \setmaster be defined? Either in the document itself or in a personalized format file. In the first case, surround the definition between \ifdefined\setmaster\else and \fi, because we don't want to read it when secondary.tex is input.
First limitation. Paths will be relative to the location of the secondary file, so all files must all be in the same directory: you can't have \input{../master} and then master.tex call \input{subdir/secondary}.
Second limitation. TeX sets the job name equal to the first input file, if not overridden from the command line with the option -jobname. So, without cooperation from the editor/front-end, you won't get master.log or master.pdf, but secondary.log. This is a built-in behavior of TeX and it can't be modified: as soon as TeX is started and opens a file for input (in this case secondary.tex), it opens the .log file with the name derived from it or from the -jobname command line option.
Thus such an approach is not better than stating what's the main file using the editor's or front-end's features. Many of them have this feature, so this should be the preferred method.
The arara methods outlined in the answers to arara: making a rule to compile the main file from a chapter file are worthy of more than a look, because they are independent from whatever editor/front-end is being used.
ararafor this: arara: making a rule to compile the main file from a chapter file There are a host of other automation tools, but imho,ararais king