[CMake] include, macro and project

Titus von Boxberg titus at v9g.de
Wed Oct 17 09:48:50 EDT 2012


Hi all,

maybe it's a silly question, but RTFM doesn't enlighten me yet:

I'd like to set the project() in a macro() defined in a file included
by CMakeLists.txt.
The macro get's called immediately after including() the file
from within CMakeLists.txt

When calling the macro cmake executes the steps in an execution order
different from the case when I directly call project() instead
of using the macro:
When using the macro, CMake first checks for the compilers, etc.
and then executes the include file.
When using project() directly, CMake first executes the include file
and then checks the compilers, etc.

The include file is determining the tool chain depending on
some configuration variables, that's why this is a problem for me.
Even if the use case might be questionnable, still I'd like to
understand the reason for the difference.

Attached is a minimal sample to reproduce the behaviour.

Any explanation?

Thanks and Regards
Titus
-------------- next part --------------
MESSAGE(STATUS "Executing global scope of CMake-Include file")

MACRO(testmacro proj)
	MESSAGE(STATUS "Executing macro of CMake-Include file")
	project(${proj})
ENDMACRO()
-------------- next part --------------
#### CMakeFiles.txt

cmake_minimum_required(VERSION 2.8)

include(CMake-Include.txt)

# Calling testmacro results in execution of CMake-Include.txt
# after checking for the compilers.
# testmacro(macroproject)

# setting project directly results in immediate execution
# of CMake-Include.txt
project(testproject)


More information about the CMake mailing list