Skip to content

Guidance on using an external library in a min project #208

Open
@isabelgk

Description

@isabelgk

I would certainly appreciate some better (or simpler) guidance on how to use CMake to link an external library (on an arbitrary path) with a min project.

I don't understand CMake, and trying to link my project to an arbitrary .lib file already compiled from a solution is doing my head in. I have managed the include file, but getting the subsequent project to link has proved impossible.

Originally posted by @scblakely in #204 (comment)

Activity

isabelgk

isabelgk commented on Feb 20, 2023

@isabelgk
ContributorAuthor

For now, how I'd do it something like this in your external's CMakeLists.txt. I haven't tested this exact set up, but I've done it similarly to this in the past.

cmake_minimum_required(VERSION 3.0)

set(C74_MIN_API_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../min-api)
include(${C74_MIN_API_DIR}/script/min-pretarget.cmake)

include_directories( 
	"${C74_INCLUDES}"
)

set( SOURCE_FILES
	${PROJECT_NAME}.cpp
)

add_library( 
	${PROJECT_NAME} 
	MODULE
	${SOURCE_FILES}
)

#   ====== see this section
#  /
# v
if (MSVC)
    # include any headers needed by your library that's kept at <repository root>/libs/include,
    # and you can change for your situation
    include_directories("${CMAKE_SOURCE_DIR}/libs/include")

    # this links to a library that's kept at <repository root>/libs/foo.lib, and you can change for your situation
    target_link_libraries(${PROJECT_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/libs/foo.lib")
endif()


include(${C74_MIN_API_DIR}/script/min-posttarget.cmake)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @isabelgk

        Issue actions

          Guidance on using an external library in a min project · Issue #208 · Cycling74/min-devkit