[CMake] about the required project label...
J Decker
d3ck0r at gmail.com
Sat Sep 18 03:00:38 EDT 2010
I have a small cmake script I include at start of several projects. I
define some things like where includes and libraries are for the
common libraries. This has worked well for the few extensions that I
did, because their root cmakelists.txt had no project. Some things
like CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT and
CMAKE_COMPILER_IS_GNUCC *are set* as valid if you have a
cmakelists.txt with no projects, and only add_subdirectory()s. They
are not set if you reference them before you define an initial
project.
So it's my inclination to define common functions and variables before
using them...
------------
cmake_minimum_required(VERSION 2.8)
# declare common global features
GET_FILENAME_COMPONENT(common_library_root
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Manufacturer\\Common
Library;Install_Dir]" ABSOLUTE CACHE)
include( ${common_library_root}/CMakeDefs )
PROJECT( my_new_project )
-----------
So I know know that won't work, and in the case of the cmakelists.txt
without a project, that shouldn't be done; Can maybe a warning (error)
be made that there is no PROJECT() ?
= = =
There are two ways I can work around this. (something I read recently
that I shouldn't do...)
1) define a PROJECT( Unused_project_name ) in CMakeDefs referenced
earlier.
a) This works 50% of the time... becuase since there are other
cmake users out there that know you shouldn't do anything before a
project label, they will have set a project before doing the include,
and then my project will interfere and not be the target project they
think they're using.
b) ? nothing good here I suppse
2) err (I don't understand why this works) but move include to the
end of the file?... and therefore within one of the projects (this
particular family has 4 projects all in the same directory...) but it
works fine to include it at the end.
The following code however doesn't work as well at the end...
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
"Set build type")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
That code wants to be before the first project to work correctly.
I'm certain there's a very logical reason that things are where they
have to be... but I think I'm as confused as the other thread about
when things happen... I guess include is done before any other logic
is parsed? what about if that include was in an If... and that if
depended on a condition of that (or another) included file?
More information about the CMake
mailing list