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 <[EMAIL PROTECTED]>:
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@cmake.org http://www.cmake.org/mailman/listinfo/cmake
-- Erk
#include <stdio.h> int main(int argc, char** argv) { int i = 0; ((char*)&i)[0] = 1; if (1 == i) { printf("LITTLE_ENDIAN\n"); } else { printf("BIG_ENDIAN\n"); } }
_______________________________________________ CMake mailing list CMake@cmake.org http://www.cmake.org/mailman/listinfo/cmake