Skip to content

cnruby/w3h1_cmake

 
 

Repository files navigation

Hello, Multiple Projects!

Creating a Solution with C++ Multiple Projects



@Gitter :gitter.im/cnruby
Code ID: basic_130
Code Name: Hello, Multiple Projects!

Youtube Video

TABLE of CONTENTS

About The Project

About The Project

#<!-- markdown-exec(cmd:cat docs/output/tree.txt) -->#
.
├── CMakeLists.txt
├── Lib
│  ├── CMakeLists.txt
│  ├── impl
│  │  └── hello.cxx
│  └── include
│     └── hello.hxx
└── Main
   │   ...
   ├── CMakeLists.txt
   └── src
      ├── CMakeLists.txt
      └── main.cxx
#<!-- /markdown-exec -->

The Folder's Structure

The One-Build of Project

_image

The Listfile of Folder './Main'

#<!-- markdown-exec(cmd:cat ./Main/CMakeLists.txt) -->#
cmake_minimum_required(VERSION 3.3)
project(cxx_main VERSION 0.1.0 LANGUAGES CXX DESCRIPTION "Hello, Multiple-Project's Main!" )

include("cmake/Initialize.cmake")
add_subdirectory(cmake)
include_directories(${PROJECT_CONIFG_DIR})

if(TARGET hello_lib)
  message(STATUS "The Library 'hello_lib' exists!")
  # Project "basic_113"
  include("src/integrate.cmake")
else()
  message(STATUS "The Library 'hello_lib' exists not.")
  # Project "basic_125"
  include("src/develop.cmake")
endif()
#<!-- /markdown-exec -->

The File 'integrate.cmake'

#<!-- markdown-exec(cmd:cat ./Main/src/integrate.cmake) -->#
add_executable(main_130 src/main.cxx)
# Method 1
target_link_libraries(main_130 hello_lib)

# Method 2
#add_library(Any::alias ALIAS hello_lib)
#target_link_libraries(main_130 Any::alias)
#<!-- /markdown-exec -->

Demonstrate The One-Build of Project

The Two-Builds of Project

_image

The Listfile of Folder './Main'

#<!-- markdown-exec(cmd:cat ./Main/CMakeLists.txt) -->#
cmake_minimum_required(VERSION 3.3)
project(cxx_main VERSION 0.1.0 LANGUAGES CXX DESCRIPTION "Hello, Multiple-Project's Main!" )

include("cmake/Initialize.cmake")
add_subdirectory(cmake)
include_directories(${PROJECT_CONIFG_DIR})

if(TARGET hello_lib)
  message(STATUS "The Library 'hello_lib' exists!")
  # Project "basic_113"
  include("src/integrate.cmake")
else()
  message(STATUS "The Library 'hello_lib' exists not.")
  # Project "basic_125"
  include("src/develop.cmake")
endif()
#<!-- /markdown-exec -->

The File 'develop.cmake'

#<!-- markdown-exec(cmd:cat ./Main/src/develop.cmake) -->#
add_executable(
  main_130 src/main.cxx
)
target_include_directories(
  main_130 PRIVATE
  ${LIB_INCLUDE_DIR}
)
target_link_libraries(
  main_130
  ${LIB_LIB_DIR}/libhello_lib.a
)
#<!-- /markdown-exec -->

Demonstrate The Two-Builds of Project

Final Summary

Final Summary

感谢大家观看!

@Gitter: gitter.im/cnruby

@Github: github.com/cnruby

@Twitter: twitter.com/cnruby

@Blogspot: cnruby.blogspot.com

References

Important

General

Requirements

Get The Code with Shell Commands

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