mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Improve the CMake project wizard template
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.
This commit is contained in:
parent
95fb6ee72e
commit
1783120eb7
4 changed files with 21 additions and 6 deletions
|
@ -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}"}")
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
#define ${projectName?replace(" ", "_")}_VERSION_MAJOR @${projectName?replace(" ", "_")}_VERSION_MAJOR@
|
||||
#define ${projectName?replace(" ", "_")}_VERSION_MINOR @${projectName?replace(" ", "_")}_VERSION_MINOR@
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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>
|
Loading…
Add table
Reference in a new issue