码迷,mamicode.com
首页 > 其他好文 > 详细

cmake语法学习 - 01 Basic - E- installing

时间:2020-04-25 16:48:02      阅读:73      评论:0      收藏:0      [点我收藏+]

标签:project   can   under   some   points   free   ble   stand   enc   

cmake_minimum_required(VERSION 3.5)

project(cmake_examples_install)

############################################################
# Create a library
############################################################

#Generate the shared library from the library sources
add_library(cmake_examples_inst SHARED
    src/Hello.cpp
)

target_include_directories(cmake_examples_inst
    PUBLIC 
        ${PROJECT_SOURCE_DIR}/include
)

############################################################
# Create an executable
############################################################

# Add an executable with the above sources
add_executable(cmake_examples_inst_bin
    src/main.cpp
)

# link the new hello_library target with the hello_binary target
target_link_libraries( cmake_examples_inst_bin
    PRIVATE 
        cmake_examples_inst
)

############################################################
# Install
############################################################

message("CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")


# Binaries
install (TARGETS cmake_examples_inst_bin
    DESTINATION bin)

# Library
# Note: may not work on windows
install (TARGETS cmake_examples_inst
    LIBRARY DESTINATION lib)

# Header files
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ 
    DESTINATION include)

# Config
install (FILES cmake-examples.conf
    DESTINATION etc)

 

 

Before diving into the code, please make sure you really uderstand what is intalling and why to do that.

Install a libiary (like OpenCV) to system  ( some specific paths ), and after that, you can import them to you project by "find_packge()" in CMake.

 

*

install (TARGETS cmake_examples_inst_bin
    DESTINATION bin)

-TARGETS is followed by the file to stall

-DESTINATION is followed by the folder.

That means, the final output path will be "${CMAKE_BINARY_DIR}/bin"

 

For beginners, the most confused thing will be where is the path to install, when did you set that, and where in the CMakeList.txt.

The answer is, there are some default paths in CMake marked by some kept variables.

So the path settings are quite ambigous. (At least it is my opinion.)

For a better understanding, I recommend you to message() some path-variables in CMake and remember them. We have limited options in this points. Please check the website of CMake.

 

 

*

target_include_directories(cmake_examples_inst

    PUBLIC 
        ${PROJECT_SOURCE_DIR}/include
)

- After setting the include paths, you can open the head files #include in you file. But of course, you need to have an IDE to support importing project from CMkeList.txt, like CLion. But it is no free which only offers me 30 days to use.

Waitting for recommendations :)

 

cmake语法学习 - 01 Basic - E- installing

标签:project   can   under   some   points   free   ble   stand   enc   

原文地址:https://www.cnblogs.com/alexYuin/p/12773615.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!