Skip to content

Commit

Permalink
added submodule cmake_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ebertolazzi committed Sep 11, 2022
1 parent c73e66a commit 36315c6
Show file tree
Hide file tree
Showing 38 changed files with 754 additions and 960 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "submodules/quarticRootsFlocke"]
path = submodules/quarticRootsFlocke
url = https://github.com/ebertolazzi/quarticRootsFlocke.git
[submodule "cmake_utils"]
path = cmake_utils
url = git@github.com:ebertolazzi/cmake_utils.git
51 changes: 24 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
# Enrico Bertolazzi #
# Dipartimento di Ingegneria Industriale #
# Universita` degli Studi di Trento #
# email: enrico.bertolazzi@ing.unitn.it #
# email: enrico.bertolazzi@unitn.it #
# #
############################################################################

cmake_minimum_required(VERSION 3.14)

project( Clothoids )
include(./cmake/CMakeLists-common.txt)
include(./cmake_utils/CMakeLists-common.txt)

project(
${PROJECT_NAME}
VERSION ${EB_PROJECT_VERSION}
VERSION ${UTILS_PROJECT_VERSION}
HOMEPAGE_URL "https://ebertolazzi.github.io/Clothoids/"
)

include(./cmake/CMakeLists-cflags.txt)
include(./cmake/CMakeLists-utilities.txt)
include(./cmake_utils/CMakeLists-cflags.txt)
include(./cmake_utils/CMakeLists-utilities.txt)

# Evaluating the suffix to append to target built by this CMake file
ebertolazzi_artifacts_suffix(ARTIFACTS_STATIC_SUFFIX TRUE)
if( EB_BUILD_SHARED )
ebertolazzi_artifacts_suffix(ARTIFACTS_DYNAMIC_SUFFIX FALSE)
utils_artifacts_suffix(ARTIFACTS_STATIC_SUFFIX TRUE)
if( UTILS_BUILD_SHARED )
utils_artifacts_suffix(ARTIFACTS_DYNAMIC_SUFFIX FALSE)
endif()

