Skip to content

Commit

Permalink
Merge pull request #3012 from MRtrix3/new_cpp_structure
Browse files Browse the repository at this point in the history
New folder structure for C++ code
  • Loading branch information
daljit46 authored Nov 13, 2024
2 parents 4d6f20f + 9972548 commit 39d3488
Show file tree
Hide file tree
Showing 830 changed files with 667 additions and 680 deletions.
1 change: 1 addition & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ jobs:
-B build
-G Ninja
-D CMAKE_BUILD_TYPE=Release
-D CMAKE_FIND_FRAMEWORK=LAST
-D MRTRIX_BUILD_TESTS=ON
-D MRTRIX_STL_DEBUGGING=ON
-D MRTRIX_USE_PCH=OFF
Expand Down
47 changes: 2 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ option(MRTRIX_BUILD_TESTS "Build tests executables" OFF)
option(MRTRIX_STRIP_CONDA "Strip ananconda/mininconda from PATH to avoid conflicts" ON)
option(MRTRIX_USE_PCH "Use precompiled headers" ON)
option(MRTRIX_PYTHON_SOFTLINK "Build directory softlink to Python source code rather than copying" ON)
option(MRTRIX_BUILD_NON_CORE_STATIC "Build MRtrix's non-core code as a static library" OFF)
option(MRTRIX_BUILD_STATIC "Build MRtrix's library statically" OFF)
option(MRTRIX_USE_LLD "Use lld as the linker" OFF)

