-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
4 changed files
with
21 additions
and
6 deletions.
There are no files selected for viewing
16 changes: 13 additions & 3 deletions
16
cmake/org.eclipse.cdt.cmake.core/templates/simple/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
2
cmake/org.eclipse.cdt.cmake.core/templates/simple/config.h.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
4 changes: 3 additions & 1 deletion
4
cmake/org.eclipse.cdt.cmake.core/templates/simple/manifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |