Skip to content

Commit ef4b7ba

Browse files
committed
ENH: Add C++ build and test tasks
Update CMakeLists.txt. Update manuscript tasks and their names.
1 parent 76bcdc5 commit ef4b7ba

File tree

4 files changed

+80
-69
lines changed

4 files changed

+80
-69
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ env/
5555
.env
5656

5757
exports/
58+
src/img1.png.base.png

myst.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ project:
5151
- format: pdf
5252
template: arxiv_nips
5353
article_type: research-article
54-
output: exports/arxiv.pdf
54+
output: exports/manuscript-arxiv-format.pdf
5555
- format: tex
5656
template: arxiv_nips
5757
output: exports/manuscript.tex

pixi.toml

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,11 @@ build-arxiv = "myst build --pdf"
3838
build-tex = "myst build --tex"
3939
build-docx = "myst build --docx"
4040
build-cff = "myst build --cff"
41-
build-meca = "myst build --meca"
4241

4342
# Combined tasks
44-
build = { depends-on = ["build-html", "build-pdf", "build-cff"] }
43+
build-manuscript = { depends-on = ["build-html", "build-pdf", "build-cff"] }
4544
build-pdfs = { depends-on = ["build-pdf", "build-arxiv"] }
46-
build-complete = { depends-on = ["build-html", "build-pdfs", "build-tex", "build-docx", "build-cff", "build-meca"] }
47-
48-
# Build source code
49-
build-src = { cmd = "mkdir -p build && cd build && cmake ../src && make", cwd = "." }
50-
test-src = { cmd = "cd build && ctest", cwd = ".", depends-on = ["build-src"] }
45+
build-meca = { cmd = "myst build --meca", depends-on = ["build-html", "build-pdfs", "build-tex", "build-docx", "build-cff"] }
5146

5247
# Start development server
5348
start = "myst start"
@@ -57,16 +52,54 @@ dev = { depends-on = ["serve"] }
5752
# Clean build artifacts
5853
clean = "myst clean"
5954

60-
[feature.cmake.dependencies]
55+
# Aggregate, standard build task
56+
build = { depends-on = ["build-manuscript", "test-project"] }
57+
58+
[feature.cxx.dependencies]
6159
cmake = "*"
6260
make = "*"
6361
ninja = "*"
6462

65-
[feature.cmake.tasks]
66-
configure-cmake = "cmake -B build -S src"
67-
build-cmake = "cmake --build build"
68-
test-cmake = "cd build && ctest"
63+
[feature.cxx.tasks.clone-itk]
64+
cmd = ["stat", "build/ITK", ">/dev/null", "||",
65+
"git", "clone",
66+
"https://github.com/InsightSoftwareConsortium/ITK",
67+
"build/ITK"]
68+
outputs = ["build/ITK/LICENSE"]
69+
description = "Fetch ITK's source code"
70+
71+
[feature.cxx.tasks.configure-itk]
72+
cmd = '''cmake -Bbuild/ITK-build -Sbuild/ITK -GNinja
73+
-DBUILD_EXAMPLES:BOOL=OFF
74+
-DBUILD_TESTING:BOOL=OFF'''
75+
depends-on = ["clone-itk"]
76+
outputs = ["build/ITK-build/CMakeFiles/**"]
77+
description = "Configure ITK"
78+
79+
[feature.cxx.tasks.build-itk]
80+
cmd = "cmake --build build/ITK-build"
81+
depends-on = ["configure-itk"]
82+
outputs = ["build/ITK-build/**"]
83+
description = "Build ITK"
84+
85+
[feature.cxx.tasks.configure-project]
86+
cmd = '''cmake -Bbuild/project-build -Ssrc -GNinja
87+
-DITK_DIR=$(pwd)/build/ITK-build'''
88+
depends-on = ["build-itk"]
89+
outputs = ["build/project-build/CMakeFiles/**"]
90+
description = "Configure the project"
91+
92+
[feature.cxx.tasks.build-project]
93+
cmd = "cmake --build build/project-build"
94+
depends-on = ["configure-project"]
95+
outputs = ["build/project-build/**"]
96+
description = "Build the project"
97+
98+
[feature.cxx.tasks.test-project]
99+
cmd = "cd build/project-build && ctest"
100+
depends-on = ["build-project"]
101+
description = "Test the project"
69102

70103
[environments]
71104
default = { features = [], solve-group = "default" }
72-
dev = { features = ["cmake"], solve-group = "default" }
105+
cxx = { features = ["cxx"], solve-group = "default" }

