Skip to content

Commit 656a051

Browse files
committed
- issue 3163: compile resources into app by cmake
examples, wizard and icon will now be added as resources by cmake. And we can resolve them from the bundle as well.
1 parent daa46e4 commit 656a051

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

copasi/CopasiUI/CMakeLists.txt

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2019 - 2022 by Pedro Mendes, Rector and Visitors of the
1+
# Copyright (C) 2019 - 2023 by Pedro Mendes, Rector and Visitors of the
22
# University of Virginia, University of Heidelberg, and University
33
# of Connecticut School of Medicine.
44
# All rights reserved.
@@ -69,9 +69,57 @@ if (BUILD_STATIC_COPASISE)
6969
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
7070
endif (BUILD_STATIC_COPASISE)
7171

72-
add_executable(CopasiUI ${COPASI_UI_FLAGS} ${SOURCES} ${HEADERS})
72+
# need to bundle resource files for apple
73+
set (RESOURCES)
74+
if (APPLE)
75+
file(GLOB_RECURSE WIZARD_RESOURCES "${CMAKE_SOURCE_DIR}/copasi/wizard/help_html/*")
76+
file(GLOB_RECURSE EXAMPLES_RESOURCES "${CMAKE_SOURCE_DIR}/TestSuite/distribution/*")
77+
set (ICNS_FILE "${CMAKE_SOURCE_DIR}/copasi.icns")
78+
set (RESOURCES ${WIZARD_RESOURCES} ${EXAMPLES_RESOURCES} ${ICNS_FILE})
79+
endif()
80+
81+
add_executable(CopasiUI ${COPASI_UI_FLAGS} ${SOURCES} ${HEADERS} ${RESOURCES})
7382
target_link_libraries(CopasiUI libCOPASIUI)
7483

84+
# now modify the package location for the resource files
85+
if (APPLE)
86+
87+
# Wizard files first
88+
foreach (FILE ${WIZARD_RESOURCES})
89+
# Get the relative path from the data-folder to the particular file.
90+
file(RELATIVE_PATH NEW_FILE "${CMAKE_SOURCE_DIR}/copasi/wizard/help_html" ${FILE})
91+
92+
# Get the relative path to the file.
93+
get_filename_component(NEW_FILE_PATH ${NEW_FILE} DIRECTORY)
94+
95+
# Set it's location inside the app package (under Resources).
96+
set_property(SOURCE ${FILE} PROPERTY MACOSX_PACKAGE_LOCATION "Resources/doc/html/${NEW_FILE_PATH}")
97+
98+
# Optional: Add the file to the 'Resources' folder group in Xcode.
99+
# This also preserves folder structure.
100+
source_group("Resources/doc/html/${NEW_FILE_PATH}" FILES "${FILE}")
101+
endforeach ()
102+
103+
# then examples
104+
foreach (FILE ${EXAMPLES_RESOURCES})
105+
# Get the relative path from the data-folder to the particular file.
106+
file(RELATIVE_PATH NEW_FILE "${CMAKE_SOURCE_DIR}/TestSuite/distribution" ${FILE})
107+
108+
# Get the relative path to the file.
109+
get_filename_component(NEW_FILE_PATH ${NEW_FILE} DIRECTORY)
110+
111+
# Set it's location inside the app package (under Resources).
112+
set_property(SOURCE ${FILE} PROPERTY MACOSX_PACKAGE_LOCATION "Resources/examples/${NEW_FILE_PATH}")
113+
114+
# Optional: Add the file to the 'Resources' folder group in Xcode.
115+
# This also preserves folder structure.
116+
source_group("Resources/examples/${NEW_FILE_PATH}" FILES "${FILE}")
117+
endforeach ()
118+
# and icon
119+
set_property(SOURCE ${ICNS_FILE} PROPERTY MACOSX_PACKAGE_LOCATION "Resources")
120+
source_group("Resources" FILES "${ICNS_FILE}")
121+
endif()
122+
75123
if(NOT APPLE)
76124
SET(APPS "\${CMAKE_INSTALL_PREFIX}/bin/CopasiUI${CMAKE_EXECUTABLE_SUFFIX}" CACHE INTERNAL "")
77125
install(TARGETS CopasiUI DESTINATION bin)

copasi/commandline/COptions.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2019 - 2022 by Pedro Mendes, Rector and Visitors of the
1+
// Copyright (C) 2019 - 2023 by Pedro Mendes, Rector and Visitors of the
22
// University of Virginia, University of Heidelberg, and University
33
// of Connecticut School of Medicine.
44
// All rights reserved.
@@ -208,7 +208,12 @@ void COptions::init(C_INT argc, char *argv[])
208208

209209
#ifdef Darwin
210210
setValue("DefaultConfigDir", CDirEntry::dirName(CopasiDir) + "/config");
211-
setValue("ExampleDir", CDirEntry::dirName(CopasiDir) + "/examples");
211+
std::string exampleDir = CDirEntry::dirName(CopasiDir) + "/examples";
212+
213+
if (!CDirEntry::exist(exampleDir))
214+
exampleDir = CopasiDir + "/Contents/Resources/examples";
215+
216+
setValue("ExampleDir", exampleDir);
212217
setValue("WizardDir", CopasiDir + "/Contents/Resources/doc/html");
213218
#elif WIN32
214219
setValue("DefaultConfigDir", CopasiDir + "\\share\\copasi\\config");

copasi/utilities/CCopasiParameterGroup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2019 - 2021 by Pedro Mendes, Rector and Visitors of the
1+
// Copyright (C) 2019 - 2023 by Pedro Mendes, Rector and Visitors of the
22
// University of Virginia, University of Heidelberg, and University
33
// of Connecticut School of Medicine.
44
// All rights reserved.
@@ -274,7 +274,7 @@ void CCopasiParameterGroup::createUndoData(CUndoData & undoData,
274274
CUndoData UndoData;
275275

276276
itChanged->second->createUndoData(UndoData, CUndoData::Type::CHANGE, * itChanged->first, framework);
277-
UndoData.addProperty(CData::OBJECT_INDEX, OldCorrectedIndex, NewCorrectedIndex);
277+
UndoData.addProperty(CData::OBJECT_INDEX, (C_INT32)OldCorrectedIndex, (C_INT32)NewCorrectedIndex);
278278

279279
if (UndoData.empty()) continue;
280280

0 commit comments

Comments
 (0)