Skip to content

Commit

Permalink
CMake: Add support for windowLibs, OSXLibs, and iOSLibs when using mo…
Browse files Browse the repository at this point in the history
…dules with CMake
  • Loading branch information
reuk authored and Reuben Thomas committed Apr 28, 2020
1 parent e19b724 commit 440a969
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions extras/Build/CMake/JUCEUtils.cmake
Expand Up @@ -416,6 +416,16 @@ endfunction()

# ==================================================================================================

function(_juce_link_libs_from_metadata module_name dict key)
_juce_get_metadata("${dict}" "${key}" libs)

if(libs)
target_link_libraries(${module_name} INTERFACE ${libs})
endif()
endfunction()

# ==================================================================================================

function(juce_add_module module_path)
set(one_value_args INSTALL_PATH INSTALL_EXPORT ALIAS_NAMESPACE)
cmake_parse_arguments(JUCE_ARG "" "${one_value_args}" "" ${ARGN})
Expand Down Expand Up @@ -521,6 +531,8 @@ function(juce_add_module module_path)
find_library("${module_name}_${module_framework}" ${module_framework} REQUIRED)
target_link_libraries(${module_name} INTERFACE "${${module_name}_${module_framework}}")
endforeach()

_juce_link_libs_from_metadata("${module_name}" "${metadata_dict}" OSXLibs)
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
_juce_get_metadata("${metadata_dict}" iOSFrameworks module_iosframeworks)

Expand All @@ -532,6 +544,8 @@ function(juce_add_module module_path)
find_library("${module_name}_${module_framework}" ${module_framework} REQUIRED)
target_link_libraries(${module_name} INTERFACE "${${module_name}_${module_framework}}")
endforeach()

_juce_link_libs_from_metadata("${module_name}" "${metadata_dict}" iOSLibs)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
_juce_get_metadata("${metadata_dict}" linuxPackages module_linuxpackages)

Expand All @@ -540,13 +554,11 @@ function(juce_add_module module_path)
target_link_libraries(${module_name} INTERFACE juce::pkgconfig_${module_name}_LINUX_DEPS)
endif()

_juce_get_metadata("${metadata_dict}" linuxLibs module_linuxlibs)

if(module_linuxlibs)
target_link_libraries(${module_name} INTERFACE ${module_linuxlibs})
endif()
_juce_link_libs_from_metadata("${module_name}" "${metadata_dict}" linuxLibs)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_compile_options(${module_name} INTERFACE /bigobj)

_juce_link_libs_from_metadata("${module_name}" "${metadata_dict}" windowsLibs)
endif()

_juce_get_metadata("${metadata_dict}" dependencies module_dependencies)
Expand Down

3 comments on commit 440a969

@vladvoina
Copy link

Choose a reason for hiding this comment

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

@reuk Thanks for the quick turnaround, but I'm still getting linker errors. Do note that the libs for the different platforms are living in a separate folder (e.g <module_root>/libs/macOSX/x86_64/libABC.a) and the OSXLibs metadata property lists the library ABC (without the lib prefix and .a).

@reuk
Copy link
Member Author

@reuk reuk commented on 440a969 Apr 28, 2020

Choose a reason for hiding this comment

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

Ah, I'd put off handling bundled libraries as I'd assumed most CMake users would want to introduce library dependencies between other targets in their CMake projects, rather than relying on pre-built libraries. Can you tell me a bit more about your use case? Is there a reason you'd prefer to use pre-built libraries, rather than depending on other targets from your build?

@vladvoina
Copy link

@vladvoina vladvoina commented on 440a969 Apr 29, 2020

Choose a reason for hiding this comment

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

Hmm, that is a good point. For the library in question it's easier/better for me to add a target dependency.

However, I do have other modules where I am not sure how to add the third-party libs as target dependency (they don't seem to use cmake and I'm no build system ninja). I'm sure I can find out, but I think in reality there will be other people for whom it's more convenient to use pre-built libraries. Additionally, not handling bundled libraries is effectively a breaking change to the JUCE module format. I'm not implying there should be no breaking changes, but if it is, it should probably be documented.

Any pointers much appreciated!

Please sign in to comment.