1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| #!/usr/bin/ruby -w
file = IO.read(ARGV[0]);
projectName = String.new; file.sub!(/TARGET = (.+)$/) { projectName = $1.dup; "PROJECT(#{projectName})" } templateType = String.new; file.sub!(/TEMPLATE = (.+)$\n/) { templateType = $1.dup; "" } file.gsub!(/include\((.+)\)/, 'INCLUDE(\1 OPTIONAL)'); file.gsub!(/includeforce\((.+)\)/, 'INCLUDE(\1)'); file.gsub!(/INCLUDEPATH \*= (.+)((\n[ \t]+.+$)*)/, 'SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} \1\2)'); file.gsub!(/SOURCES \*= (.+)((\n[ \t]+.+$)*)/, "SET(#{projectName}_sources $#{projectName}_sources" ' \1\2)'); file.gsub!(/HEADERS \*= (.+)((\n[ \t]+.+$)*)/, "SET(#{projectName}_headers $#{projectName}_headers" ' \1\2)'); file.gsub!(/DEFINES \*= (.+)((\n[ \t]+.+$)*)/, 'SET(DEFINES ${DEFINES} \1\2)');
file.gsub!(/(.+)\s\*=\s(.+)/, 'SET(\1 ${\1} \2)'); file.gsub!(/(.+)\s=\s(.+)/, 'SET(\1 \2)'); file.gsub!(/\$\$\{(.+)\}/, '${\1}'); file.gsub!(/\$\$\((.+)\)/, '$ENV{\1}'); file.gsub!(/([A-Za-z_\-.]+)\.pri/, '\1.cmake');
file.gsub!(/\\\)/, ')');
file += "ADD_EXECUTABLE(#{projectName} #{projectName}_sources)" if templateType == "app"; file += "ADD_LIBRARY(#{projectName} ${#{projectName}_sources})" if templateType == "lib";
if ARGV.length > 1 outname = ARGV[1]; else if ARGV[0] =~ /.+\.pro$/ outname = File.join(File.dirname(ARGV[0]), "CMakeLists.txt"); elsif (ARGV[0] =~ /.+\.pri$/) || (ARGV[0] =~ /.+\.prf$/) outbase = File.basename(ARGV[0]); outbase.sub!(/\.pr./, ".cmake"); outname = File.join(File.dirname(ARGV[0]), outbase) end end outfile = File.new(outname, "w"); outfile.puts(file); outfile.close;
|