forked from Segs/Segs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create project skeleton generator. It might even work :)
git-svn-id: svn://svn.code.sf.net/p/segs/code2@142 a19be42f-918d-4297-8077-ab25d1e4f51f
- Loading branch information
nemerle
committed
Sep 30, 2009
1 parent
af536aa
commit 1953d30
Showing
4 changed files
with
183 additions
and
44 deletions.
There are no files selected for viewing
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,52 @@ | ||
#!/usr/bin/env ruby | ||
require 'pp' | ||
class CMakeFile | ||
attr_reader :current_path | ||
def initialize(path,parent=nil) | ||
@parent=parent | ||
@current_path=path | ||
if(path[0]!='.' && parent!=nil) # path relative to parent | ||
@current_path = File.join(parent.current_path,path) | ||
end | ||
end | ||
def create_component(name) | ||
p @current_path | ||
raise "CMakeLists.txt already exists" if File::exists?(File.join(@current_path,"CMakeLists.txt")) | ||
fp = File.open(File.join(@current_path,"CMakeLists.txt"),"w") | ||
fp<<'# $Id:$ | ||
SET(target_CPP | ||
) | ||
SET(target_INCLUDE | ||
) | ||
SET(target_INCLUDE_DIR "") | ||
# add components here | ||
# end of additional components | ||
INCLUDE_DIRECTORIES(${target_INCLUDE_DIR}) | ||
SET (target_SOURCES | ||
${target_CPP} | ||
${target_INCLUDE} | ||
) | ||
' | ||
fp<<"#ADD_LIBRARY(#{name} STATIC ${target_SOURCES})\n" | ||
fp<<"SEGS_REGISTER_COMPONENT(#{name} ${target_INCLUDE_DIR} ${target_CPP} ${target_INCLUDE} )\n" | ||
fp.close() | ||
end | ||
def parent_dir(path) # returns absolute path of given path | ||
File.expand_path((File.join(path,".."))) | ||
end | ||
# name is the same as the subdir name is the same as the component name | ||
def add_subdir(name,prefix="",optional=false) | ||
build_name = name | ||
build_name = prefix+"_"+name if !prefix.nil? | ||
fp = File.open(File.join(@current_path,"CMakeLists.txt"),"a+") | ||
fp <<"\n" | ||
if(optional) | ||
# add option | ||
fp << "SET(BUILD_#{build_name} TRUE CACHE BOOL \"Build #{name}?\")\n" | ||
end | ||
fp<<"IF(BUILD_#{build_name})\n\t" if(optional) | ||
fp<<"ADD_SUBDIRECTORY(#{name})\n" | ||
fp<<"ENDIF(BUILD_#{build_name})" if(optional) | ||
end | ||
end |
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
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,107 @@ | ||
#!/usr/bin/env ruby | ||
require 'pp' | ||
require 'CMakeCreator.rb' | ||
require 'SegsUtil.rb' | ||
def show_usage() | ||
print("usage:\nCreateProject name\n") | ||
print("\tThis utility will create skeleton for the named project \n") | ||
end | ||
class Servers_Creator | ||
def initialize(parent_cmake,prefix,*servers) | ||
@prefix=prefix | ||
@servers_arr=servers | ||
Dir.mkdir_optional(File.join(parent_cmake.current_path,"Servers")) if @servers_arr.size>0 | ||
parent_cmake.add_subdir("Servers") | ||
@cmake = CMakeFile.new("Servers",parent_cmake) | ||
end | ||
def create() | ||
@servers_arr.each {|serv| create_server(serv) } | ||
end | ||
def create_server(serv) | ||
@cmake.add_subdir(serv,@prefix,true) | ||
serv_path = File.join(@cmake.current_path,serv) | ||
Dir.mkdir_optional(serv_path) | ||
Dir.mkdir_optional(File.join(serv_path,"src")) | ||
Dir.mkdir_optional(File.join(serv_path,"include")) | ||
Dir.mkdir_optional(File.join(serv_path,"docs")) | ||
CMakeFile.new(serv,@cmake).create_component(@prefix+"_"+serv) | ||
end | ||
end | ||
class Clients_Creator | ||
def initialize(parent_cmake,prefix,*clients) | ||
@prefix=prefix | ||
@clients=clients | ||
parent_cmake.add_subdir("Clients") | ||
Dir.mkdir_optional(File.join(parent_cmake.current_path,"Clients")) if @clients.size>0 | ||
@cmake = CMakeFile.new("Clients",parent_cmake) | ||
end | ||
def create() | ||
sub_dir = @cmake.current_path | ||
@clients.each {|client| create_client(client) } | ||
end | ||
def create_client(name) | ||
@cmake.add_subdir(name,@prefix,true) | ||
path = File.join(@cmake.current_path,name) | ||
Dir.mkdir_optional(path) | ||
Dir.mkdir_optional(File.join(path,"src")) | ||
Dir.mkdir_optional(File.join(path,"include")) | ||
Dir.mkdir_optional(File.join(path,"docs")) | ||
CMakeFile.new(name,@cmake).create_component(@prefix+"_"+name) | ||
end | ||
end | ||
class Common_Creator | ||
def initialize(parent_cmake,prefix,topname,*subs) | ||
@prefix=prefix | ||
@subs=subs | ||
parent_cmake.add_subdir(topname) | ||
Dir.mkdir_optional(File.join(parent_cmake.current_path,topname)) | ||
@cmake = CMakeFile.new(topname,parent_cmake) | ||
end | ||
def create() | ||
sub_dir = @cmake.current_path | ||
@subs.each {|sub| create_sub(sub) } | ||
end | ||
def create_sub(name) | ||
@cmake.add_subdir(name,@prefix,true) | ||
path = File.join(@cmake.current_path,name) | ||
Dir.mkdir_optional(path) | ||
Dir.mkdir_optional(File.join(path,"src")) | ||
Dir.mkdir_optional(File.join(path,"include")) | ||
Dir.mkdir_optional(File.join(path,"docs")) | ||
CMakeFile.new(name,@cmake).create_component(@prefix+"_"+name) | ||
end | ||
end | ||
class Data_Creator | ||
def initialize(cmake,*servers) | ||
@servers_arr=servers | ||
@cmake = cmake | ||
end | ||
end | ||
class Docs_Creator | ||
def initialize(cmake,*servers) | ||
@servers_arr=servers | ||
@cmake = cmake | ||
end | ||
end | ||
|
||
if(ARGV.size()!=1) | ||
show_usage() | ||
else | ||
Dir.chdir("../Projects") | ||
root_cmake = CMakeFile.new(".") # Top dir in Projects | ||
project_dir = File.join(root_cmake.current_path,ARGV[0]) | ||
Dir.mkdir_optional(project_dir) | ||
|
||
project_root = CMakeFile.new(project_dir,root_cmake) | ||
root_cmake.add_subdir(ARGV[0],"",true) | ||
sc = Servers_Creator.new(project_root,ARGV[0],"TestServer","LoginServer") | ||
sc.create() | ||
cc = Clients_Creator.new(project_root,ARGV[0],"CliClient","GuiClient") | ||
cc.create() | ||
Common_Creator.new(project_root,ARGV[0],"Common").create() | ||
Common_Creator.new(project_root,ARGV[0],"Utilities").create() | ||
Common_Creator.new(project_root,ARGV[0],"Data").create() | ||
Common_Creator.new(project_root,ARGV[0],"Docs").create() | ||
end | ||
|
||
|
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,11 @@ | ||
#!/usr/bin/env ruby | ||
class Dir | ||
def Dir.mkdir_optional(name) | ||
if(File.exist?(name)) | ||
print("Warning: directory #{name} already exists\n") | ||
return 0 | ||
end | ||
Dir.mkdir(name) | ||
0 | ||
end | ||
end |