Skip to content

Commit

Permalink
v1.0 beta version
Browse files Browse the repository at this point in the history
  • Loading branch information
baranaydogan committed May 14, 2024
1 parent eff722f commit 2859885
Show file tree
Hide file tree
Showing 98 changed files with 10,575 additions and 21,414 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.vscode/
.vs/
.cache/
test/
build/
build_*/
build-*/

174 changes: 51 additions & 123 deletions CMakeLists.txt
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,153 +1,81 @@
cmake_minimum_required (VERSION 3.15)
cmake_minimum_required(VERSION 3.15.0)

PROJECT(Trekker)
PROJECT(trekker LANGUAGES CXX C)

# Set output names
set(trekkerExe trekker)

# Using C++11 standard
set(CMAKE_CXX_STANDARD 11)
# Using C++17 standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(UNIX AND NOT APPLE)

message(STATUS "Building for Linux")

# Set up manual page
add_definitions(-DSHOWMANUAL="man ${CMAKE_SOURCE_DIR}/doc/build/man/trekker")

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -W -Wall -Wextra -pedantic -pedantic-errors -Wno-long-long -ggdb3 -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -W -Wall -Wextra -pedantic -pedantic-errors -Wno-long-long")
option(BUILD_SHARED_LIBS "Build shared libraries" ON)

# FOR STATIC BUILD
# Build and link only static libraries and executables
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -static-libgcc -static-libstdc++ -Wl,--whole-archive -lpthread -Wl,--no-whole-archive")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")

# Check for zlib support
find_package(ZLIB)
if(ZLIB_LIBRARIES)
add_definitions(-D HAVE_ZLIB)
message(STATUS "Enabled zlib support")
else()
message(STATUS "Disabled zlib support")
endif()

elseif(MSVC)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install")

message(STATUS "Building for Windows")
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_INCLUDE_PATH})
link_directories(${CMAKE_LIBRARY_PATH})

# Building for Windows
add_definitions(-D BUILD_FOR_WINDOWS)
# List source files
file(GLOB_RECURSE SRCS CONFIGURE_DEPENDS RELATIVE ${CMAKE_SOURCE_DIR} "src/*.c*")
list(REMOVE_ITEM SRCS "main.cpp")

# Enable static compilation
# set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
# set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL$<$<CONFIG:Release>:Release>")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL$<$<CONFIG:Debug>:Debug>")
# Set executable
set(CMDNAME trekker)
add_executable(${CMDNAME} ${CMAKE_SOURCE_DIR}/src/main.cpp ${SRCS})
target_link_libraries(${CMDNAME} Nibrary geogram z)

# Disable some compiler warnings for cl
add_compile_options(/wd4244) # conversion from 'double' to 'x', possible loss of data
add_compile_options(/wd4267) # conversion from 'size_t' to 'x', possible loss of data
add_compile_options(/wd4996) # 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead.
add_compile_options(/wd4305) # truncation from 'double' to 'float'
add_compile_options(/wd4101) # unreferenced local variable

# No zlib support for Windows at the moment

else()
message(FATAL_ERROR "This operating system is not supported")
find_package(OpenMP REQUIRED)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()

# Check if a python package should be built
option(Build_Python3_WRAPPER "Enable to build a python package for Trekker" ${Build_Python3_WRAPPER})

if(${Build_Python3_WRAPPER} STREQUAL "ON")
message(STATUS "Enabled Python wrapper. A Python package will be build.")
message(WARNING "Please change Python path if necessary which is currently set as: ${Python3_EXECUTABLE}")
else()
set(Build_Python3_WRAPPER "OFF")
message(STATUS "A Python package will not be build.")
endif()
if(UNIX)

# List all source files
file(GLOB_RECURSE SRCS RELATIVE ${CMAKE_SOURCE_DIR} "src/*.c*")
list(REMOVE_ITEM SRCS "src/cmd.cpp")
message(STATUS "Building for Unix")

# Make an all object library
add_library(OBJS OBJECT ${SRCS})
target_include_directories(OBJS PUBLIC ${CMAKE_SOURCE_DIR}/src/nifticlib-2.0.0/znzlib)
target_include_directories(OBJS PUBLIC ${CMAKE_SOURCE_DIR}/src/nifticlib-2.0.0/niftilib)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -march=native")

# In order to build shared libraries PIC must be on
set_property(TARGET OBJS PROPERTY POSITION_INDEPENDENT_CODE 1)
if(CMAKE_BUILD_TYPE MATCHES Debug)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()

# Build the static executable
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")

