Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[portmidi] Add non-Windows support, refactory install process #19710

Merged
merged 16 commits into from
Sep 17, 2021
5 changes: 0 additions & 5 deletions ports/portmidi/CONTROL

This file was deleted.

50 changes: 50 additions & 0 deletions ports/portmidi/add-feature-options.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
diff --git a/portmidi/trunk/CMakeLists.txt b/portmidi/trunk/CMakeLists.txt
index 4919b78..d387a26 100644
--- a/portmidi/trunk/CMakeLists.txt
+++ b/portmidi/trunk/CMakeLists.txt
@@ -68,10 +68,14 @@ endif(UNIX)
include_directories(pm_common porttime)
add_subdirectory(pm_common)

+if (0)
add_subdirectory(pm_test)
+endif()

add_subdirectory(pm_dylib)

# Cannot figure out how to make an xcode Java application with CMake
+if (JAVA_SUPPORT)
add_subdirectory(pm_java)
+endif()

diff --git a/portmidi/trunk/pm_common/CMakeLists.txt b/portmidi/trunk/pm_common/CMakeLists.txt
index 01866e3..915cf9f 100644
--- a/portmidi/trunk/pm_common/CMakeLists.txt
+++ b/portmidi/trunk/pm_common/CMakeLists.txt
@@ -113,17 +113,25 @@ target_link_libraries(portmidi-static ${PM_NEEDED_LIBS})
# define the jni library
include_directories(${JAVA_INCLUDE_PATHS})

+if (JAVA_SUPPORT)
set(JNISRC ${LIBSRC} ../pm_java/pmjni/pmjni.c)
add_library(pmjni SHARED ${JNISRC})
target_link_libraries(pmjni ${JNI_EXTRA_LIBS})
set_target_properties(pmjni PROPERTIES EXECUTABLE_EXTENSION "jnilib")
+endif()

# install the libraries (Linux and Mac OS X command line)
if(1)
- INSTALL(TARGETS portmidi-static pmjni
+ INSTALL(TARGETS portmidi-static
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
+ if (JAVA_SUPPORT)
+ INSTALL(TARGETS pmjni
Copy link
Contributor Author

@JackBoosY JackBoosY Aug 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This target pmjni requires java executable on local machine, so I disabled it.
In source/portmidi/trunk/pm_java/CMakeLists.txt:

    add_custom_command(OUTPUT pmdefaults/PmDefaultsFrame.class
        COMMAND javac -classpath . pmdefaults/PmDefaultsFrame.java
	MAIN_DEPENDENCY pmdefaults/PmDefaultsFrame.java
	DEPENDS pmdefaults/PmDefaults.java
	WORKING_DIRECTORY .)
    add_custom_command(OUTPUT pmdefaults/PmDefaults.class
        COMMAND javac -classpath . pmdefaults/PmDefaults.java
	MAIN_DEPENDENCY pmdefaults/PmDefaults.java
	DEPENDS pmdefaults/PmDefaultsFrame.java
	WORKING_DIRECTORY .)

+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)
+ endif()
# .h files installed by pm_dylib/CMakeLists.txt, so don't need them here
INSTALL(FILES portmidi.h ../porttime/porttime.h
DESTINATION include)
79 changes: 79 additions & 0 deletions ports/portmidi/fix-build-install.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
diff --git a/portmidi/trunk/pm_common/CMakeLists.txt b/portmidi/trunk/pm_common/CMakeLists.txt
index cbeeade..01866e3 100644
--- a/portmidi/trunk/pm_common/CMakeLists.txt
+++ b/portmidi/trunk/pm_common/CMakeLists.txt
@@ -104,8 +104,9 @@ set(JNI_EXTRA_LIBS ${PM_NEEDED_LIBS} ${JAVA_JVM_LIBRARY})
# this completes the list of library sources by adding shared code
list(APPEND LIBSRC pmutil portmidi)

+if (NOT BUILD_SHARED_LIBS)
# now add the shared files to make the complete list of library sources
-add_library(portmidi-static ${LIBSRC})
+add_library(portmidi-static STATIC ${LIBSRC})
set_target_properties(portmidi-static PROPERTIES OUTPUT_NAME "portmidi_s")
target_link_libraries(portmidi-static ${PM_NEEDED_LIBS})

@@ -118,11 +119,13 @@ target_link_libraries(pmjni ${JNI_EXTRA_LIBS})
set_target_properties(pmjni PROPERTIES EXECUTABLE_EXTENSION "jnilib")

# install the libraries (Linux and Mac OS X command line)
-if(UNIX)
+if(1)
INSTALL(TARGETS portmidi-static pmjni
- LIBRARY DESTINATION /usr/local/lib
- ARCHIVE DESTINATION /usr/local/lib)
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)
# .h files installed by pm_dylib/CMakeLists.txt, so don't need them here
-# INSTALL(FILES portmidi.h ../porttime/porttime.h
-# DESTINATION /usr/local/include)
-endif(UNIX)
+ INSTALL(FILES portmidi.h ../porttime/porttime.h
+ DESTINATION include)
+endif(1)
+endif()
diff --git a/portmidi/trunk/pm_common/portmidi.h b/portmidi/trunk/pm_common/portmidi.h
index e07991e..2187c3e 100644
--- a/portmidi/trunk/pm_common/portmidi.h
+++ b/portmidi/trunk/pm_common/portmidi.h
@@ -108,6 +108,8 @@ typedef unsigned int uint32_t;

#ifdef _WINDLL
#define PMEXPORT __declspec(dllexport)
+#elif defined _USEDLL
+#define PMEXPORT __declspec(dllexport)
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved
#else
#define PMEXPORT
#endif
diff --git a/portmidi/trunk/pm_dylib/CMakeLists.txt b/portmidi/trunk/pm_dylib/CMakeLists.txt
index f693dd6..f2994d1 100644
--- a/portmidi/trunk/pm_dylib/CMakeLists.txt
+++ b/portmidi/trunk/pm_dylib/CMakeLists.txt
@@ -113,15 +113,21 @@ set(SHARED_FILES pmutil portmidi)
prepend_path(SHARED_PATHS ../pm_common/ ${SHARED_FILES})
list(APPEND LIBSRC ${SHARED_PATHS})

+if (BUILD_SHARED_LIBS)
add_library(portmidi-dynamic SHARED ${LIBSRC})
set_target_properties(portmidi-dynamic PROPERTIES OUTPUT_NAME "portmidi")
target_link_libraries(portmidi-dynamic ${PM_NEEDED_LIBS})
+if (MSVC)
+ target_compile_definitions(portmidi-dynamic PRIVATE _WINDLL)
+endif()

# install the libraries (Linux and Mac OS X command line)
-if(UNIX)
+if(1)
INSTALL(TARGETS portmidi-dynamic
- LIBRARY DESTINATION /usr/local/lib
- ARCHIVE DESTINATION /usr/local/lib)
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)
INSTALL(FILES ../pm_common/portmidi.h ../porttime/porttime.h
- DESTINATION /usr/local/include)
-endif(UNIX)
+ DESTINATION include)
+endif(1)
+endif()
45 changes: 15 additions & 30 deletions ports/portmidi/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,47 +1,32 @@
vcpkg_fail_port_install(ON_TARGET "linux" "osx" "uwp" ON_ARCH "arm")
vcpkg_fail_port_install(ON_TARGET "uwp" ON_ARCH "arm")

vcpkg_from_sourceforge(
OUT_SOURCE_PATH SOURCE_PATH
REPO portmedia
FILENAME "portmedia-code-r234.zip"
SHA512 cbc332d89bc465450b38245a83cc300dfd2e1e6de7c62284edf754ff4d8a9aa3dc49a395dcee535ed9688befb019186fa87fd6d8a3698898c2acbf3e6b7a0794
PATCHES
fix-build-install.patch
add-feature-options.patch
)

# Alter path to main portmidi root
set(SOURCE_PATH "${SOURCE_PATH}/portmidi/trunk")

# Mark portmidi-static as static, disable pmjni library depending on the Java SDK

file(READ "${SOURCE_PATH}/pm_common/CMakeLists.txt" PM_CMAKE)
string(REPLACE "add_library(portmidi-static \${LIBSRC})" "add_library(portmidi-static STATIC \${LIBSRC})" PM_CMAKE "${PM_CMAKE}")
string(REPLACE "add_library(pmjni SHARED \${JNISRC})" "# Removed pmjni" PM_CMAKE "${PM_CMAKE}")
string(REPLACE "target_link_libraries(pmjni \${JNI_EXTRA_LIBS})" "# Removed pmjni" PM_CMAKE "${PM_CMAKE}")
string(REPLACE "set_target_properties(pmjni PROPERTIES EXECUTABLE_EXTENSION \"jnilib\")" "# Removed pmjni" PM_CMAKE "${PM_CMAKE}")
file(WRITE "${SOURCE_PATH}/pm_common/CMakeLists.txt" "${PM_CMAKE}")

# Run cmake configure step
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}/portmidi/trunk"
OPTIONS
-DJAVA_SUPPORT=OFF
-DJAVA_INCLUDE_PATH=
-DJAVA_INCLUDE_PATH2=
-DJAVA_JVM_LIBRARY=
)

# Run cmake build step, nothing is installed on Windows
vcpkg_build_cmake()
vcpkg_cmake_install()

file(INSTALL ${SOURCE_PATH}/pm_common/portmidi.h DESTINATION ${CURRENT_PACKAGES_DIR}/include)
file(INSTALL ${SOURCE_PATH}/porttime/porttime.h DESTINATION ${CURRENT_PACKAGES_DIR}/include)

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/Release/portmidi_s.lib DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/Debug/portmidi_s.lib DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
else()
file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/Release/portmidi.dll DESTINATION ${CURRENT_PACKAGES_DIR}/bin)
file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/Release/portmidi.lib DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/Debug/portmidi.dll DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin)
file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/Debug/portmidi.lib DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
if (VCPKG_TARGET_IS_WINDOWS AND VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/portmidi.h"
"#elif defined _USEDLL" "#elif 1"
)
endif()

file(INSTALL ${SOURCE_PATH}/license.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/portmidi RENAME copyright)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

file(INSTALL "${SOURCE_PATH}/portmidi/trunk/license.txt" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
14 changes: 14 additions & 0 deletions ports/portmidi/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "portmidi",
"version-string": "0.234",
"port-version": 1,
"description": "Free, cross-platform, open-source I/O library for MIDI",
"homepage": "https://sourceforge.net/projects/portmedia/",
"supports": "!(uwp | arm)",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
}
]
}
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -5046,7 +5046,7 @@
},
"portmidi": {
"baseline": "0.234",
"port-version": 0
"port-version": 1
},
"portsmf": {
"baseline": "0.238",
Expand Down
5 changes: 5 additions & 0 deletions versions/p-/portmidi.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "25c860cdf27c3b71ccbdf9e48af5e6bbe4c9276f",
"version-string": "0.234",
"port-version": 1
},
{
"git-tree": "16f079de23d02226d49bd22659392d85e568528e",
"version-string": "0.234",
Expand Down