[CMake] CMake command line arguments

Gabriel Petrovay gabipetrovay at gmail.com
Sun Mar 6 21:36:49 EST 2011


This does not work because the "NMake Makefile" generator already sets
the variable: CMAKE_BUILD_TYPE to "Debug"

So your code will never be executed:
if(NOT CMAKE_BUILD_TYPE)
  # it will never get here
  set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif(NOT CMAKE_BUILD_TYPE)

And I want to have a default of "Release".


Gabriel

On Mon, Mar 7, 2011 at 3:14 AM, 徐亮 <lxu4net at gmail.com> wrote:
> You can check if the variable has defined. You can see
> "http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:if" for
> detail information.
>
> if(NOT CMAKE_BUILD_TYPE)
>   set(CMAKE_BUILD_TYPE RelWithDebInfo)
> endif()
>
> 2011/3/7 Gabriel Petrovay <gabipetrovay at gmail.com>
>>
>> Hi,
>>
>> I don't understand how to do that...
>>
>> The user who builds does not set any environment and does not provide
>> any -D arguments. I want CMake to automatically configure variables
>> like: CMAKE_BUILD_TYPE or CMAKE_INSTALL_PREFIX when the user does not
>> provide them. So I want *my* default values. But I don't want to set
>> them when the user provides the *generator* ("NMake Makefiles")
>> default values.
>>
>> The only way I see it is for CMake to tell you what parameters were
>> there in the command line. Does CMake support this?
>>
>> How do you do this with the PATH environment variable?
>>
>>
>> Gabriel
>>
>> On Mon, Mar 7, 2011 at 2:41 AM, 徐亮 <lxu4net at gmail.com> wrote:
>> >> From: Gabriel Petrovay <gabipetrovay at gmail.com>
>> >> Subject: [CMake] CMake command line arguments
>> >>
>> >> Hi,
>> >>
>> >> Is there a way to read the arguments that were passed to CMake from
>> >> inside a CMakeLists.txt file?
>> >>
>> >> There is a problem that some generators (like "NMake Makefiles") set a
>> >> default value for certain variables (like CMAKE_BUILD_TYPE=Debug,
>> >> CMAKE_INSTALL_PREFIX=C:\Program Files\${CMAKE_PROJECT_NAME})
>> >>
>> >> >From inside CMake one can not set up a different default value if the
>> >> user does not specify it with a -D option. This is because
>> >> IF(CMAKE_BUILD_TYPE) will always be true because of the default set by
>> >> the generator ("NMake Makefiles").
>> >>
>> >> There was this guy having the same problem:
>> >> http://www.mail-archive.com/cmake@cmake.org/msg09640.html
>> >>
>> >> Any solution how one can solve this? Reading the arguments passed to
>> >> CMake would be one, but I find no documentation/example/google_result
>> >> for this.
>> >>
>> >>
>> >> Thanks!
>> >>
>> >> --
>> >> MSc Gabriel Petrovay
>> >> Mobile: +41(0)787978034
>> >> www.28msec.com
>> >>
>> >
>> > I use "environment variables" to handle this problem. Such as "$ENV{PATH}".
>> > Liang Xu
>> >
>> > _______________________________________________
>> > Powered by www.kitware.com
>> >
>> > Visit other Kitware open-source projects at
>> > http://www.kitware.com/opensource/opensource.html
>> >
>> > Please keep messages on-topic and check the CMake FAQ at:
>> > http://www.cmake.org/Wiki/CMake_FAQ
>> >
>> > Follow this link to subscribe/unsubscribe:
>> > http://www.cmake.org/mailman/listinfo/cmake
>> >
>>
>>
>>
>> --
>> MSc Gabriel Petrovay
>> Mobile: +41(0)787978034
>> www.28msec.com
>
>
>
> --
> Liang Xu
>



-- 
MSc Gabriel Petrovay
Mobile: +41(0)787978034
www.28msec.com


More information about the CMake mailing list