# The Linux version statically links zlib as well. We skip compiling and linking zlib for Windows yet.
if(UNIX AND NOT APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wno-long-long -Wno-stringop-truncation -Wno-dev -Wno-unknown-pragmas -Wno-unused-result -Wall -Wextra -pedantic -pedantic-errors")

add_library(Trekker SHARED $<TARGET_OBJECTS:OBJS>)
add_library(tmp STATIC $<TARGET_OBJECTS:OBJS>)
target_include_directories(tmp PUBLIC ${CMAKE_SOURCE_DIR}/src/nifticlib-2.0.0/znzlib)
target_include_directories(tmp PUBLIC ${CMAKE_SOURCE_DIR}/src/nifticlib-2.0.0/niftilib)
# Thread support
find_package (Threads)
target_link_libraries(${CMDNAME} Threads::Threads)

set(trekkerLib ${CMAKE_BINARY_DIR}/libTrekker.a)
add_custom_target(combined COMMAND ar -x $<TARGET_FILE:tmp> COMMAND ar -qcs ${trekkerLib} *.o WORKING_DIRECTORY ${CMAKE_BINARY_DIR} DEPENDS tmp)
add_custom_target(libTrekker.a)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")

add_library(c STATIC IMPORTED GLOBAL)
add_dependencies(c combined)
set_target_properties(c PROPERTIES IMPORTED_LOCATION ${trekkerLib})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")

add_executable(${trekkerExe} ${CMAKE_SOURCE_DIR}/src/cmd.cpp)
if(ZLIB_LIBRARIES)
target_link_libraries(${trekkerExe} c ${ZLIB_LIBRARIES})
else()
target_link_libraries(${trekkerExe} c)
endif()

INSTALL(TARGETS ${trekkerExe} DESTINATION ${CMAKE_BINARY_DIR}/install/bin)
INSTALL(CODE "configure_file(${CMAKE_BINARY_DIR}/libTrekker.a ${CMAKE_BINARY_DIR}/install/lib/libTrekker.a COPYONLY)")
INSTALL(CODE "configure_file(${CMAKE_BINARY_DIR}/libTrekker.so ${CMAKE_BINARY_DIR}/install/lib/libTrekker.so COPYONLY)")
INSTALL(CODE "configure_file(${CMAKE_SOURCE_DIR}/src/trekker.h ${CMAKE_BINARY_DIR}/install/include/trekker.h COPYONLY)")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9")
target_link_libraries(${CMDNAME} stdc++fs)
endif()

endif()
elseif(MSVC)

if(MSVC)
message(STATUS "Building for Windows")

add_library(libTrekker_shared SHARED $<TARGET_OBJECTS:OBJS>)
add_library(libTrekker STATIC $<TARGET_OBJECTS:OBJS>)
target_include_directories(libTrekker PUBLIC ${CMAKE_SOURCE_DIR}/src/nifticlib-2.0.0/znzlib)
target_include_directories(libTrekker PUBLIC ${CMAKE_SOURCE_DIR}/src/nifticlib-2.0.0/niftilib)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /permissive- /bigobj")

add_executable(${trekkerExe} ${CMAKE_SOURCE_DIR}/src/cmd.cpp)
target_link_libraries(${trekkerExe} libTrekker)
# For definitions
add_compile_definitions(BUILD_FOR_WINDOWS _USE_MATH_DEFINES _WIN32 WIN32 _WIN64 WIN64)

INSTALL(TARGETS libTrekker DESTINATION ${CMAKE_BINARY_DIR}/install/lib)
INSTALL(TARGETS ${trekkerExe} DESTINATION ${CMAKE_BINARY_DIR}/install/bin)
INSTALL(CODE "configure_file(${CMAKE_SOURCE_DIR}/src/trekker.h ${CMAKE_BINARY_DIR}/install/include/trekker.h COPYONLY)")
# Disable some compiler warnings
set(DISABLED_WARNINGS "/wd4244 /wd4267 /wd4996 /wd4305 /wd4101 /wd4068 /wd4661 /wd4477 /wd4804 /wd4700")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DISABLED_WARNINGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DISABLED_WARNINGS}")

else()
message(FATAL_ERROR "This operating system is not supported")
endif()


if(${Build_Python3_WRAPPER} STREQUAL "ON")

