CMake : how to use bash command in CMakeLists.txt

前端 未结 2 1855
离开以前
离开以前 2021-02-04 01:23

I\'m wondering how I can use bash command in CMakeLists.txt. What I want is to get the number of processor retrieved using :

export variable=`getconf _NPROCESSOR         


        
相关标签:
2条回答
  • 2021-02-04 01:39

    This seems to do the trick, and saves the "set" too.

    execute_process(COMMAND getconf  _NPROCESSORS_ONLN
                    OUTPUT_VARIABLE NB_PROCESSOR)
    
    0 讨论(0)
  • 2021-02-04 01:54

    Use the EXEC_PROGRAM command and then use the CACHE option of the SET command to save the output to a variable like GTK_PKG_FLAGS. Then use the SET command to add the value. Something like this:

    IF(NOT GTK_PKG_FLAGS)
       EXEC_PROGRAM(pkg-config ARGS --cflags --libs gtkmm
                    OUTPUT_VARIABLE GTK_PKG_FLAGS)
       SET(GTK_PKG_FLAGS "${GTK_PKG_FLAGS}" CACHE STRING "GTK Flags")
    ENDIF(NOT GTK_PKG_FLAGS)
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GTK_PKG_FLAGS}")
    

    Links: http://www.cmake.org/pipermail/cmake/2005-January/006051.html

    0 讨论(0)
提交回复
热议问题