Skip to content

Commit

Permalink
Improve the CMake project wizard template
Browse files Browse the repository at this point in the history
Fixes out-of-the-box deprecation warnings, the template now specifies a
minimum CMake version of 3.10

Allows project names containing spaces by using freemarker syntax to
remove them where necessary in the CMakeLists.txt file.

Demonstrates how to implement the common idiom of configuration header
files.
  • Loading branch information
mbooth101 committed Oct 17, 2022
1 parent 95fb6ee commit 1783120
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
16 changes: 13 additions & 3 deletions cmake/org.eclipse.cdt.cmake.core/templates/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
cmake_minimum_required (VERSION 2.6)
cmake_minimum_required(VERSION 3.10)

project (${projectName})
# Set some basic project attributes
project (${projectName?replace(" ", "_")}
VERSION 0.1
DESCRIPTION "A Hello World Project")

add_executable(${projectName} ${projectName}.cpp)
# This project will output an executable file
add_executable(${r"${PROJECT_NAME}"} ${projectName?replace(" ", "_")}.cpp)

# Create a simple configuration header
configure_file(config.h.in config.h)

# Include the configuration header in the build
target_include_directories(${r"${PROJECT_NAME}"} PUBLIC "${r"${PROJECT_BINARY_DIR}"}")
2 changes: 2 additions & 0 deletions cmake/org.eclipse.cdt.cmake.core/templates/simple/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define ${projectName?replace(" ", "_")}_VERSION_MAJOR @${projectName?replace(" ", "_")}_VERSION_MAJOR@
#define ${projectName?replace(" ", "_")}_VERSION_MINOR @${projectName?replace(" ", "_")}_VERSION_MINOR@
5 changes: 3 additions & 2 deletions cmake/org.eclipse.cdt.cmake.core/templates/simple/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <iostream>
using namespace std;
#include "config.h"

int main(int argc, char **argv) {
cout << "Hello world";
std::cout << "Hello World" << std::endl;
std::cout << "Version " << ${projectName?replace(" ", "_")}_VERSION_MAJOR << "." << ${projectName?replace(" ", "_")}_VERSION_MINOR << std::endl;
return 0;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<templateManifest>
<file src="/templates/simple/CMakeLists.txt"
dest="/${projectName}/CMakeLists.txt"/>
<file src="/templates/simple/config.h.in"
dest="/${projectName}/config.h.in"/>
<file src="/templates/simple/main.cpp"
dest="/${projectName}/${projectName}.cpp"
dest="/${projectName}/${projectName?replace(" ", "_")}.cpp"
open="true"/>
</templateManifest>

0 comments on commit 1783120

Please sign in to comment.