set(MRTRIX_DEPENDENCIES_DIR "" CACHE PATH
Expand Down Expand Up @@ -73,16 +73,6 @@ file(RELATIVE_PATH relDir
set(CMAKE_INSTALL_RPATH ${base} ${base}/${relDir})

include(BuildType)
include(LinkerSetup)
include(FindFFTW)
include(CompilerCache)
include(ECMEnableSanitizers)
include(Dependencies)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
include(MacOSBundle)
endif()

use_compiler_cache()

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git AND NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit)
message(WARNING
Expand All @@ -91,37 +81,6 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git AND NOT EXISTS ${CMAKE_CURRENT_SOURCE
"and then run `pre-commit install` from the ${CMAKE_CURRENT_SOURCE_DIR} directory.")
endif()

add_library(mrtrix-common INTERFACE)
add_library(mrtrix::common ALIAS mrtrix-common)
target_compile_definitions(mrtrix-common INTERFACE
MRTRIX_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
$<$<PLATFORM_ID:Windows>:MRTRIX_WINDOWS>
$<$<PLATFORM_ID:Darwin>:MRTRIX_MACOSX>
$<$<PLATFORM_ID:FreeBSD>:MRTRIX_FREEBSD>
)

if(MRTRIX_STL_DEBUGGING AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Enabling STL debug mode")
target_compile_definitions(mrtrix-common INTERFACE
$<$<CXX_COMPILER_ID:MSVC>:_ITERATOR_DEBUG_LEVEL=1>
$<$<CXX_COMPILER_ID:GNU>:_GLIBCXX_DEBUG _GLIBCXX_DEBUG_PEDANTIC>
$<$<CXX_COMPILER_ID:Clang>:_LIBCPP_DEBUG=1>
)
endif()

if(MRTRIX_WARNINGS_AS_ERRORS)
message(STATUS "Enabling warnings as errors")
target_compile_options(mrtrix-common INTERFACE
$<$<CXX_COMPILER_ID:MSVC>:/WX>
$<$<CXX_COMPILER_ID:GNU,Clang>:-Werror>
)
endif()

# Allow compilation of big object of files in debug mode on MINGW
if(MINGW AND CMAKE_BUILD_TYPE MATCHES "Debug")
target_compile_options(mrtrix-common INTERFACE -Wa,-mbig-obj)
endif()


if(MRTRIX_STRIP_CONDA AND DEFINED ENV{CONDA_PREFIX})
message(WARNING "CONDA_PREFIX is set to ${CONDA_PREFIX}, adding conda diretories to CMAKE_IGNORE_PATH to avoid conflicts.\n"
Expand All @@ -145,11 +104,9 @@ if(COMPILER_PATH MATCHES "fsl/bin" OR LINKER_PATH MATCHES "fsl/bin")
)
endif()

add_subdirectory(cmd)
add_subdirectory(core)
add_subdirectory(cpp)
add_subdirectory(python)
add_subdirectory(share)
add_subdirectory(src)

if(PROJECT_IS_TOP_LEVEL AND MRTRIX_BUILD_TESTS)
add_subdirectory(testing)
Expand Down
7 changes: 3 additions & 4 deletions clang-format-all
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ parser.add_argument(

args = parser.parse_args()
clang_format = args.executable
paths = ['core', 'cmd', 'src', 'testing']
paths = ['cpp', 'testing']
extensions = ['.h', '.cpp']
exclusion_list = ['core/file/nifti1.h',
'core/file/nifti2.h',
'core/file/json.h']
exclusion_list = ['cpp/gui/opengl/gl_core_3_3.h',
'cpp/gui/opengl/gl_core_3_3.cpp']

# if clang-format path contains spaces, wrap it in quotes
if ' ' in clang_format and not clang_format.startswith('"'):
Expand Down
8 changes: 4 additions & 4 deletions cmake/MacOSBundle.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function(set_bundle_properties executable_name)
set(icon_files ${CMAKE_CURRENT_SOURCE_DIR}/../icons/macos/${executable_name}.icns)
set(icon_files ${PROJECT_SOURCE_DIR}/icons/macos/${executable_name}.icns)
if(${executable_name} STREQUAL "mrview")
list(APPEND icon_files ${CMAKE_CURRENT_SOURCE_DIR}/../icons/macos/mrview_doc.icns)
list(APPEND icon_files ${PROJECT_SOURCE_DIR}/icons/macos/mrview_doc.icns)
endif()

string(TIMESTAMP CURRENT_YEAR "%Y")
Expand All @@ -10,14 +10,14 @@ function(set_bundle_properties executable_name)
target_sources(${executable_name} PRIVATE ${icon_files})
set_target_properties(${executable_name} PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/../packaging/macos/bundle/${executable_name}.plist.in"
MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/packaging/macos/bundle/${executable_name}.plist.in"
RESOURCE "${icon_files}"
INSTALL_RPATH "@executable_path/../../../../lib"
)
endfunction()

function(install_bundle_wrapper_scripts executable_name)
set(wrapper_script ${CMAKE_CURRENT_SOURCE_DIR}/../packaging/macos/bundle/wrapper_launcher.sh.in)
set(wrapper_script ${PROJECT_SOURCE_DIR}/packaging/macos/bundle/wrapper_launcher.sh.in)
configure_file(${wrapper_script} ${PROJECT_BINARY_DIR}/bin/${executable_name}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
@ONLY
Expand Down
8 changes: 0 additions & 8 deletions core/version.cpp.in

This file was deleted.

4 changes: 0 additions & 4 deletions core/version.h

This file was deleted.

41 changes: 41 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
include(LinkerSetup)
include(FindFFTW)
include(ECMEnableSanitizers)
include(Dependencies)
include(CompilerCache)
use_compiler_cache()

add_library(mrtrix-common INTERFACE)
add_library(mrtrix::common ALIAS mrtrix-common)
target_compile_definitions(mrtrix-common INTERFACE
MRTRIX_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
$<$<PLATFORM_ID:Windows>:MRTRIX_WINDOWS>
$<$<PLATFORM_ID:Darwin>:MRTRIX_MACOSX>
$<$<PLATFORM_ID:FreeBSD>:MRTRIX_FREEBSD>
)

if(MRTRIX_STL_DEBUGGING AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Enabling STL debug mode")
target_compile_definitions(mrtrix-common INTERFACE
$<$<CXX_COMPILER_ID:MSVC>:_ITERATOR_DEBUG_LEVEL=1>
$<$<CXX_COMPILER_ID:GNU>:_GLIBCXX_DEBUG _GLIBCXX_DEBUG_PEDANTIC>
$<$<CXX_COMPILER_ID:Clang>:_LIBCPP_DEBUG=1>
)
endif()

if(MRTRIX_WARNINGS_AS_ERRORS)
message(STATUS "Enabling warnings as errors")
target_compile_options(mrtrix-common INTERFACE
$<$<CXX_COMPILER_ID:MSVC>:/WX>
$<$<CXX_COMPILER_ID:GNU,Clang>:-Werror>
)
endif()

# Allow compilation of big object of files in debug mode on MINGW
if(MINGW AND CMAKE_BUILD_TYPE MATCHES "Debug")
target_compile_options(mrtrix-common INTERFACE -Wa,-mbig-obj)
endif()

add_subdirectory(cmd)
add_subdirectory(core)
add_subdirectory(gui)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 6 additions & 2 deletions cmd/CMakeLists.txt → cpp/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
include(MacOSBundle)
endif()

set(GUI_CMD_SRCS mrview.cpp shview.cpp)

file(GLOB HEADLESS_CMD_SRCS *.cpp)
Expand Down Expand Up @@ -26,8 +30,8 @@ function(add_cmd CMD_SRC IS_GUI)
get_filename_component(CMD_NAME ${CMD_SRC} NAME_WE)
add_executable(${CMD_NAME} ${CMD_SRC})
target_link_libraries(${CMD_NAME} PRIVATE
$<IF:$<BOOL:${IS_GUI}>,mrtrix::gui,mrtrix::headless>
mrtrix::exec-version-lib
$<IF:$<BOOL:${IS_GUI}>,mrtrix::gui,mrtrix::core>
mrtrix::executable-version
)
set_target_properties(${CMD_NAME} PROPERTIES
LINK_DEPENDS_NO_SHARED true
Expand Down
2 changes: 1 addition & 1 deletion cmd/afdconnectivity.cpp → cpp/cmd/afdconnectivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "dwi/tractography/mapping/mapping.h"
#include "dwi/tractography/properties.h"
#include "memory.h"
#include "version.h"
#include "mrtrix_version.h"

using namespace MR;
using namespace MR::DWI;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/labelconvert.cpp → cpp/cmd/labelconvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include "image.h"
#include "image_helpers.h"
#include "mrtrix.h"
#include "mrtrix_version.h"
#include "transform.h"
#include "version.h"

#include "algo/loop.h"
#include "file/path.h"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions cmd/mrview.cpp → cpp/cmd/mrview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*/

// clang-format off
#include "gui/gui.h"
#include "gui.h"
#include "command.h"
// clang-format on

#include "gui/mrview/icons.h"
#include "gui/mrview/mode/list.h"
#include "gui/mrview/sync/syncmanager.h"
#include "gui/mrview/tool/list.h"
#include "gui/mrview/window.h"
#include "memory.h"
#include "mrview/icons.h"
#include "mrview/mode/list.h"
#include "mrview/sync/syncmanager.h"
#include "mrview/tool/list.h"
#include "mrview/window.h"
#include "progressbar.h"

using namespace MR;
Expand Down Expand Up @@ -75,7 +75,7 @@ void usage() {
MR::GUI::MRView::Tool::classname::add_commandline_options(OPTIONS);
{
using namespace MR::GUI::MRView::Tool;
#include "gui/mrview/tool/list.h"
#include "mrview/tool/list.h"
}

REQUIRES_AT_LEAST_ONE_ARGUMENT = false;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions cmd/shview.cpp → cpp/cmd/shview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/

// clang-format off
#include "gui/gui.h"
#include "gui.h"
#include "command.h"
// clang-format on

#include "file/path.h"
#include "gui/shview/icons.h"
#include "gui/shview/render_window.h"
#include "math/SH.h"
#include "progressbar.h"
#include "shview/icons.h"
#include "shview/render_window.h"

using namespace MR;
using namespace App;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/tckglobal.cpp → cpp/cmd/tckglobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include "file/matrix.h"
#include "image.h"
#include "math/SH.h"
#include "mrtrix_version.h"
#include "thread.h"
#include "version.h"

#include "dwi/tractography/GT/externalenergy.h"
#include "dwi/tractography/GT/gt.h"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 39d3488

Please sign in to comment.