[CMake] Changing link flags for one target

2018-07-03 Thread Andrew White
In my cross-compile environment for an embedded platform, I need to set the 
stack size for each executable.  The linker flag to set the stack size is (for 
example) "-Wl,-elf2flt='-s 2'".

Is there an easy way to set this flag for every executable except one, for 
which I set "-Wl,-elf2flt='-s 4'"?  Obviously I can call
Set_target_properties( PROPERTIES LINK_FLAGS "-Wl,-elf2flt='-s 
2'")
on each target, but is there a mechanism to make this the default and then set 
a different value on a single target?

If necessary, I suspect "-Wl,-elf2flt='-s 2' -Wl,-elf2flt='-s 4'" will 
produce the correct result.
* can I avoid doing it like this?
* how can I be sure that the more specific option will follow the general one?

(Assume all the targets are added via add_subdirectory commands that are common 
across multiple platforms, and that I'm adding platform-specific build rules in 
the project CMakeLists.txt)

Thanks

--
Andrew

-- 

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:
https://cmake.org/mailman/listinfo/cmake


[CMake] Adding a target to 'all' that was previously excluded

2018-07-03 Thread Andrew White
How do I add an excluded (executable) target to the build.  I know that if I 
add a library EXCLUDE_FROM_ALL and then create a dependency on that library 
then that the library will be built anyway.  How do I trigger similar behaviour 
from an executable target?

Example:

Directory A contains a CMakeLists.txt that builds half a dozen utilities. As 
part of my project, I want to add a single target from that list.

I can include the build info without auto-adding all targets by going:

Add_subdirectory(blah EXCLUDE_FROM_ALL)

How do I then add target blah_X to my 'all' build?  Or is there another way to 
approach this?

Thanks

--
Andrew

-- 

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:
https://cmake.org/mailman/listinfo/cmake


[CMake] Different INSTALL target settings per project

2018-07-03 Thread Andrew White
We have a number of projects that include other projects.  Some of the parent 
projects are cross-compile projects with various odd settings.

Example project:

add_subdirectory(a)
add_subdirectory(b)

I want to go:
Install(TARGETS target_a program_b
RUNTIME DESTINATION other-bin
)

If I put it in the root CMakeLists.txt, CMake complains that the targets are 
not defined in this context.  But if I put an install() command in subdirs A 
and B, then the 'other-bin' output path will apply to all projects, not just 
this one.

Is there an easy way to specify custom install paths for targets in 
subdirectories without directly hacking the environment variables?

Thanks

--
Andrew

-- 

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:
https://cmake.org/mailman/listinfo/cmake


[CMake] Null alias targets?

2018-06-13 Thread Andrew White
I have a library that needs to be built on some platforms but on others is part 
of the OS.  I'd like to avoid putting "if platform" conditional code in the 
places it is used, but instead hide it away in my platform-specific code.

One way to do this is define a variable mylib_targetname in each platform and 
add ${mylib_targetname} as a dependency.  It can be defined on some platforms 
and undefined on others.

It feels cleaner if I could create an alias target MY_NAMESPACE::mylib and 
refer to that. This lets me define the dependency without making sure an 
environment variable is set, which feels more natural.  But in order to make 
this work I need a way to express that MY_NAMESPACE::mylib might be 
(legitimately) null on some platforms, and I can't figure out how to do this.

Any ideas?

--
Andrew

-- 

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:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] CMakeLists.txt in different place than source

2018-06-13 Thread Andrew White
J Decker wrote:

You can define a variable to define the base of the sources

set( SOURCE_ROOT /some/path )



could be set relative to the current cmake path per cmake that uses those

souces... and then just prefix it



add_library(my_lib

${SOURCE_ROOT}/src/a.c

${SOURCE_ROOT}/include/a.h

)



Thanks, but that’s approximately exactly what I’m trying to avoid doing.  I 
cheat a little, in that I have a macro that will prepend a prefix to every 
element of a list.  My motivation is avoiding situations where I add the prefix 
to the files but forget to add the prefix when I call 
target_include_directories or suchlike.



I’m not sure anything trickier is workable in the CMake model, however.  For 
example, hacking CMAKE_CURRENT_SOURCE_DIR might make sense for file paths, but 
if I then call add_subdirectory should it be rooted at the CMakeList directory 
or the source root directory.



--

Andrew


-- 

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:
https://cmake.org/mailman/listinfo/cmake


[CMake] CMakeLists.txt in different place than source

2018-06-12 Thread Andrew White
I have a situation where I want my CMakeLists.txt in a different place than my 
source.

e.g.:

/some/path/project/CMakeLists.txt
/other/path/source/src/a.c
/other/path/source/include/a.h

Is there an easy way to say "process this CMakeLists.txt as if it were in 
/other/path/source" (at least as far as file paths are concerned)?

e.g.:

add_library(my_lib
src/a.c
include/a.h
)

target_include_directories(my_lib PUBLIC include)

I know I can add a full path prefix to every file, but there are a lot of them. 
 I'm hoping for a shortcut.

--
Andrew


-- 

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:
https://cmake.org/mailman/listinfo/cmake