[CMake] How about GNU Automatic Variables

J Decker d3ck0r at gmail.com
Fri Nov 28 10:03:14 EST 2014


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141128/420dcff0/attachment.html>


More information about the CMake mailing list