Re: [CMake] Parsing command line arguments from the make

2016-04-05 Thread Fedja Jeleskovic
I ended up using this exact approach with addition of one top level
Makefile which is used to run cmake in build folder. Top level Makefile
takes those arguments and passes them down to the cmake execution, which
than makes a decision on which way to go depending on the argument passed
in.

Here is how that part looks like:
BUILD_DIR   :=  build

ifneq ($(ENV),)
DEPLOY=$(ENV)
endif

ifeq "$(DEPLOY)" "V1"
NEW_FLAG=-DVERSION_1=ON
else
ifeq "$(DEPLOY)" "V2"
NEW_FLAG = -DVERSION_2=ON
else
ifeq "$(DEPLOY)" "V3"
NEW_FLAG = -DVERSION_3=ON
endif
endif
endif

all: ${BUILD_DIR}/Makefile
$(MAKE) -C ${BUILD_DIR}

cmake:
touch CMakeLists.txt
$(MAKE) ${BUILD_DIR}/Makefile

${BUILD_DIR}/Makefile:
@[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR}
@[ -f ${BUILD_DIR}/Makefile ] || (cd ${BUILD_DIR} && cmake $(NEW_FLAG) ..)
touch $@


I have also created three options (needed three in my case) that create
#defines for each of them and depending on which is initialized at the
start, ends up being enabled in the source code.

The issue that I had at the end was to clean cached values of those since
regular clean wasn't clearing #define that was previously set. At the end I
am running "make clean"  in build folder, following with delete of
build/CMakeCache.txt and build/Makefile. After that new option passed in to
the top level Makefile does what I need (initialize proper #define that is).

Here is how the clean section looks like in the top level Makefile:
.PHONY : clean
clean:
@- [ -f ${BUILD_DIR}/Makefile ] && $(MAKE) --silent -C ${BUILD_DIR} clean
|| true
@- [ -f ${BUILD_DIR}/CMakeCache.txt ] && rm ${BUILD_DIR}/CMakeCache.txt ||
true
@- [ -f ${BUILD_DIR}/Makefile ] && rm -rf ${BUILD_DIR}/Makefile || true


If there is a better way to clear the cache so I don't have to delete those
two files, I would like someone to point it.

Thanks for help and hope this will be useful for someone else in the future!

Any other comments on this are welcome!

On Tue, Apr 5, 2016 at 4:36 AM, Matějů Miroslav, Ing. <
mateju.miros...@azd.cz> wrote:

> Hi Fedja,
>
>
>
> As far as I know, the Makefiles generated  from CMake cannot contain
> decisions. CMake supports several output types aside from Makefiles and
> some of them probably don’t support decisions. However, you could supply
> these arguments within CMake call using -D option. For example
>
> cmake -DENV=VERSION_2 
>
> creates a CMake variable just like
>
> set(ENV "VERSION_2" CACHE)
>
> in the CMake source file.
>
>
>
> As you’ve mentioned already, you can access environment variables using
> $ENV{variable} syntax in CMake.
>
>
>
> Hope this helps.
>
>
>
> Miroslav
>
>
>
> *From:* CMake [mailto:cmake-boun...@cmake.org] *On Behalf Of *Fedja
> Jeleskovic
> *Sent:* Friday, April 01, 2016 8:08 PM
> *To:* cmake@cmake.org
> *Subject:* [CMake] Parsing command line arguments from the make
>
>
>
> Since I am converting existing makefile project to use cmake instead I
> need to accept values that come from command line which looks like this:
> VARIABLE_NAME="/home/user/project" make ENV=VERSION_2
>
>
>
> First one is used like this:
>
> include $(VARIABLE_NAME)/Makefile.include
>
>
>
> Second one has this code that triggers different paths later:
> ifneq ($(ENV),)
>
> DEPLOYMENT_VERSION=$(ENV)
>
> endif
>
>
>
> How do I do this in cmake?
>
>
>
> Thanks!
>
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Parsing command line arguments from the make

2016-04-05 Thread Matějů Miroslav , Ing .
Hi Fedja,

As far as I know, the Makefiles generated  from CMake cannot contain decisions. 
CMake supports several output types aside from Makefiles and some of them 
probably don’t support decisions. However, you could supply these arguments 
within CMake call using -D option. For example
cmake -DENV=VERSION_2 
creates a CMake variable just like
set(ENV "VERSION_2" CACHE)
in the CMake source file.

As you’ve mentioned already, you can access environment variables using 
$ENV{variable} syntax in CMake.

Hope this helps.

Miroslav

From: CMake [mailto:cmake-boun...@cmake.org] On Behalf Of Fedja Jeleskovic
Sent: Friday, April 01, 2016 8:08 PM
To: cmake@cmake.org
Subject: [CMake] Parsing command line arguments from the make

Since I am converting existing makefile project to use cmake instead I need to 
accept values that come from command line which looks like this:
VARIABLE_NAME="/home/user/project" make ENV=VERSION_2

First one is used like this:
include $(VARIABLE_NAME)/Makefile.include

Second one has this code that triggers different paths later:
ifneq ($(ENV),)
DEPLOYMENT_VERSION=$(ENV)
endif

How do I do this in cmake?

Thanks!
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Re: [CMake] Parsing command line arguments from the make

2016-04-01 Thread Fedja Jeleskovic
To make my question a bit more clear, I am trying to figure out how to add
these things so my make will be able to use them. If I need environment
variable inside the cmake, I could use $ENV{VARIABLE_NAME} and have it.

The problem is to create the code inside the CMakeLists.txt, so that
generated Makefile will be able to get before and after arguments that are
supplied.
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

[CMake] Parsing command line arguments from the make

2016-04-01 Thread Fedja Jeleskovic
Since I am converting existing makefile project to use cmake instead I need
to accept values that come from command line which looks like this:
VARIABLE_NAME="/home/user/project" make ENV=VERSION_2

First one is used like this:
include $(VARIABLE_NAME)/Makefile.include

Second one has this code that triggers different paths later:
ifneq ($(ENV),)
DEPLOYMENT_VERSION=$(ENV)
endif

How do I do this in cmake?

Thanks!
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake