Skip to content

Commit

Permalink
- issue 3163: compile resources into app by cmake
Browse files Browse the repository at this point in the history
examples, wizard and icon will now be added as resources by cmake. And we can resolve them from the bundle as well.
  • Loading branch information
fbergmann committed May 11, 2023
1 parent daa46e4 commit 656a051
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
52 changes: 50 additions & 2 deletions copasi/CopasiUI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2019 - 2022 by Pedro Mendes, Rector and Visitors of the
# Copyright (C) 2019 - 2023 by Pedro Mendes, Rector and Visitors of the
# University of Virginia, University of Heidelberg, and University
# of Connecticut School of Medicine.
# All rights reserved.
Expand Down Expand Up @@ -69,9 +69,57 @@ if (BUILD_STATIC_COPASISE)
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
endif (BUILD_STATIC_COPASISE)

add_executable(CopasiUI ${COPASI_UI_FLAGS} ${SOURCES} ${HEADERS})
# need to bundle resource files for apple
set (RESOURCES)
if (APPLE)
file(GLOB_RECURSE WIZARD_RESOURCES "${CMAKE_SOURCE_DIR}/copasi/wizard/help_html/*")
file(GLOB_RECURSE EXAMPLES_RESOURCES "${CMAKE_SOURCE_DIR}/TestSuite/distribution/*")
set (ICNS_FILE "${CMAKE_SOURCE_DIR}/copasi.icns")
set (RESOURCES ${WIZARD_RESOURCES} ${EXAMPLES_RESOURCES} ${ICNS_FILE})
endif()

add_executable(CopasiUI ${COPASI_UI_FLAGS} ${SOURCES} ${HEADERS} ${RESOURCES})
target_link_libraries(CopasiUI libCOPASIUI)

# now modify the package location for the resource files
if (APPLE)

# Wizard files first
foreach (FILE ${WIZARD_RESOURCES})
# Get the relative path from the data-folder to the particular file.
file(RELATIVE_PATH NEW_FILE "${CMAKE_SOURCE_DIR}/copasi/wizard/help_html" ${FILE})

# Get the relative path to the file.
get_filename_component(NEW_FILE_PATH ${NEW_FILE} DIRECTORY)

# Set it's location inside the app package (under Resources).
set_property(SOURCE ${FILE} PROPERTY MACOSX_PACKAGE_LOCATION "Resources/doc/html/${NEW_FILE_PATH}")

# Optional: Add the file to the 'Resources' folder group in Xcode.
# This also preserves folder structure.
source_group("Resources/doc/html/${NEW_FILE_PATH}" FILES "${FILE}")
endforeach ()

# then examples
foreach (FILE ${EXAMPLES_RESOURCES})
# Get the relative path from the data-folder to the particular file.
file(RELATIVE_PATH NEW_FILE "${CMAKE_SOURCE_DIR}/TestSuite/distribution" ${FILE})

# Get the relative path to the file.
get_filename_component(NEW_FILE_PATH ${NEW_FILE} DIRECTORY)

# Set it's location inside the app package (under Resources).
set_property(SOURCE ${FILE} PROPERTY MACOSX_PACKAGE_LOCATION "Resources/examples/${NEW_FILE_PATH}")

# Optional: Add the file to the 'Resources' folder group in Xcode.
# This also preserves folder structure.
source_group("Resources/examples/${NEW_FILE_PATH}" FILES "${FILE}")
endforeach ()
# and icon
set_property(SOURCE ${ICNS_FILE} PROPERTY MACOSX_PACKAGE_LOCATION "Resources")
source_group("Resources" FILES "${ICNS_FILE}")
endif()

if(NOT APPLE)
SET(APPS "\${CMAKE_INSTALL_PREFIX}/bin/CopasiUI${CMAKE_EXECUTABLE_SUFFIX}" CACHE INTERNAL "")
install(TARGETS CopasiUI DESTINATION bin)
Expand Down
9 changes: 7 additions & 2 deletions copasi/commandline/COptions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 - 2022 by Pedro Mendes, Rector and Visitors of the
// Copyright (C) 2019 - 2023 by Pedro Mendes, Rector and Visitors of the
// University of Virginia, University of Heidelberg, and University
// of Connecticut School of Medicine.
// All rights reserved.
Expand Down Expand Up @@ -208,7 +208,12 @@ void COptions::init(C_INT argc, char *argv[])

#ifdef Darwin
setValue("DefaultConfigDir", CDirEntry::dirName(CopasiDir) + "/config");
setValue("ExampleDir", CDirEntry::dirName(CopasiDir) + "/examples");
std::string exampleDir = CDirEntry::dirName(CopasiDir) + "/examples";

if (!CDirEntry::exist(exampleDir))
exampleDir = CopasiDir + "/Contents/Resources/examples";

setValue("ExampleDir", exampleDir);
setValue("WizardDir", CopasiDir + "/Contents/Resources/doc/html");
#elif WIN32
setValue("DefaultConfigDir", CopasiDir + "\\share\\copasi\\config");
Expand Down
4 changes: 2 additions & 2 deletions copasi/utilities/CCopasiParameterGroup.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 - 2021 by Pedro Mendes, Rector and Visitors of the
// Copyright (C) 2019 - 2023 by Pedro Mendes, Rector and Visitors of the
// University of Virginia, University of Heidelberg, and University
// of Connecticut School of Medicine.
// All rights reserved.
Expand Down Expand Up @@ -274,7 +274,7 @@ void CCopasiParameterGroup::createUndoData(CUndoData & undoData,
CUndoData UndoData;

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

if (UndoData.empty()) continue;

Expand Down

0 comments on commit 656a051

Please sign in to comment.