[CMake] Finding out the Endianness of a system at CMake config time

Eric Noulard eric.noulard at gmail.com
Wed Nov 22 12:48:47 EST 2006


May be you could use TRY_RUN to detect endianity
with something like:

TRY_RUN(
  ENDIANESS_RESULT
  ENDIANESS_COMPILE
  /tmp/
  ${CMAKE_CURRENT_SOURCE_DIR}/make/endianess.c
  OUTPUT_VARIABLE ENDIANESS_OUT
  )


MESSAGE(STATUS "ENDIANITY is :${ENDIANESS_OUT}")

endianess.c is attached.

The trouble I have is that I expected to have
my "endianess" program output in ${ENDIANESS_OUT}
but I get too much including
compilation process ouput.

>>>>>>>>>
-- ENDIANITY is :gmake[1]: Entering directory `/tmp/CMakeFiles/CMakeTmp'
/usr/bin/gmake -f CMakeFiles/cmTryCompileExec.dir/build.make
CMakeFiles/cmTryCompileExec.dir/build
gmake[2]: Entering directory `/tmp/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /tmp/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object
CMakeFiles/cmTryCompileExec.dir/home/noularde/TSP/tsp_all/tsp/src/util/libutil/endianess.o
/usr/bin/gcc   -o
CMakeFiles/cmTryCompileExec.dir/home/noularde/TSP/tsp_all/tsp/src/util/libutil/endianess.o
  -c /home/noularde/TSP/tsp_all/tsp/src/util/libutil/endianess.c
Linking C executable cmTryCompileExec
/usr/bin/cmake -P CMakeFiles/cmTryCompileExec.dir/cmake_clean_target.cmake
/usr/bin/gcc       -fPIC
"CMakeFiles/cmTryCompileExec.dir/home/noularde/TSP/tsp_all/tsp/src/util/libutil/endianess.o"
  -o cmTryCompileExec -rdynamic
gmake[2]: Leaving directory `/tmp/CMakeFiles/CMakeTmp'
gmake[1]: Leaving directory `/tmp/CMakeFiles/CMakeTmp'
LITTLE_ENDIAN
>>>>>>>>>

I have played with STRING(REFEX MATCH ...)
with no success.

I never use TRY_RUN but now that I have tried it I wonder
how to use it if I am not able to separate compile output
from RUN output?


2006/11/22, Mike Jackson <mike.jackson at imts.us>:
> I have recently joined a project where I am to do some coding. The code base
> is cross platform HPC type code and the original coders have defined their
> own little/big endian #defines (L_ENDIAN & B_ENDIAN). They pass this into
> the compiler via -DL_ENDIAN during compiles.
>
> Is there a way to automatically have cmake figure this out for me? Right now
> I have an OPTION(....) clause in my CMakeLists.txt file to select the right
> value.. which is stupid and error prone but it worked to boot strap the
> process for the moment.
>
> Any hints would be appreciated..
>
>
>
> --
> Mike Jackson   Senior Research Engineer
> Innovative Management & Technology Services
>
>
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>
>


-- 
Erk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: endianess.c
Type: text/x-csrc
Size: 183 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20061122/d018e6e6/endianess.c


More information about the CMake mailing list