mirror of
https://github.com/ttroy50/cmake-examples.git
synced 2025-12-18 20:24:35 +03:00
Update to minimum CMake 3.5
And modernise some examples.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(cmake_examples_install)
|
||||
|
||||
@@ -6,34 +6,29 @@ project(cmake_examples_install)
|
||||
# Create a library
|
||||
############################################################
|
||||
|
||||
# Source files to be used in the library
|
||||
set(library_SOURCES
|
||||
#Generate the shared library from the library sources
|
||||
add_library(cmake_examples_inst SHARED
|
||||
src/Hello.cpp
|
||||
)
|
||||
|
||||
#Generate the shared library from the library sources
|
||||
add_library(cmake_examples_inst SHARED ${library_SOURCES})
|
||||
|
||||
|
||||
target_include_directories(cmake_examples_inst
|
||||
PUBLIC ${PROJECT_SOURCE_DIR}/include
|
||||
PUBLIC
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
############################################################
|
||||
# Create an executable
|
||||
############################################################
|
||||
|
||||
# Source fles for the binary
|
||||
set(binary_SOURCES
|
||||
# Add an executable with the above sources
|
||||
add_executable(cmake_examples_inst_bin
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
# Add an executable with the above sources
|
||||
add_executable(cmake_examples_inst_bin ${binary_SOURCES})
|
||||
|
||||
# link the new hello_library target with the hello_binary target
|
||||
target_link_libraries( cmake_examples_inst_bin
|
||||
PRIVATE cmake_examples_inst
|
||||
PRIVATE
|
||||
cmake_examples_inst
|
||||
)
|
||||
|
||||
############################################################
|
||||
@@ -49,6 +44,9 @@ install (TARGETS cmake_examples_inst_bin
|
||||
install (TARGETS cmake_examples_inst
|
||||
LIBRARY DESTINATION lib)
|
||||
|
||||
# Header files
|
||||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
|
||||
DESTINATION include)
|
||||
|
||||
# Config
|
||||
install (FILES cmake-examples.conf
|
||||
|
||||
@@ -17,7 +17,8 @@ $ tree
|
||||
├── cmake-examples.conf
|
||||
├── CMakeLists.txt
|
||||
├── include
|
||||
│ └── Hello.h
|
||||
│ └── installing
|
||||
│ └── Hello.h
|
||||
├── README.adoc
|
||||
└── src
|
||||
├── Hello.cpp
|
||||
@@ -26,7 +27,7 @@ $ tree
|
||||
|
||||
* link:CMakeLists.txt[] - Contains the CMake commands you wish to run
|
||||
* link:cmake-examples.conf[] - An example configuration file
|
||||
* link:include/Hello.h[] - The header file to include
|
||||
* link:include/installing/Hello.h[] - The header file to include
|
||||
* link:src/Hello.cpp[] - A source file to compile
|
||||
* link:src/main.cpp[] - The source file with main
|
||||
|
||||
@@ -72,6 +73,16 @@ install (TARGETS cmake_examples_inst
|
||||
----
|
||||
====
|
||||
|
||||
|
||||
[source,cmake]
|
||||
----
|
||||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
|
||||
DESTINATION include)
|
||||
----
|
||||
|
||||
Install the header files for developing against the +cmake_examples_inst+ library
|
||||
into the +${CMAKE_INSTALL_PREFIX}/include+ directory.
|
||||
|
||||
[source,cmake]
|
||||
----
|
||||
install (FILES cmake-examples.conf
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "Hello.h"
|
||||
#include "installing/Hello.h"
|
||||
|
||||
void Hello::print()
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "Hello.h"
|
||||
#include "installing/Hello.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Hello hi;
|
||||
hi.print();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user