[CMake] How about GNU Automatic Variables

J Decker d3ck0r at gmail.com
Sat Nov 29 07:43:18 EST 2014


On Sat, Nov 29, 2014 at 1:48 AM, Domen Vrankar <domen.vrankar at gmail.com>
wrote:

> I was curious and I looked a bit further:
> http://www.cmake.org/cmake/help/v3.0/command/add_library.html has a
> OBJECT target that perhaps you could use instead of static library.
>
> referencing objects is kinda messy, was actually cleaner to just copy
things; I already did it for a whole slew of files so I could compile .c as
C/C++/CLI ... but needed other compiler options; ended up copying almost
the whole tree to ${cmake_binary_dir}/(subst/.c/.cpp/)
because I couldn't set compile properties per project only per source....


> http://www.cmake.org/cmake/help/v3.0/command/set_property.html also
> has a SOURCE option that I haven't mentioned before because I'm not
> certain how to produce two differently named .o files but maybe you'll
> be able to figure that out...
>
>
That works, but it only applies to the name of the source; if you don't
have differntly named sources it doesn't help; and I think that's the one I
used in the first place....

----
and as a related note; is better to make the generated output into binary
dir; if into source_dir will just mess up source control and people will
commit generated sources....


Regards,
> Domen
>
>
> 2014-11-29 10:31 GMT+01:00 Domen Vrankar <domen.vrankar at gmail.com>:
> > Hi,
> >
> > I haven't tested this but I think you could write something like this:
> >
> > add_library(test_single test.c)
> > set_property(
> >    TARGET test_single
> >    PROPERTY COMPILE_DEFINITIONS DOUBLE=some_val
> > )
> > add_library(test_double test.c)
> > set_property(
> >    TARGET test_double
> >    PROPERTY COMPILE_DEFINITIONS DOUBLE=some_other_val
> > )
> >
>

wouldn't be included in a single library, and you'd have to know later to
include 2 libs, or maintain a varible that's a list of libs...



> > and then link the static libraries to an executable.
> >
> > As far as I know you could also use
> > set_target_properties(test_single PROPERTIES COMPILE_DEFINITIONS
> > DOUBLE=some_val)
> > but I'm not certain what the difference is... Probably back
> compatibility...
> >
> > Hope this helps,
> > Domen
> >
> >
> >
> > 2014-11-29 9:27 GMT+01:00 Zhang Xianyi <traits.zhang at gmail.com>:
> >> Hi Decker,
> >>
> >> Thank you for the answer.
> >>
> >> If I want to debug test_double, the debugger will refer to
> >> ${CMAKE_BINARY_DIR}/test_double.c.
> >> I am not sure it is appropriate to debug a generated file.
> >>
> >>
> >> Xianyi
> >>
> >> 2014-11-28 23:03 GMT+08:00 J Decker <d3ck0r at gmail.com>:
> >>>
> >>>
> >>>
> >>> On Fri, Nov 28, 2014 at 1:29 AM, Zhang Xianyi <traits.zhang at gmail.com>
> >>> wrote:
> >>>>
> >>>> Hi,
> >>>>
> >>>> I want to use cmake for a library which supports different floating
> point
> >>>> precision.
> >>>>
> >>>> In Makefile, I used $(*F)  to generate the different function name.
> >>>>
> >>>> Could I use $(*F) in cmake?
> >>>>
> >>>>
> >>>> ==================
> >>>>
> >>>> test.c
> >>>>
> >>>> ===============
> >>>>
> >>>> #ifdef DOUBLE
> >>>>
> >>>> #define TYPE double
> >>>>
> >>>> #else
> >>>>
> >>>> #define TYPE float
> >>>>
> >>>> #endif
> >>>>
> >>>>
> >>>> void CNAME(TYPE * a)
> >>>>
> >>>> {
> >>>>
> >>>>   a[0]=1.0;
> >>>>
> >>>> }
> >>>>
> >>>>
> >>>
> >>> CMakeLists.txt
> >>> ====================
> >>>  cmake_minimum_required(VERSION 2.8)
> >>>
> >>>        add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/test_double.c
> >>>                            DEPENDS test.c
> >>>                            COMMAND ${CMAKE_COMMAND} -E
> copy_if_different
> >>> test.c   ${CMAKE_BINARY_DIR}/test_double.c
> >>>                            COMMAND ${CMAKE_COMMAND} -E touch
> >>> ${CMAKE_BINARY_DIR}/test_double.c
> >>>                            )
> >>>
> >>>
> >>> add_library( libtest   test.c  ${CMAKE_BINARY_DIR}/test_double.c )
> >>>
> >>> SET_PROPERTY(SOURCE ${CMAKE_BINARY_DIR}/test_double.c
> >>>                  APPEND
> >>> PROPERTY COMPILE_DEFINITIONS "DOUBLE" )
> >>>
> >>> ======================
> >>>
> >>>> ===========
> >>>>
> >>>> Makefile
> >>>>
> >>>> ================
> >>>>
> >>>> OBJS=test_single.o test_double.o
> >>>>
> >>>> all:$(OBJS)
> >>>>
> >>>>       ar -rua libtest.a $(OBJS)
> >>>>
> >>>> test_single.o : test.c
> >>>>
> >>>>         $(CC) -DCNAME=$(*F) -UDOUBLE -c $< -o $(@F)
> >>>>
> >>>> test_double.o : test.c
> >>>>
> >>>>         $(CC) -DCNAME=$(*F) -DDOUBLE -c $< -o $(@F)
> >>>>
> >>>>
> >>>> ============
> >>>>
> >>>> Thank you
> >>>>
> >>>> Xianyi
> >>>>
> >>>>
> >>>> --
> >>>>
> >>>> 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
> >>>
> >>>
> >>
> >>
> >> --
> >>
> >> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141129/e42754bb/attachment-0001.html>


More information about the CMake mailing list