Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lennart Nachtigall
CmakeProjectGenerator
Commits
a8e948cc
Commit
a8e948cc
authored
Apr 16, 2015
by
Lennart Nachtigall
Browse files
added more features
parent
a5994926
Changes
13
Hide whitespace changes
Inline
Side-by-side
Cmake-Project-Generator/Cmake-Project-Generator.sln
0 → 100644
View file @
a8e948cc
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cmake-Project-Generator", "Cmake-Project-Generator\Cmake-Project-Generator.csproj", "{58FE24D7-ED03-46B5-8F3E-3E52AF821089}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{58FE24D7-ED03-46B5-8F3E-3E52AF821089}.Debug|x86.ActiveCfg = Debug|x86
{58FE24D7-ED03-46B5-8F3E-3E52AF821089}.Debug|x86.Build.0 = Debug|x86
{58FE24D7-ED03-46B5-8F3E-3E52AF821089}.Release|x86.ActiveCfg = Release|x86
{58FE24D7-ED03-46B5-8F3E-3E52AF821089}.Release|x86.Build.0 = Release|x86
EndGlobalSection
EndGlobal
Cmake-Project-Generator/Cmake-Project-Generator.userprefs
0 → 100644
View file @
a8e948cc
<Properties StartupItem="Cmake-Project-Generator/Cmake-Project-Generator.csproj" />
\ No newline at end of file
Cmake-Project-Generator/Cmake-Project-Generator/Cmake-Project-Generator.csproj
0 → 100644
View file @
a8e948cc
<?xml version="1.0" encoding="utf-8"?>
<Project
DefaultTargets=
"Build"
ToolsVersion=
"4.0"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
x86
</Platform>
<ProjectGuid>
{58FE24D7-ED03-46B5-8F3E-3E52AF821089}
</ProjectGuid>
<OutputType>
Exe
</OutputType>
<RootNamespace>
CmakeProjectGenerator
</RootNamespace>
<AssemblyName>
Cmake-Project-Generator
</AssemblyName>
<TargetFrameworkVersion>
v4.5
</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|x86' "
>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug
</OutputPath>
<DefineConstants>
DEBUG;
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<Externalconsole>
true
</Externalconsole>
<PlatformTarget>
x86
</PlatformTarget>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|x86' "
>
<DebugType>
full
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release
</OutputPath>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<Externalconsole>
true
</Externalconsole>
<PlatformTarget>
x86
</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"System"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildBinPath)\Microsoft.CSharp.targets"
/>
</Project>
\ No newline at end of file
Cmake-Project-Generator/Cmake-Project-Generator/Program.cs
0 → 100644
View file @
a8e948cc
using
System
;
using
System.IO
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Runtime
;
namespace
CmakeProjectGenerator
{
class
MainClass
{
static
string
ProjectName
;
static
string
ProjectBasePath
;
static
List
<
string
>
CompilerFlags
=
new
List
<
string
>();
static
string
BinaryOutputDir
;
static
string
CodeDirectory
;
static
List
<
string
>
SubDirectories
=
new
List
<
string
>();
static
string
ProjectPath
;
static
List
<
string
>
IncludeDirs
=
new
List
<
string
>
();
static
bool
enableAssemlber
=
false
;
public
static
bool
CheckForYN
()
{
string
input
=
""
;
while
(
input
!=
"Y"
||
input
!=
"N"
)
{
input
=
Console
.
ReadLine
();
if
(
input
==
"Y"
||
input
==
"N"
)
break
;
else
Console
.
WriteLine
(
"Enter [Y] or [N]"
);
}
if
(
input
==
"Y"
)
return
true
;
else
return
false
;
}
public
static
void
Main
(
string
[]
args
)
{
Console
.
WriteLine
(
"Hello welcome to the cmake project generator"
);
Console
.
WriteLine
(
"Specify ProjectName:"
);
ProjectName
=
Console
.
ReadLine
();
Console
.
WriteLine
(
"Specify ProjectPath:"
);
ProjectBasePath
=
Console
.
ReadLine
();
Console
.
WriteLine
(
"Add Debug option? [Y/N]"
);
if
(
CheckForYN
())
{
CompilerFlags
.
Add
(
"-g"
);
}
Console
.
WriteLine
(
"Add C++11 option? [Y/N]"
);
if
(
CheckForYN
())
{
CompilerFlags
.
Add
(
"-std=c++11"
);
}
Console
.
WriteLine
(
"Add -Wall option? [Y/N]"
);
if
(
CheckForYN
())
{
CompilerFlags
.
Add
(
"-Wall"
);
}
Console
.
WriteLine
(
"Enable Assemlber support? [Y/N]"
);
if
(
CheckForYN
())
{
enableAssemlber
=
true
;
}
//Console.WriteLine ("Which one is the code directory (relative path)");
//CodeDirectory = Console.ReadLine ();
string
subDir
=
""
;
Console
.
WriteLine
(
"Add any sub directories? [Y/N]"
);
if
(
Console
.
ReadLine
()
==
"Y"
)
{
Console
.
WriteLine
(
"Specify all subdirectories, relative to the src dir, Enter [N] if you had enough"
);
while
(
subDir
!=
"N"
)
{
//Console.WriteLine ("Specify all subdirectories, relative to the src dir, Enter [N] if you had enough");
subDir
=
Console
.
ReadLine
();
if
(
subDir
==
"N"
||
subDir
==
"n"
)
break
;
SubDirectories
.
Add
(
subDir
);
}
Console
.
WriteLine
(
"This tool will automatically create the subdirectories and create a CmakeLists.txt file in them"
);
}
Console
.
WriteLine
(
"Create project ? [Y/N]"
);
if
(
Console
.
ReadLine
()
==
"Y"
)
{
ProjectPath
=
Path
.
Combine
(
ProjectBasePath
,
ProjectName
);
Directory
.
CreateDirectory
(
ProjectPath
);
Directory
.
CreateDirectory
(
Path
.
Combine
(
ProjectPath
,
"src"
));
Directory
.
CreateDirectory
(
Path
.
Combine
(
ProjectPath
,
"bin"
));
Directory
.
CreateDirectory
(
Path
.
Combine
(
ProjectPath
,
"build"
));
Directory
.
CreateDirectory
(
Path
.
Combine
(
ProjectPath
,
"lib"
));
Directory
.
CreateDirectory
(
Path
.
Combine
(
ProjectPath
,
"doc"
));
Directory
.
CreateDirectory
(
Path
.
Combine
(
ProjectPath
,
"scripts"
));
Console
.
WriteLine
(
"Created Directories"
);
StreamWriter
cmakeWriter
=
new
StreamWriter
(
Path
.
Combine
(
ProjectPath
,
"CMakeLists.txt"
));
cmakeWriter
.
WriteLine
(
"cmake_minimum_required(VERSION 2.8)"
);
cmakeWriter
.
WriteLine
();
cmakeWriter
.
WriteLine
(
"set (PROJECT_NAME_STR "
+
ProjectName
+
")"
);
cmakeWriter
.
WriteLine
(
"#Specify project name and tell cmake that we have c and cpp files"
);
cmakeWriter
.
WriteLine
(
"project(${PROJECTNAME_STR} C CXX)"
);
cmakeWriter
.
WriteLine
();
if
(
enableAssemlber
)
{
cmakeWriter
.
WriteLine
(
"ENABLE_LANGUAGE(ASM)"
);
}
cmakeWriter
.
WriteLine
();
cmakeWriter
.
WriteLine
(
"#Set output path"
);
cmakeWriter
.
WriteLine
(
"set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin CACHE PATH \"Output directory for libraries\")"
);
cmakeWriter
.
WriteLine
(
"set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin CACHE PATH \"Output directory for executables\")"
);
cmakeWriter
.
WriteLine
();
string
definitions
=
""
;
foreach
(
var
item
in
CompilerFlags
)
{
definitions
+=
" "
+
item
;
}
cmakeWriter
.
WriteLine
(
"#Set compiler flags. More details: http://stackoverflow.com/questions/11783932/how-to-add-linker-or-compile-flag-in-cmake-file"
);
cmakeWriter
.
WriteLine
(
"add_definitions("
+
definitions
+
")"
);
cmakeWriter
.
WriteLine
();
CodeDirectory
=
Path
.
Combine
(
ProjectPath
,
"src"
);
cmakeWriter
.
WriteLine
(
"#add code dir as subdir"
);
cmakeWriter
.
WriteLine
(
"add_subdirectory(${PROJECT_SOURCE_DIR}/src/)"
);
cmakeWriter
.
WriteLine
();
IncludeDirs
.
Add
(
"${PROJECT_SOURCE_DIR}/src"
);
foreach
(
var
item
in
SubDirectories
)
{
IncludeDirs
.
Add
(
"${PROJECT_SOURCE_DIR}/src/"
+
item
);
}
string
include
=
""
;
foreach
(
var
item
in
IncludeDirs
)
{
include
+=
" "
+
item
;
}
cmakeWriter
.
WriteLine
(
"#tell cmake which directories we have for our include files"
);
cmakeWriter
.
WriteLine
(
"include_directories("
+
include
+
")"
);
cmakeWriter
.
WriteLine
();
cmakeWriter
.
WriteLine
();
cmakeWriter
.
WriteLine
(
"#tell cmake we want a executable"
);
cmakeWriter
.
WriteLine
(
"add_executable(${PROJECT_NAME_STR}_exec ${PROJECT_SOURCE_DIR}/src/main.cpp)"
);
cmakeWriter
.
WriteLine
();
cmakeWriter
.
WriteLine
(
"#tell cmake which parts needs to be linked. If experience linker problems it's wise to change the linking order"
);
cmakeWriter
.
WriteLine
(
"target_link_libraries(${PROJECT_NAME_STR}_exec root_lib"
);
foreach
(
var
item
in
SubDirectories
)
{
cmakeWriter
.
WriteLine
(
item
);
}
cmakeWriter
.
WriteLine
(
")"
);
cmakeWriter
.
Close
();
StreamWriter
mainWriter
=
new
StreamWriter
(
Path
.
Combine
(
CodeDirectory
,
"main.cpp"
));
mainWriter
.
WriteLine
(
"#include<iostream>"
);
mainWriter
.
WriteLine
(
"int main(void)"
);
mainWriter
.
WriteLine
(
"{"
);
mainWriter
.
WriteLine
(
"std::cout << \"hello\";"
);
mainWriter
.
WriteLine
(
"}"
);
mainWriter
.
Close
();
StreamWriter
exampleWriter
=
new
StreamWriter
(
Path
.
Combine
(
CodeDirectory
,
"example.cpp"
));
exampleWriter
.
WriteLine
(
"//This is an example file so that the compilation of the empty project will succeed, you can remove it"
);
exampleWriter
.
WriteLine
(
"#include<iostream>"
);
exampleWriter
.
WriteLine
(
"int test(void)"
);
exampleWriter
.
WriteLine
(
"{"
);
exampleWriter
.
WriteLine
(
"std::cout << \"hello\";"
);
exampleWriter
.
WriteLine
(
"}"
);
exampleWriter
.
Close
();
StreamWriter
cmakeSrcWriter
=
new
StreamWriter
(
Path
.
Combine
(
CodeDirectory
,
"CMakeLists.txt"
));
cmakeSrcWriter
.
WriteLine
(
"include_directories(${CMAKE_CURRENT_SOURCE_DIR})"
);
foreach
(
var
item
in
SubDirectories
)
{
Directory
.
CreateDirectory
(
Path
.
Combine
(
CodeDirectory
,
item
));
cmakeSrcWriter
.
WriteLine
(
"add_subdirectory(${PROJECT_SOURCE_DIR}/src/"
+
item
+
")"
);
}
cmakeSrcWriter
.
WriteLine
(
"file(GLOB SRC_FILES ./*.c*)"
);
cmakeSrcWriter
.
WriteLine
(
"list(REMOVE_ITEM SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)"
);
cmakeSrcWriter
.
WriteLine
(
"MESSAGE(${SRC_FILES})"
);
cmakeSrcWriter
.
WriteLine
(
"add_library(root_lib"
);
cmakeSrcWriter
.
WriteLine
(
"${SRC_FILES}"
);
cmakeSrcWriter
.
WriteLine
(
")"
);
cmakeSrcWriter
.
Close
();
foreach
(
var
item
in
SubDirectories
)
{
StreamWriter
subDirWriter
=
new
StreamWriter
(
Path
.
Combine
(
CodeDirectory
,
Path
.
Combine
(
item
,
"CMakeLists.txt"
)));
subDirWriter
.
WriteLine
(
"include_directories(${CMAKE_CURRENT_SOURCE_DIR})"
);
subDirWriter
.
WriteLine
(
"file(GLOB SRC_FILES ./*.c*)"
);
subDirWriter
.
WriteLine
(
"add_library("
+
item
);
subDirWriter
.
WriteLine
(
"${SRC_FILES}"
);
subDirWriter
.
WriteLine
(
")"
);
subDirWriter
.
Close
();
}
foreach
(
var
item
in
SubDirectories
)
{
StreamWriter
subDirCodeWriter
=
new
StreamWriter
(
Path
.
Combine
(
CodeDirectory
,
Path
.
Combine
(
item
,
item
+
".cpp"
)));
subDirCodeWriter
.
WriteLine
(
"//This is an example file so that the compilation of the empty project will succeed, you can remove it"
);
subDirCodeWriter
.
WriteLine
(
"#include<iostream>"
);
subDirCodeWriter
.
WriteLine
(
"int test(void)"
);
subDirCodeWriter
.
WriteLine
(
"{"
);
subDirCodeWriter
.
WriteLine
(
"std::cout << \"hello\";"
);
subDirCodeWriter
.
WriteLine
(
"}"
);
subDirCodeWriter
.
Close
();
}
Console
.
WriteLine
(
"Now open a console an do:"
);
Console
.
WriteLine
(
"cd "
+
ProjectPath
+
"/build"
);
Console
.
WriteLine
(
"cmake .."
);
Console
.
WriteLine
(
"make"
);
Console
.
WriteLine
(
"Do you want me to run this ? [Y/N]"
);
if
(
CheckForYN
())
{
Process
cmakeP
=
new
Process
();
cmakeP
.
StartInfo
=
new
ProcessStartInfo
(
"cmake"
){
WorkingDirectory
=
Path
.
Combine
(
ProjectPath
,
"build"
)
,
Arguments
=
".."
};
cmakeP
.
Start
();
cmakeP
.
WaitForExit
();
Process
makeP
=
new
Process
();
makeP
.
StartInfo
=
new
ProcessStartInfo
(
"make"
){
WorkingDirectory
=
Path
.
Combine
(
ProjectPath
,
"build"
)
};
makeP
.
Start
();
makeP
.
WaitForExit
();
}
}
}
}
}
Cmake-Project-Generator/Cmake-Project-Generator/Properties/AssemblyInfo.cs
0 → 100644
View file @
a8e948cc
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[
assembly
:
AssemblyTitle
(
"Cmake-Project-Generator"
)]
[
assembly
:
AssemblyDescription
(
""
)]
[
assembly
:
AssemblyConfiguration
(
""
)]
[
assembly
:
AssemblyCompany
(
""
)]
[
assembly
:
AssemblyProduct
(
""
)]
[
assembly
:
AssemblyCopyright
(
"firesurfer"
)]
[
assembly
:
AssemblyTrademark
(
""
)]
[
assembly
:
AssemblyCulture
(
""
)]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[
assembly
:
AssemblyVersion
(
"1.0.*"
)]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
Cmake-Project-Generator/Cmake-Project-Generator/bin/Debug/Cmake-Project-Generator.exe
0 → 100755
View file @
a8e948cc
File added
Cmake-Project-Generator/Cmake-Project-Generator/bin/Debug/Cmake-Project-Generator.exe.mdb
0 → 100644
View file @
a8e948cc
File added
Cmake-Project-Generator/Cmake-Project-Generator/bin/Debug/~/testAbc/CMakeLists.txt
0 → 100644
View file @
a8e948cc
cmake_minimum_required
(
VERSION 2.8
)
set PROJECT_NAME_STR testAbc
set
(
LIBRARY_OUTPUT_PATH
${
PROJECT_SOURCE_DIR
}
/bin CACHE PATH
"Output directory for libraries"
)
set
(
EXECUTABLE_OUTPUT_PATH
${
PROJECT_SOURCE_DIR
}
/bin CACHE PATH
"Output directory for executables"
)
add_definitions
(
-g -std=c++11 -Wall
)
#Get all files in src dir
file
(
GLOB SRC_FILES {CMAKE_CURRENT_SOURCE_DIR}/src/*.c*
)
list
(
REMOVE_ITEM SRC_FILES main.cpp
)
add_library
(
root_lib
${
SRC_FILES
}
)
add_executable
(
${
PROJECT_NAME_STR
}
_exec
${
PROJECT_SOURCE_DIR
}
/src/main.cpp
)
target_link_libraries
(
${
PROJECT_NAME_STR
}
_exec root_lib
)
Cmake-Project-Generator/Cmake-Project-Generator/bin/Debug/~/testAbc/src/main.cpp
0 → 100644
View file @
a8e948cc
#include
<iostream>
int
main
(
void
)
{
std
::
cout
<<
"hello"
}
Cmake-Project-Generator/Cmake-Project-Generator/obj/x86/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
0 → 100644
View file @
a8e948cc
// <autogenerated />
[
assembly
:
global
::
System
.
Runtime
.
Versioning
.
TargetFrameworkAttribute
(
".NETFramework,Version=v4.5"
,
FrameworkDisplayName
=
""
)]
Cmake-Project-Generator/Cmake-Project-Generator/obj/x86/Debug/Cmake-Project-Generator.csproj.FilesWrittenAbsolute.txt
0 → 100644
View file @
a8e948cc
/home/firesurfer/Cmake-Project-Generator/Cmake-Project-Generator/obj/x86/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
/home/firesurfer/Cmake-Project-Generator/Cmake-Project-Generator/bin/Debug/Cmake-Project-Generator.exe.mdb
/home/firesurfer/Cmake-Project-Generator/Cmake-Project-Generator/bin/Debug/Cmake-Project-Generator.exe
/home/firesurfer/Cmake-Project-Generator/Cmake-Project-Generator/obj/x86/Debug/Cmake-Project-Generator.exe
/home/firesurfer/Cmake-Project-Generator/Cmake-Project-Generator/obj/x86/Debug/Cmake-Project-Generator.exe.mdb
Cmake-Project-Generator/Cmake-Project-Generator/obj/x86/Debug/Cmake-Project-Generator.exe
0 → 100755
View file @
a8e948cc
File added
Cmake-Project-Generator/Cmake-Project-Generator/obj/x86/Debug/Cmake-Project-Generator.exe.mdb
0 → 100644
View file @
a8e948cc
File added
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment