Skip to content

cnruby/w3h1_cmake

 
 

Repository files navigation

Hello, Object Library!

How to Create and Use The Object File in CMake



@Gitter :gitter.im/cnruby
Code ID: basic_137
Code Name: Hello, Object Library!

Youtube Video

Short Video

TABLE of CONTENTS

About The Project basic_137

About The Project

About The Project basic_137

Explain The C++ Library Obejct of CMake

// ./src/main.cxx
#include <iostream>
#include "config.hxx"
#include "header.hxx"
#include "macro.hxx"

int main(int, char**) {
  std::cout << "Project ID:\t\t\t" << PROJECT_NAME << std::endl;
  std::cout << "Project Code:\t\t\t" << PROJECT_DESCRIPTION << std::endl;
  std::cout << "Project Version:\t\t" << MACRO_VERSION << std::endl << std::endl;

  Header header;
  header.hello("Library");

Explain C++ and CMake Code

# ./src/one.cmake
add_executable(
  ${MAIN_NAME}_one
  main.cxx
)

# ./src/three.cmake
add_library(
  ${MAIN_NAME}_o
  OBJECT main.cxx
)
add_executable(
  ${MAIN_NAME}_three
)
target_link_libraries(
  ${MAIN_NAME}_three
  ${LIB_NAME}_o ${MAIN_NAME}_o
)

Explain Main's CMake Code

# ./lib/one.cmake
add_library(
  ${LIB_NAME}_a
  STATIC header.cxx
)

# ./lib/three.cmake
add_library(
  ${LIB_NAME}_o
  OBJECT header.cxx
)
add_library(
  ${LIB_NAME}_ar STATIC
)
target_link_libraries(
  ${LIB_NAME}_ar
  ${LIB_NAME}_o
)

Explain Library's CMake Code

A Demonstration of Building Project

About The Project basic_137

The Difference for two build methods

About The Project basic_137

Final Summary

感谢大家观看!

@Gitter: gitter.im/cnruby

@Github: github.com/cnruby

@Twitter: twitter.com/cnruby

@Blogspot: cnruby.blogspot.com

References

Requirements

Get The Code with Shell Commands

git clone https://github.com/cnruby/w3h1_cmake.git basic_137
cd basic_137
git checkout basic_137
code .

The Structure of Folder

# ./docs/output/tree.txt
.
├── cmake
│  ├── CMakeLists.txt
│  ├── config.h.in
│  ├── GetOutput.cmake
│  └── Initialize.cmake
├── CMakeLists.txt
├── config
   ├── config.hxx
│  └── macro.hxx
└── src
   ├── CMakeLists.txt
   ├── main.cxx
   ├── one.cmake
   └── three.cmake