INSTALL(CODE "configure_file(${CMAKE_SOURCE_DIR}/src/python/setup.py ${CMAKE_BINARY_DIR}/install/python/setup.py COPYONLY)")
INSTALL(CODE "configure_file(${CMAKE_SOURCE_DIR}/src/python/LICENSE ${CMAKE_BINARY_DIR}/install/python/LICENSE COPYONLY)")
INSTALL(CODE "configure_file(${CMAKE_SOURCE_DIR}/src/python/README.md ${CMAKE_BINARY_DIR}/install/python/README.md COPYONLY)")
INSTALL(CODE "configure_file(${CMAKE_SOURCE_DIR}/src/python/cython/Trekker.pxd ${CMAKE_BINARY_DIR}/install/python/cython/Trekker.pxd COPYONLY)")
INSTALL(CODE "configure_file(${CMAKE_SOURCE_DIR}/src/python/cython/Trekker.pyx ${CMAKE_BINARY_DIR}/install/python/cython/Trekker.pyx COPYONLY)")
INSTALL(CODE "configure_file(${CMAKE_SOURCE_DIR}/src/trekker.h ${CMAKE_BINARY_DIR}/install/python/cython/trekker.h COPYONLY)")

if(UNIX AND NOT APPLE)
INSTALL(CODE "configure_file(${CMAKE_BINARY_DIR}/install/lib/libTrekker.a ${CMAKE_BINARY_DIR}/install/python/cython/libTrekker.a COPYONLY)")
INSTALL(CODE "execute_process(COMMAND ${Python3_EXECUTABLE} ${CMAKE_BINARY_DIR}/install/python/setup.py sdist bdist_wheel WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/install/python)")
endif()

if(MSVC)
INSTALL(CODE "configure_file(${CMAKE_BINARY_DIR}/install/lib/libTrekker.lib ${CMAKE_BINARY_DIR}/install/python/cython/Trekker.lib COPYONLY)")
string(REPLACE "/" "\\\\" PythonCommand ${Python3_EXECUTABLE})
INSTALL(CODE "execute_process(COMMAND cmd.exe /c \"${PythonCommand}\" ${CMAKE_BINARY_DIR}/install/python/setup.py sdist bdist_wheel WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/install/python)")
endif()

endif()
INSTALL(TARGETS ${CMDNAME} DESTINATION bin)
4 changes: 1 addition & 3 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@


BSD 3-Clause License

Copyright (c) 2021, Dogu Baran Aydogan All rights reserved.
Copyright (c) 2021-2024, Dogu Baran Aydogan All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Expand Down
Binary file removed binaries/Trekker-0.9-cp38-cp38-linux_x86_64.whl
Binary file not shown.
Binary file removed binaries/Trekker-0.9-cp38-cp38-win_amd64.whl
Binary file not shown.
Binary file removed binaries/trekker_linux_x64_v0.9
Binary file not shown.
Binary file added binaries/trekker_linux_x64_v1.0b
Binary file not shown.
Binary file removed binaries/trekker_win_x64_v0.9.exe
Binary file not shown.
32 changes: 23 additions & 9 deletions build_Linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@

cmakeExe=cmake
buildType=Release #Release or Debug
buildShared=OFF
buildDir=build-static

c_compiler=gcc
cxx_compiler=g++
inc_path="../nibrary/${buildDir}/install/include/nibrary_v0.1"
lib_path="../nibrary/${buildDir}/install/lib/nibrary_v0.1"

buildPythonPackage=ON #ON or OFF
pythonExe=python
c_compiler=/bin/gcc
cxx_compiler=/bin/g++


rm -rf ${buildDir}
mkdir -p ${buildDir}
cd ${buildDir}

${cmakeExe} \
-DCMAKE_C_COMPILER=${c_compiler} \
-DCMAKE_CXX_COMPILER=${cxx_compiler} \
-DCMAKE_BUILD_TYPE=${buildType} \
-DCMAKE_INCLUDE_PATH=${inc_path} \
-DCMAKE_LIBRARY_PATH=${lib_path} \
-DBUILD_SHARED_LIBS=${buildShared} \
..

rm -rf build/Linux
mkdir -p build/Linux
cd build/Linux
${cmakeExe} -DCMAKE_C_COMPILER=${c_compiler} -DCMAKE_CXX_COMPILER=${cxx_compiler} -DCMAKE_BUILD_TYPE=${buildType} -DBuild_Python3_WRAPPER=${buildPythonPackage} -DPython3_EXECUTABLE=${pythonExe} ../..
${cmakeExe} --build . --config ${buildType} --target install --parallel 16
cd ../..

cd ..

11 changes: 0 additions & 11 deletions build_Windows.bat

This file was deleted.

11 changes: 0 additions & 11 deletions src/base/algorithm.cpp

This file was deleted.

48 changes: 0 additions & 48 deletions src/base/algorithm.h

This file was deleted.

Loading

0 comments on commit 2859885

Please sign in to comment.