mirror of
1
0
Fork 0

Fixing #8, and starting basic example

This commit is contained in:
Henry Fredrick Schreiner 2019-02-21 22:28:07 +01:00
parent c695ac4669
commit 7c05525f46
7 changed files with 63 additions and 2 deletions

View File

@ -39,7 +39,7 @@ Here, the generation happens after `some_target` is complete, and happens when y
## Included common utilities
A useful tool in writing CMake builds that work cross-platform is `cmake -E <mode>` (seen in CMake files as `${CMAKE_COMMAND} -E`). This mode allows CMake to do a variety of things without calling system tools explicitly, like `copy`, `make_directory`, and `remove`. It is mostly used for the build time commands. Note that the very useful `create_symlink` mode only works on Unix systems. [See the docs](https://cmake.org/cmake/help/latest/manual/cmake.1.html#command-line-tool-mode).
A useful tool in writing CMake builds that work cross-platform is `cmake -E <mode>` (seen in CMake files as `${CMAKE_COMMAND} -E`). This mode allows CMake to do a variety of things without calling system tools explicitly, like `copy`, `make_directory`, and `remove`. It is mostly used for the build time commands. Note that the very useful `create_symlink` mode used to be Unix only, but was added for Windows in CMake 3.13. [See the docs](https://cmake.org/cmake/help/latest/manual/cmake.1.html#command-line-tool-mode).
[execute_process]: https://cmake.org/cmake/help/latest/command/execute_process.html

View File

@ -155,7 +155,7 @@ shiny new Python find module (2 and 3 versions too), and many more.
* `string(JOIN` and `list(JOIN`, and `list(TRANSFORM`
* `file(TOUCH` and `file(GLOB CONFIGURE_DEPENDS`
* C++20 support
* CUDA as a language improvements: CUDA < 7.5 supported
* CUDA as a language improvements: CUDA 7 and 7.5 now supported
* Support for OpenMP on macOS (command line only)
* Several new properties and property initializers
* CPack finally reads `CMAKE_PROJECT_VERSION` variables

View File

@ -4,6 +4,8 @@ project(ModernCMakeExamples)
enable_testing()
add_subdirectory(simple-project)
add_subdirectory(root-usefile)
add_subdirectory(root-simple)
add_subdirectory(root-simple-3.11)

View File

@ -0,0 +1,36 @@
# Almost all CMake files should start with this
# You should always specify a range with the newest
# and oldest tested versions of CMake. This will ensure
# you pick up the best policies.
cmake_minimum_required(VERSION 3.1...3.13)
# This is your project statement. You should always list languages;
# Listing the version is nice here since it sets lots of useful variables
project(ModernCMakeExample VERSION 1.0 LANGUAGES CXX)
# If you set any CMAKE_ variables, that can go here.
# (But usually don't do this, except maybe for C++ standard)
# Find packages go here.
# You should usually split this into folders, but this is a simple example
# This is a "default" library, and will match the *** variable setting.
# Other common choices are STATIC, SHARED, and MODULE
# Including header files here helps IDEs but is not required.
# Output libname matches target name, with the usual extensions on your system
add_library(MyLibExample simple_lib.cpp simple_lib.hpp)
# Link each target with other targets or add options, etc.
# Adding something we can run - Output name matches target name
add_executable(MyExample simple_example.cpp)
# Make sure you link your targets with this command. It can also link libraries and
# even flags, so linking a target that does not exist will not give a configure-time error.
target_link_libraries(MyExample PRIVATE MyLibExample)
# This part is so the Modern CMake book can verify this example builds. For your code,
# you'll probably want tests too
enable_testing()
add_test(NAME MyExample COMMAND MyExample)

View File

@ -0,0 +1,13 @@
// This is an example file as part of Modern-CMake
#include "simple_lib.hpp"
#include <iostream>
int main() {
std::cout << "Simple example C++ compiled correctly and ran." << std::endl;
std::cout << simple_lib_function() << std::endl;
return 0;
}

View File

@ -0,0 +1,5 @@
#include <string>
std::string simple_lib_function() {
return "Compiled in library";
}

View File

@ -0,0 +1,5 @@
#pragma once
#include <string>
std::string simple_lib_function();