Skip to content

Commit

Permalink
updated Rakefile to compile on WINDOWS
Browse files Browse the repository at this point in the history
  • Loading branch information
ebertolazzi committed Sep 11, 2019
1 parent c130d74 commit 30e984d
Show file tree
Hide file tree
Showing 4 changed files with 332 additions and 155 deletions.
74 changes: 44 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,34 @@

cmake_minimum_required(VERSION 3.5)

SET( TARGET Clothoids )

PROJECT( ${TARGET} CXX C )

FILE( GLOB S ./CMakeLists-cflags.txt )
IF( EXISTS ${S} )
INCLUDE( ${S} )
IF ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
SET( DEBUG_SUFFIX "_debug" )
ELSE()
SET( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE )
SET( CMAKE_VERBOSE_MAKEFILE TRUE )
IF( CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
SET( CMAKE_CXX_FLAGS "-std=c++11 " )
SET( CMAKE_CXX_FLAGS_RELEASE "-fPIC -Wall -Wno-weak-vtables -Wno-implicit-fallthrough -Wno-documentation-unknown-command -Wno-float-equal -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-reserved-id-macro -Wno-documentation -msse4.2 -msse4.1 -mssse3 -msse3 -msse2 -msse -mmmx -funroll-loops -O3 -g0 " )
SET( CMAKE_CXX_FLAGS_DEBUG "-fPIC -Wall -Wno-weak-vtables -Wno-implicit-fallthrough -Wno-documentation-unknown-command -Wno-float-equal -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-reserved-id-macro -Wno-documentation -O0 -g3 -DMECHATRONIX_DEBUG " )
ELSEIF( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
SET( CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ " )
SET( CMAKE_CXX_FLAGS_RELEASE "-fPIC -Weverything -Wno-weak-vtables -Wno-implicit-fallthrough -Wno-documentation-unknown-command -Wno-float-equal -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-reserved-id-macro -Wno-documentation -msse4.2 -msse4.1 -mssse3 -msse3 -msse2 -msse -mmmx -funroll-loops -O3 -g0 -fPIC -Weverything -Wno-weak-vtables -Wno-implicit-fallthrough -Wno-documentation-unknown-command -Wno-float-equal -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-reserved-id-macro -Wno-documentation " )
SET( CMAKE_CXX_FLAGS_DEBUG "-fPIC -Weverything -Wno-weak-vtables -Wno-implicit-fallthrough -Wno-documentation-unknown-command -Wno-float-equal -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-reserved-id-macro -Wno-documentation -O0 -gfull -DMECHATRONIX_DEBUG -fPIC -Weverything -Wno-weak-vtables -Wno-implicit-fallthrough -Wno-documentation-unknown-command -Wno-float-equal -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-reserved-id-macro -Wno-documentation " )
ELSEIF( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
SET( CMAKE_CXX_FLAGS_RELEASE "/nologo /GS /W3 /WX- /Gm- /Gd /fp:precise /EHsc /FS /D_WINDOWS /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS /DHAVE_STRING_H /DNO_GETTIMEOFDAY /DYAML_DECLARE_STATIC /DPCRE_STATIC /O2 /MD " )
SET( CMAKE_CXX_FLAGS_DEBUG "/nologo /GS /W3 /WX- /Gm- /Gd /fp:precise /EHsc /FS /D_WINDOWS /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS /DHAVE_STRING_H /DNO_GETTIMEOFDAY /DYAML_DECLARE_STATIC /DPCRE_STATIC /Od /Ob0 /MDd /Zi /RTC1 /D_DEBUG " )
SET( DEBUG_SUFFIX )
ENDIF()

IF ( BUILD_SHARED )
IF ( APPLE )
SET( TARGET Clothoids_osx${DEBUG_SUFFIX} )
ELSEIF( LINUX OR UNIX )
SET( TARGET Clothoids_linux${DEBUG_SUFFIX} )
ELSE()
MESSAGE( FATAL_ERROR "Unsupported compiler ${CMAKE_CXX_COMPILER_ID}")
SET( TARGET Clothoids_win${BITS}${DEBUG_SUFFIX} )
SET( CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON )
ENDIF()
ENDIF()

IF ( APPLE )
SET( TARGETS Clothoids_osx_static${DEBUG_SUFFIX} )
ELSEIF( LINUX OR UNIX )
SET( TARGETS Clothoids_linux_static${DEBUG_SUFFIX} )
ELSE()
SET( TARGETS Clothoids_win${BITS}_static${DEBUG_SUFFIX} )
ENDIF()

PROJECT( Clothoids CXX C )

INCLUDE( ./CMakeLists-cflags.txt )
MESSAGE( STATUS "Compiler used: ${CMAKE_CXX_COMPILER_ID}")

SET( CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} )
Expand Down Expand Up @@ -68,24 +70,36 @@ ENDFOREACH (F ${S})

INCLUDE_DIRECTORIES( src submodules/quarticRootsFlocke/src )

ADD_LIBRARY( ${TARGET} STATIC ${SOURCES} ${HEADERS} )
SET( CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/lib )

IF ( BUILD_SHARED )
ADD_LIBRARY( ${TARGETS} STATIC ${SOURCES} ${HEADERS} )
ADD_LIBRARY( ${TARGET} SHARED ${SOURCES} ${HEADERS} )
INSTALL(
TARGETS ${TARGET} ${TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/dll
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
)
ELSE()
ADD_LIBRARY( ${TARGETS} STATIC ${SOURCES} ${HEADERS} )
INSTALL(
TARGETS ${TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/dll
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
)
ENDIF()

IF( BUILD_EXECUTABLE )

SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)

SET( EXECUTABLE testBiarc testDistance testG2 testG2plot testG2stat testG2stat2arc testG2statCLC testIntersect testPolyline testTriangle2D )
FOREACH ( EXE ${EXECUTABLE} )
ADD_EXECUTABLE( ${EXE} tests-cpp/${EXE}.cc ${HEADERS} )
TARGET_LINK_LIBRARIES( ${EXE} ${TARGET} )
TARGET_LINK_LIBRARIES( ${EXE} ${TARGETS} )
ENDFOREACH ( EXE ${EXECUTABLE} )
ENDIF()

INSTALL( TARGETS ${TARGET}
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/dll
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX} )

INSTALL( FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include )

MESSAGE( STATUS "Using ${SSE_FLAGS} extensions")
Expand Down
239 changes: 114 additions & 125 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#
#
#

%w( colorize rake fileutils ).each do |gem|
%w(colorize rake fileutils).each do |gem|
begin
require gem
rescue LoadError
Expand All @@ -11,161 +7,154 @@
end
end

require "rake/clean"
require_relative "./Rakefile_common.rb"

CLEAN.include ["./**/*.o", "./**/*.obj", "./bin/**/example*", "./build"]
CLOBBER.include []
CLEAN.exclude('**/[cC][oO][rR][eE]')
task :default => [:build]

cmakeversion = %x( cmake --version ).scan(/\d+\.\d+/).last
if cmakeversion >= "3.12" then
PARALLEL = '--parallel 8 '
else
PARALLEL = ''
task :mkl, [:year, :bits] do |t, args|
args.with_defaults(:year => "2017", :bits => "x64" )
sh "'C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/bin/compilervars.bat' -arch #{args.bits} vs#{args.year}shell"
end

LIB_NAME="Clothoids"

task :default => [:build]

desc "run tests"
TESTS = [
"testBiarc",
"testDistance",
"testG2",
"testG2plot",
"testG2stat",
"testG2stat2arc",
"testG2statCLC",
"testIntersect",
"testPolyline",
"testTriangle2D"
]

"run tests on linux/osx"
task :run do
sh "./bin/testBiarc"
sh "./bin/testDistance"
sh "./bin/testG2"
sh "./bin/testG2plot"
sh "./bin/testG2stat"
sh "./bin/testG2stat2arc"
sh "./bin/testG2statCLC"
sh "./bin/testIntersect"
sh "./bin/testPolyline"
sh "./bin/testTriangle2D"
TESTS.each do |cmd|
sh "./bin/#{cmd}"
end
end

desc "run tests"
desc "run tests (Release) on windows"
task :run_win do
sh "./bin/Release/testBiarc"
sh "./bin/Release/testDistance"
sh "./bin/Release/testG2"
sh "./bin/Release/testG2plot"
sh "./bin/Release/testG2stat"
sh "./bin/Release/testG2stat2arc"
sh "./bin/Release/testG2statCLC"
sh "./bin/Release/testIntersect"
sh "./bin/Release/testPolyline"
sh "./bin/Release/testTriangle2D"
TESTS.each do |cmd|
sh "bin\\Release\\#{cmd}.exe"
end
end

desc "run tests (Debug) on windows"
task :run_win_debug do
TESTS.each do |cmd|
sh "bin\\Debug\\#{cmd}.exe"
end
end

desc "compile for Visual Studio [default year=2017, bits=x64]"
task :build_win, [:year, :bits] do |t, args|
args.with_defaults( :year => "2017", :bits => "x64" )

desc "compile for UNIX/OSX [default GC='./GC',executable='no']"
task :build, [:gc_dir,:executable] do |t, args|
dir = "vs_#{args.year}_#{args.bits}"

args.with_defaults( :gc_dir => './GC', :executable => "no" )
FileUtils.rm_rf dir
FileUtils.mkdir_p dir
FileUtils.cd dir

if args.gc_dir == './GC' then
puts "\n\nBuild submodule GenericContainer".green
FileUtils.rm_rf "GC"
sh "git clone -b develop --depth 1 https://github.com/ebertolazzi/GenericContainer.git GC"
FileUtils.cd "GC"
FileUtils.cp "../CMakeLists-cflags.txt", "CMakeLists-cflags.txt"
sh "rake build"
FileUtils.cd ".."
cmake_cmd = win_vs(args.bits,args.year)
if COMPILE_EXECUTABLE then
cmake_cmd += ' -DBUILD_EXECUTABLE:VAR=true '
else
puts "\n\nUse GenericContainer at #{args.gc_dir}".green
cmake_cmd += ' -DBUILD_EXECUTABLE:VAR=false '
end

FileUtils.rm_rf "lib"
FileUtils.rm_rf "build"
FileUtils.mkdir_p "build"
FileUtils.cd "build"

cmd = 'cmake -DCMAKE_INSTALL_PREFIX:PATH=../lib'
if args.executable.to_s == "yes" then
cmd += ' -DBUILD_EXECUTABLE=true'
if COMPILE_DYNAMIC then
cmake_cmd += ' -DBUILD_SHARED:VAR=true '
else
cmake_cmd += ' -DBUILD_SHARED:VAR=false '
end
cmd += ' '+PARALLEL+'..'

puts "\n\nPrepare #{LIB_NAME} project".green

sh cmd

puts "\n\nCompile #{LIB_NAME} Debug".green
sh 'cmake --build . --config Debug --target install '+PARALLEL
FileUtils.cp "../lib/lib#{LIB_NAME}.a", "../lib/lib#{LIB_NAME}_debug.a"
FileUtils.mkdir_p "../lib/lib"
FileUtils.mkdir_p "../lib/bin"
FileUtils.mkdir_p "../lib/bin/"+args.bits
FileUtils.mkdir_p "../lib/dll"
FileUtils.mkdir_p "../lib/include"

if COMPILE_DEBUG then
sh cmake_cmd + ' -DCMAKE_BUILD_TYPE:VAR=Debug ..'
sh 'cmake --build . --config Debug --target install '+PARALLEL
FileUtils.cp_r './lib/dll', '../lib/' if Dir.exist?('./lib/dll')
Dir['./lib/bin/*'].each do |f|
FileUtils.cp f, '../lib/bin/'+args.bits+'/'+File.basename(f)
end
Dir['./lib/lib/*'].each do |f|
if /\_static.*\.lib$/.match(f) then
FileUtils.cp f, '../lib/lib/'+File.basename(f)
else
FileUtils.cp f, '../lib/dll/'+File.basename(f)
end
end
end

puts "\n\nCompile #{LIB_NAME} Release".green
sh 'cmake --build . --config Release --target install '+PARALLEL
sh cmake_cmd + ' -DCMAKE_BUILD_TYPE:VAR=Release ..'
sh 'cmake --build . --config Release --target install '+PARALLEL
FileUtils.cp_r './lib/dll', '../lib/' if Dir.exist?('./lib/dll')
Dir['./lib/bin/*'].each do |f|
FileUtils.cp f, '../lib/bin/'+args.bits+'/'+File.basename(f)
end
Dir['./lib/lib/*'].each do |f|
if /\_static.*\.lib$/.match(f) then
FileUtils.cp f, '../lib/lib/'+File.basename(f)
else
FileUtils.cp f, '../lib/dll/'+File.basename(f)
end
end
FileUtils.cp_r './lib/include', '../lib/' if Dir.exist?('./lib/include')
FileUtils.cd '..'

end

desc "compile for Visual Studio [default year=2017 bits=x64 gc_dir=./GC executable=no]"
task :build_win, [:year, :bits, :gc_dir, :executable ] do |t, args|
args.with_defaults(
:year => "2017",
:bits => "x64",
:gc_dir => './GC',
:executable => 'no'
)

if args.gc_dir == './GC' then
puts "\n\nBuild submodule GenericContainer".green
FileUtils.rm_rf "GC"
sh "git clone -b develop --depth 1 https://github.com/ebertolazzi/GenericContainer.git GC"
FileUtils.cd "GC"
FileUtils.cp "../CMakeLists-cflags.txt", "CMakeLists-cflags.txt"
sh "rake build"
FileUtils.cd ".."
else
puts "\n\nUse GenericContainer at #{args.gc_dir}".green
end
desc 'compile for OSX'
task :build_osx do

puts "\n\nPrepare #{LIB_NAME} project".green
dir = "vs_#{args.year}_#{args.bits}"
dir = "build"

FileUtils.rm_rf dir
FileUtils.mkdir_p dir
FileUtils.cd dir

tmp = " -DBITS=#{args.bits} -DYEAR=#{args.year} " +
' -DCMAKE_INSTALL_PREFIX:PATH=..\lib'

if args.executable.to_s == "yes" then
tmp += ' -DBUILD_EXECUTABLE=true'
end
tmp += ' '+PARALLEL+'..'
cmake_cmd = 'cmake '

win32_64 = ''
case args.bits
when /x64/
win32_64 = ' Win64'
if COMPILE_EXECUTABLE then
cmake_cmd += ' -DBUILD_EXECUTABLE:VAR=true '
else
cmake_cmd += ' -DBUILD_EXECUTABLE:VAR=false '
end

case args.year
when "2010"
sh 'cmake -G "Visual Studio 10 2010' + win32_64 +'" ' + tmp
when "2012"
sh 'cmake -G "Visual Studio 11 2012' + win32_64 +'" ' + tmp
when "2013"
sh 'cmake -G "Visual Studio 12 2013' + win32_64 +'" ' + tmp
when "2015"
sh 'cmake -G "Visual Studio 14 2015' + win32_64 +'" ' + tmp
when "2017"
sh 'cmake -G "Visual Studio 15 2017' + win32_64 +'" ' + tmp
if COMPILE_DYNAMIC then
cmake_cmd += ' -DBUILD_SHARED:VAR=true '
else
puts "Visual Studio year #{year} not supported!\n";
cmake_cmd += ' -DBUILD_SHARED:VAR=false '
end

FileUtils.mkdir_p "../lib"
if COMPILE_DEBUG then
sh cmake_cmd + ' -DCMAKE_BUILD_TYPE:VAR=Debug ..'
sh 'cmake --build . --config Debug --target install '+PARALLEL
end
sh cmake_cmd + ' -DCMAKE_BUILD_TYPE:VAR=Release ..'
sh 'cmake --build . --config Release --target install '+PARALLEL
FileUtils.cd '..'
end

puts "\n\nCompile #{LIB_NAME} Debug".green
sh 'cmake --build . --config Debug --target install '+PARALLEL
FileUtils.cp "Debug/#{LIB_NAME}.lib", "../lib/#{LIB_NAME}_vs#{args.year}_#{args.bits}_debug.lib"
desc 'compile for LINUX'
task :build_linux => [ :build_osx ] do
end

puts "\n\nCompile #{LIB_NAME} Release".green
sh 'cmake --build . --config Release --target install '+PARALLEL
FileUtils.cp "Release/#{LIB_NAME}.lib", "../lib/#{LIB_NAME}_vs#{args.year}_#{args.bits}.lib"
desc "clean for OSX"
task :clean_osx do
end

FileUtils.cd '..'
desc "clean for LINUX"
task :clean_linux do
end

desc "clean for WINDOWS"
task :clean_win do
end
Loading

0 comments on commit 30e984d

Please sign in to comment.