message( STATUS "Compiler used: ${CMAKE_CXX_COMPILER_ID}" )
Expand Down Expand Up @@ -85,15 +85,15 @@ find_library(
)
if( UTILS )
message(STATUS "Found Utils${ARTIFACTS_STATIC_SUFFIX}")
ebertolazzi_copy_directory(
utils_copy_directory(
"${UPDIR}/Utils/lib"
"${CMAKE_CURRENT_SOURCE_DIR}/lib3rd"
)
else()
message(STATUS "NOT Found Utils${ARTIFACTS_STATIC_SUFFIX} use submodule")
add_subdirectory(./submodules/Utils)
include_directories(./submodules/Utils/src)
set( UTILS ebertolazzi_Utils_Static )
set( UTILS ${UTILS_NAMESPACE}_Utils_Static )
set( DEPEND_TARGETS ${DEPEND_TARGETS} ${UTILS} )
endif()

Expand All @@ -110,7 +110,7 @@ else()
message(STATUS "NOT Found quarticRootsFlocke${ARTIFACTS_STATIC_SUFFIX}")
add_subdirectory(./submodules/quarticRootsFlocke)
include_directories(./submodules/quarticRootsFlocke/src)
set( ROOTS ebertolazzi_quarticRootsFlocke_Static )
set( ROOTS ${UTILS_NAMESPACE}_quarticRootsFlocke_Static )
set( DEPEND_TARGETS ${DEPEND_TARGETS} ${ROOTS} )
endif()

Expand All @@ -121,36 +121,36 @@ endif()
# |___/
#
# define target
ebertolazzi_setup_target(
utils_setup_target(
${PROJECT_NAME}
TRUE # build static
"${SOURCE_DIR}"
"${SOURCES}"
"${SOURCE_DIR}"
"${PUBLIC_HEADERS}"
)
if ( EB_BUILD_SHARED )
ebertolazzi_setup_target(
if ( UTILS_BUILD_SHARED )
utils_setup_target(
${PROJECT_NAME}
FALSE # build dynamic
"${SOURCE_DIR}"
"${SOURCES}"
"${SOURCE_DIR}"
"${PUBLIC_HEADERS}"
)
target_link_libraries( ${EB_NAMESPACE}_${PROJECT_NAME} ${ROOTS} ${UTILS} )
target_link_libraries( ${UTILS_NAMESPACE}_${PROJECT_NAME} ${ROOTS} ${UTILS} )
endif()

if ( DEPEND_TARGETS )
add_dependencies( ${EB_NAMESPACE}_${PROJECT_NAME}_Static ${DEPEND_TARGETS} )
add_dependencies( ${UTILS_NAMESPACE}_${PROJECT_NAME}_Static ${DEPEND_TARGETS} )
endif()

# _____ _
# |_ _|__ __| |_ ___
# | |/ -_|_-< _(_-<
# |_|\___/__/\__/__/
#
if ( EB_ENABLE_TESTS )
if ( UTILS_ENABLE_TESTS )

enable_testing()

Expand All @@ -165,7 +165,7 @@ if ( EB_ENABLE_TESTS )
set( ZLIB_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/lib3rd/zlib/include ")
endif()

set( LIBS ${EB_NAMESPACE}_${PROJECT_NAME}_Static ${UTILS} ${ROOTS} ${ZLIB_LIBRARIES} ${CMAKE_DL_LIBS} )
set( LIBS ${UTILS_NAMESPACE}_${PROJECT_NAME}_Static ${UTILS} ${ROOTS} ${ZLIB_LIBRARIES} ${CMAKE_DL_LIBS} )

if( UNIX )
if ( NOT APPLE )
Expand All @@ -182,8 +182,8 @@ if ( EB_ENABLE_TESTS )
#find_library( WPTH pthread REQUIRED )
#set( LIBS ${LIBS} ${WS2} ${IPH} ${KER} )
set( LIBS ${LIBS} ws2_32 iphlpapi kernel32 )
if (EB_BUILD_SHARED)
target_link_libraries( ${EB_NAMESPACE}_${PROJECT_NAME} ${LIBS} ${ZLIB_LIBRARIES} ${CMAKE_DL_LIBS} )
if (UTILS_BUILD_SHARED)
target_link_libraries( ${UTILS_NAMESPACE}_${PROJECT_NAME} ${LIBS} ${ZLIB_LIBRARIES} ${CMAKE_DL_LIBS} )
endif()
endif()

Expand All @@ -210,11 +210,8 @@ if ( EB_ENABLE_TESTS )
foreach( S ${EXELISTCPP} )
add_executable( ${S} ${CMAKE_CURRENT_SOURCE_DIR}/src_tests/${S}.cc )
target_link_libraries( ${S} ${LIBS} )
add_test(
NAME "${S}"
COMMAND ./bin/${S}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
set_target_properties( ${S} PROPERTIES SUFFIX ".exe" )
add_test( NAME "${S}" COMMAND ./bin/${S}.exe WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
add_dependencies( "${PROJECT_NAME}_all_tests" ${S} )
endforeach()

Expand All @@ -241,6 +238,6 @@ install(
# |___/
#

include( ./cmake/CMakeLists-cpack.txt )
include( ./cmake_utils/CMakeLists-cpack.txt )

ebertolazzi_final_messages()
utils_final_messages()
157 changes: 34 additions & 123 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,117 +1,22 @@
%w(colorize rake fileutils).each do |gem|
begin
require gem
rescue LoadError
warn "Install the #{gem} gem:\n $ (sudo) gem install #{gem}".magenta
exit 1
end
end

case RUBY_PLATFORM
when /darwin/
OS = :mac
when /linux/
OS = :linux
when /cygwin|mswin|mingw|bccwin|wince|emx/
OS = :win
when /msys/
OS = :win
end

require_relative "./Rakefile_common.rb"

file_base = File.expand_path(File.dirname(__FILE__)).to_s+'/lib'
require_relative "./cmake_utils/Rakefile_common.rb"

cmd_cmake_build = ""
if COMPILE_EXECUTABLE then
cmd_cmake_build += ' -DEB_ENABLE_TESTS:VAR=ON '
else
cmd_cmake_build += ' -DEB_ENABLE_TESTS:VAR=OFF '
end
if COMPILE_DYNAMIC then
cmd_cmake_build += ' -DEB_BUILD_SHARED:VAR=ON '
else
cmd_cmake_build += ' -DEB_BUILD_SHARED:VAR=OFF '
end
if COMPILE_DEBUG then
cmd_cmake_build += ' -DCMAKE_BUILD_TYPE:VAR=Debug --loglevel=STATUS '
else
cmd_cmake_build += ' -DCMAKE_BUILD_TYPE:VAR=Release --loglevel=STATUS '
end
cmd_cmake_build += " -DEB_INSTALL_LOCAL=ON "

FileUtils.cp './cmake/CMakeLists-cflags.txt', 'submodules/Utils/cmake/CMakeLists-cflags.txt'
FileUtils.cp './cmake/CMakeLists-cflags.txt', 'submodules/quarticRootsFlocke/cmake/CMakeLists-cflags.txt'
CLEAN.include ["./**/*.o", "./**/*.obj", "./bin/**/example*", "./build"]
CLEAN.clear_exclude.exclude { |fn| fn.pathmap("%f").downcase == "core" }
CLOBBER.include []

desc "default task --> build"
task :default => :build

desc "run tests"
task :test do
FileUtils.cd "build"
sh 'ctest --output-on-failure'
FileUtils.cd '..'
end

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

"run tests on linux/osx"
task :run do
TESTS.each do |cmd|
sh "./bin/#{cmd}" if File.exist?( "./bin/#{cmd}" )
end
end

desc "run tests (Release) on windows"
task :run_win do
TESTS.each do |cmd|
sh "bin\\Release\\#{cmd}.exe" if File.exist?( "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 "build lib"
task :build do
puts "CLOTHOIDS build".green
case OS
when :mac
Rake::Task[:build_osx].invoke
when :linux
Rake::Task[:build_linux].invoke
when :win
Rake::Task[:build_win].invoke
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" )

dir = "build"

FileUtils.rm_rf dir
FileUtils.mkdir_p dir
FileUtils.cd dir
FileUtils.rm_rf "build"
FileUtils.mkdir_p "build"
FileUtils.cd "build"

cmd_cmake = win_vs(args.bits,args.year) + cmd_cmake_build
cmd_cmake = cmake_generation_command(args.bits,args.year) + cmd_cmake_build()

puts "run CMAKE for CLOTHOIDS".yellow
sh cmd_cmake + ' ..'
Expand All @@ -122,17 +27,11 @@ task :build_win, [:year, :bits] do |t, args|
sh 'cmake --build . --config Release --target install '+PARALLEL+QUIET
end

if RUN_CPACK then
puts "run CPACK for ROOTS".yellow
sh 'cpack -C CPackConfig.cmake'
sh 'cpack -C CPackSourceConfig.cmake'
end

FileUtils.cd '..'
end

desc "compile for OSX"
task :build_osx do
desc "compile for OSX/LINUX/MINGW"
task :build_osx_linux_mingw do

dir = "build"

Expand All @@ -151,22 +50,34 @@ task :build_osx do
sh 'cmake --build . --config Release --target install '+PARALLEL+QUIET
end

if RUN_CPACK then
puts "run CPACK for ROOTS".yellow
sh 'cpack -C CPackConfig.cmake'
sh 'cpack -C CPackSourceConfig.cmake'
end

FileUtils.cd '..'
end

desc "compile for LINUX"
task :build_linux => :build_osx

task :clean_osx do
task :clean_osx_linux_mingw do
FileUtils.rm_rf 'build'
FileUtils.rm_rf 'lib'
FileUtils.rm_rf 'lib3rd'
end

task :clean_linux => :clean_osx
task :clean_win => :clean_osx
desc "compile for OSX"
task :build_osx => :build_osx_linux_mingw

desc "compile for LINUX"
task :build_linux => :build_osx_linux_mingw

desc "compile for MINGW"
task :build_mingw => :build_osx_linux_mingw

task :clean_osx => :clean_osx_linux_mingw
task :clean_linux => :clean_osx_linux_mingw
task :clean_mingw => :clean_osx_linux_mingw
task :clean_win => :clean_osx_linux_mingw

desc 'pack for OSX/LINUX/MINGW/WINDOWS'
task :cpack do
FileUtils.cd "build"
puts "run CPACK for CLOTHOIDS".yellow
sh 'cpack -C CPackConfig.cmake'
sh 'cpack -C CPackSourceConfig.cmake'
FileUtils.cd ".."
end
Loading

0 comments on commit 36315c6

Please sign in to comment.