Andy Niu �����ĵ�

Andy Niu

Andy Niu Help  1.0.0.0
Cmake

变量

 cmakeע������
 
 ָ����װĿ¼CMAKE_INSTALL_PREFIX
 
 cmakeʾ��
 

详细描述

变量说明

cmakeʾ��
1��һ������£��������ֶ���дmakefile�ļ���Ȼ��ִ��make����Ŀ���ļ���
2����û�а취����makefile�ļ��أ�
    �����cmake��cmake�����ļ�CMakeLists.txt�������ļ�makefile
3��ʾ�����£�
    niuzibin@ubuntu:~/work/test1/cmake$ ll
    total 16
    drwxrwxr-x 2 niuzibin niuzibin 4096 Apr  9 00:17 ./
    drwxrwxr-x 4 niuzibin niuzibin 4096 Apr  9 00:11 ../
    -rw-rw-r-- 1 niuzibin niuzibin   45 Apr  9 00:12 CMakeLists.txt
    -rw-rw-r-- 1 niuzibin niuzibin   89 Apr  9 00:12 hello.c
    niuzibin@ubuntu:~/work/test1/cmake$ more hello.c 
    #include <stdio.h>
    int main(void)
    {
            printf("Hello world\n");
            return 0;
    }
    niuzibin@ubuntu:~/work/test1/cmake$ more CMakeLists.txt 
    PROJECT(HELLO)
    ADD_EXECUTABLE(hello hello.c)
4��ִ��cmake�����£�
    niuzibin@ubuntu:~/work/test1/cmake$ cmake CMakeLists.txt 
    -- The C compiler identification is GNU 4.8.4
    -- The CXX compiler identification is GNU 4.8.4
    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/niuzibin/work/test1/cmake
    niuzibin@ubuntu:~/work/test1/cmake$ ll
    total 44
    drwxrwxr-x 3 niuzibin niuzibin  4096 Apr  9 00:18 ./
    drwxrwxr-x 4 niuzibin niuzibin  4096 Apr  9 00:11 ../
    -rw-rw-r-- 1 niuzibin niuzibin 11953 Apr  9 00:18 CMakeCache.txt
    drwxrwxr-x 5 niuzibin niuzibin  4096 Apr  9 00:18 CMakeFiles/
    -rw-rw-r-- 1 niuzibin niuzibin  1603 Apr  9 00:18 cmake_install.cmake
    -rw-rw-r-- 1 niuzibin niuzibin    45 Apr  9 00:12 CMakeLists.txt
    -rw-rw-r-- 1 niuzibin niuzibin    89 Apr  9 00:12 hello.c
    -rw-rw-r-- 1 niuzibin niuzibin  4592 Apr  9 00:18 Makefile
5��������һ�ѵ��ļ�����������ֻ��Ҫ���� Makefile�ļ������ɵ�Makefile�ļ����ݺܶ��ȫ�棬ִ��һ��make�����£�
    niuzibin@ubuntu:~/work/test1/cmake$ make
    Scanning dependencies of target hello
    [100%] Building C object CMakeFiles/hello.dir/hello.c.o
    Linking C executable hello
    [100%] Built target hello
    niuzibin@ubuntu:~/work/test1/cmake$ ./hello 
    Hello world
cmakeע������
1��ָ����ִ�Сд�����������д�����£�
    message(STATUS "the binary dir is ${PROJECT_BINARY_DIR}")
    MESSAGE(STATUS "the binary dir is ${PROJECT_BINARY_DIR}")
    message��Сд��OK������STATUS��PROJECT_BINARY_DIR�����д
    Ϊ�˷����Ķ����Ƽ�д�����£�
    message(STATUS "the binary dir is ${PROJECT_BINARY_DIR}")
    ע������֪��ij��������ȡֵʱ��ʹ��message��ӡ�����Ǹ��ð취��
ָ����װĿ¼CMAKE_INSTALL_PREFIX
1��cmakeָ����װĿ¼��ʹ��CMAKE_INSTALL_PREFIX��ָ����CMAKE_INSTALL_PREFIXĬ��ֵ�� /usr/local/
2����һ�ְ취��
    cmake -DCMAKE_INSTALL_PREFIX=/usr ../
3���ڶ��ְ취��
    �޸�cmake�ļ������룺SET(CMAKE_INSTALL_PREFIX < install_path >) 
    �ر�ע�⣬ʹ�����ְ취������ Ҫ���� PROJECT(< project_name >) ֮�󣬷��߿��ܲ������á�
Copyright (c) 2015~2016, Andy Niu @All rights reserved. By Andy Niu Edit.