src/CMakeLists.txt

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,37 @@
1-
cmake_minimum_required(VERSION 2.8)
2-
INCLUDE(${CMAKE_SOURCE_DIR}/IJMacros.txt)
3-
4-
#Change PROJECT_NAME to the name of your project
5-
PROJECT(ImageCopy)
6-
7-
#The following lines are required to use Dart
8-
ENABLE_TESTING()
9-
INCLUDE(Dart)
10-
11-
#Declare any external dependencies that your project may have here.
12-
#examples include: ITK, VTK, JPEG, PNG, OpenGL, ZLIB, Perl, Java
13-
#If you're not sure what name to use, look in the Modules directory of your
14-
#cmake install and check that a file named Find(Package).cmake exists
15-
#
16-
# The packages can be specified with a version number, for example:
17-
#
18-
# ITK 3.2.0
19-
# ITK 4.6.0
20-
#
21-
# If no version is specified, the most recent release of the package
22-
# will be used.
23-
SET(Required_Packages
24-
ITK
1+
cmake_minimum_required(VERSION 3.16.3)
2+
3+
# Set project name and description
4+
project(InsightJournalTemplate
5+
VERSION 1.0.0
6+
DESCRIPTION "Template for Insight Journal submissions with ITK image processing examples"
7+
LANGUAGES CXX
258
)
269

27-
#this foreach loads all of the packages that you specified as required.
28-
#It shouldn't need to be modified.
29-
FOREACH(Package ${Required_Packages})
30-
LOADPACKAGE(${Package})
31-
ENDFOREACH(Package)
10+
# Set C++ standard
11+
set(CMAKE_CXX_STANDARD 17)
12+
13+
# Find ITK
14+
find_package(ITK REQUIRED)
15+
include(${ITK_USE_FILE})
16+
17+
# Enable testing
18+
include(CTest)
19+
enable_testing()
3220

33-
#Set any libraries that your project depends on.
34-
#examples: ITKCommon, VTKRendering, etc
35-
SET(Libraries
36-
${ITK_LIBRARIES}
21+
# Add executables
22+
add_executable(ImageCompare ImageCompare.cxx)
23+
target_link_libraries(ImageCompare PUBLIC ${ITK_LIBRARIES})
24+
25+
add_executable(ImageCopy ImageCopy.cxx)
26+
target_link_libraries(ImageCopy PUBLIC ${ITK_LIBRARIES})
27+
28+
# Add tests
29+
add_test(
30+
NAME CreateImage
31+
COMMAND ImageCopy ${CMAKE_SOURCE_DIR}/img1.png
3732
)
3833

39-
#the following block of code is an example of how to build an executable in
40-
#cmake. Unmodified, it will add an executable called "MyExe" to the project.
41-
#MyExe will be built using the files MyClass.h and MyClass.cxx, and it will
42-
#be linked to all the libraries you specified above.
43-
#You can build more than one executable per project
44-
SET(CurrentExe "ImageCompare")
45-
ADD_EXECUTABLE(${CurrentExe} ImageCompare.cxx)
46-
TARGET_LINK_LIBRARIES(${CurrentExe} ${Libraries})
47-
SET(CurrentExe "ImageCopy")
48-
ADD_EXECUTABLE(${CurrentExe} ImageCopy.cxx)
49-
TARGET_LINK_LIBRARIES(${CurrentExe} ${Libraries})
50-
51-
#the following line is an example of how to add a test to your project.
52-
#Testname is the title for this particular test. ExecutableToRun is the
53-
#program which will be running this test. It can either be a part of this
54-
#project or an external executable. After that list any args that are needed
55-
#for this test. Include as many tests as you like. If your project doesn't have
56-
#any tests you can comment out or delete the following line.
57-
ADD_TEST(CreateImage ImageCopy ${CMAKE_SOURCE_DIR}/img1.png)
58-
ADD_TEST(CompareImage ImageCompare ${CMAKE_SOURCE_DIR}/img1.png ${CMAKE_SOURCE_DIR}/img1.png.base.png)
59-
60-
#Once you're done modifying this template, you should rename it to "CMakeLists.txt"
34+
add_test(
35+
NAME CompareImage
36+
COMMAND ImageCompare ${CMAKE_SOURCE_DIR}/img1.png ${CMAKE_SOURCE_DIR}/img1.png.base.png
37+
)

0 commit comments

Comments
 (0)