Skip to content

Commit 6819ebf

Browse files
authored
Remove model name prefix in generated model files (#2015)
Helps to avoid issues with too long paths on Windows 💩
1 parent 2aef279 commit 6819ebf

File tree

226 files changed

+306
-595
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

226 files changed

+306
-595
lines changed

documentation/cpp_interface.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ The content of a model source directory looks something like this (given
2929
3030
CMakeLists.txt
3131
main.cpp
32-
model_steadystate_deltaqB.cpp
33-
model_steadystate_deltaqB.h
34-
[... many more files model_steadystate_*.(cpp|h|md5|o) ]
32+
deltaqB.cpp
33+
deltaqB.h
34+
[... many more files *.(cpp|h|md5|o) ]
3535
wrapfunctions.cpp
3636
wrapfunctions.h
3737
model_steadystate.h
38+
model_steadystate.cpp
3839
3940
These files provide the implementation of a model-specific subclass of
4041
:cpp:class:`amici::Model`. The ``CMakeLists.txt`` file can be used to build the

matlab/@amimodel/compileAndLinkModel.m

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ function compileAndLinkModel(modelname, modelSourceFolder, coptim, debug, funs,
2020
% if no list provided, try to determine relevant files from model
2121
% folder
2222
if(isempty(funs))
23-
ls = dir(fullfile(modelSourceFolder, [modelname '_*.cpp']));
23+
ls = dir(fullfile(modelSourceFolder, '*.cpp'));
24+
% wrapfunctions is handled separately
2425
ls = {ls.name};
26+
ls = ls(cellfun(@(x) ~strcmp(x, "wrapfunctions.cpp"), ls));
2527
% extract funs from filename (strip of modelname_ and .cpp
26-
funs = cellfun(@(x) x((length(modelname)+2):(length(x)-4)), ls, 'UniformOutput', false);
28+
funs = cellfun(@(x) x(1:(length(x)-4)), ls, 'UniformOutput', false);
2729
end
2830

2931
objectFileSuffix = '.o';
@@ -74,7 +76,7 @@ function compileAndLinkModel(modelname, modelSourceFolder, coptim, debug, funs,
7476

7577
%% Model-specific files
7678
for j=1:length(funs)
77-
baseFileName = [modelname '_' strrep(funs{j}, 'sigma_', 'sigma')];
79+
baseFileName = strrep(funs{j}, 'sigma_', 'sigma');
7880
cfun(1).(funs{j}) = sourceNeedsRecompilation(modelSourceFolder, modelObjectFolder, baseFileName, objectFileSuffix);
7981
end
8082

@@ -124,7 +126,7 @@ function compileAndLinkModel(modelname, modelSourceFolder, coptim, debug, funs,
124126
if(numel(funsForRecompile))
125127
fprintf('ffuns | ');
126128

127-
sources = cellfun(@(x) ['"' fullfile(modelSourceFolder,[modelname '_' x '.cpp']) '"'],funsForRecompile,'UniformOutput',false);
129+
sources = cellfun(@(x) ['"' fullfile(modelSourceFolder,[x '.cpp']) '"'],funsForRecompile,'UniformOutput',false);
128130
sources = strjoin(sources,' ');
129131

130132
cmd = ['mex ' DEBUG COPT ...
@@ -136,15 +138,14 @@ function compileAndLinkModel(modelname, modelSourceFolder, coptim, debug, funs,
136138
disp(cmd);
137139
rethrow(ME);
138140
end
139-
cellfun(@(x) updateFileHashSource(modelSourceFolder, modelObjectFolder, [modelname '_' x]),funsForRecompile,'UniformOutput',false);
141+
cellfun(@(x) updateFileHashSource(modelSourceFolder, modelObjectFolder, x),funsForRecompile,'UniformOutput',false);
140142
end
141143

142144
% append model object files
143145
for j=1:length(funs)
144-
filename = fullfile(modelObjectFolder, [modelname '_' strrep(funs{j}, 'sigma_', 'sigma') objectFileSuffix]);
146+
filename = fullfile(modelObjectFolder, [strrep(funs{j}, 'sigma_', 'sigma') objectFileSuffix]);
145147
if(exist(filename,'file'))
146-
objectsstr = strcat(objectsstr,...
147-
' "',filename,'"');
148+
objectsstr = strcat(objectsstr, ' "',filename,'"');
148149
end
149150
end
150151

matlab/@amimodel/generateC.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function generateC(this)
2626

2727
if(bodyNotEmpty)
2828
fprintf([ifun{1} ' | ']);
29-
fid = fopen(fullfile(this.wrap_path,'models',this.modelname,[this.modelname '_' cppFunctionName '.cpp']),'w');
29+
fid = fopen(fullfile(this.wrap_path,'models',this.modelname,[ cppFunctionName '.cpp']),'w');
3030
fprintf(fid,'\n');
3131
fprintf(fid,'#include "amici/symbolic_functions.h"\n');
3232
fprintf(fid,'#include "amici/defines.h" //realtype definition\n');
@@ -267,7 +267,7 @@ function generateCMakeFile(this)
267267
funcName = this.funs{j};
268268
if(checkIfFunctionBodyIsNonEmpty(this,funcName))
269269
cppFunctionName = strrep(funcName, 'sigma_', 'sigma');
270-
sourceStr = [ sourceStr, sprintf('${MODEL_DIR}/%s_%s.cpp\n', this.modelname, cppFunctionName) ];
270+
sourceStr = [ sourceStr, sprintf('${MODEL_DIR}/%s.cpp\n', cppFunctionName) ];
271271
end
272272
end
273273

@@ -315,5 +315,5 @@ function generateMainC(this)
315315
% if we don't have symbolic variables, it might have been generated before and symbolic expressions were simply not
316316
% regenerated. any() for empty (no generated) variables is always false.
317317
cppFunctionName = strrep(ifun, 'sigma_', 'sigma');
318-
nonempty = or(exist(fullfile(this.wrap_path,'models',this.modelname,[this.modelname '_' cppFunctionName '.cpp']),'file'),any(this.fun.(ifun).sym(:)~=0));
318+
nonempty = or(exist(fullfile(this.wrap_path,'models',this.modelname,[cppFunctionName '.cpp']),'file'),any(this.fun.(ifun).sym(:)~=0));
319319
end

models/model_calvetti/CMakeLists.txt

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
cmake_minimum_required(VERSION 3.3)
2-
3-
if(POLICY CMP0060)
4-
cmake_policy(SET CMP0060 NEW)
5-
endif(POLICY CMP0060)
6-
if(POLICY CMP0065)
7-
cmake_policy(SET CMP0065 NEW)
8-
endif(POLICY CMP0065)
9-
if(POLICY CMP0074)
10-
# Use package_ROOT environment variables
11-
cmake_policy(SET CMP0074 NEW)
12-
endif(POLICY CMP0074)
1+
cmake_minimum_required(VERSION 3.15)
132

143
project(model_calvetti)
154

@@ -30,24 +19,24 @@ foreach(FLAG ${MY_CXX_FLAGS})
3019
endif()
3120
endforeach(FLAG)
3221

33-
find_package(Amici HINTS ${CMAKE_CURRENT_LIST_DIR}/../../build)
22+
find_package(Amici REQUIRED HINTS ${CMAKE_CURRENT_LIST_DIR}/../../build)
3423
message(STATUS "Found AMICI ${Amici_DIR}")
3524

3625
set(MODEL_DIR ${CMAKE_CURRENT_LIST_DIR})
3726

38-
set(SRC_LIST_LIB ${MODEL_DIR}/model_calvetti_JSparse.cpp
39-
${MODEL_DIR}/model_calvetti_Jy.cpp
40-
${MODEL_DIR}/model_calvetti_M.cpp
41-
${MODEL_DIR}/model_calvetti_dJydsigma.cpp
42-
${MODEL_DIR}/model_calvetti_dJydy.cpp
43-
${MODEL_DIR}/model_calvetti_dwdx.cpp
44-
${MODEL_DIR}/model_calvetti_dydx.cpp
45-
${MODEL_DIR}/model_calvetti_root.cpp
46-
${MODEL_DIR}/model_calvetti_sigmay.cpp
47-
${MODEL_DIR}/model_calvetti_w.cpp
48-
${MODEL_DIR}/model_calvetti_x0.cpp
49-
${MODEL_DIR}/model_calvetti_xdot.cpp
50-
${MODEL_DIR}/model_calvetti_y.cpp
27+
set(SRC_LIST_LIB ${MODEL_DIR}/JSparse.cpp
28+
${MODEL_DIR}/Jy.cpp
29+
${MODEL_DIR}/M.cpp
30+
${MODEL_DIR}/dJydsigma.cpp
31+
${MODEL_DIR}/dJydy.cpp
32+
${MODEL_DIR}/dwdx.cpp
33+
${MODEL_DIR}/dydx.cpp
34+
${MODEL_DIR}/root.cpp
35+
${MODEL_DIR}/sigmay.cpp
36+
${MODEL_DIR}/w.cpp
37+
${MODEL_DIR}/x0.cpp
38+
${MODEL_DIR}/xdot.cpp
39+
${MODEL_DIR}/y.cpp
5140

5241
${MODEL_DIR}/wrapfunctions.cpp
5342
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)