Hello, Patrik, you may try to do something like:
# FindMyLib.cmake - helper Find-module for MyLib.
#[=======================================================================[.rst:
FindMyLib
---------
Finds the MyLib.
Input variables
^^^^^^^^^^^^^^^
MyLib_DIR - the hint directory in which the MyLib may be found.
Imported Targets
^^^^^^^^^^^^^^^^
This module provides the following imported targets, if found:
``MyLib::MyLib``
The MyLib library.
Result Variables
^^^^^^^^^^^^^^^^
This will define the following variables:
``MyLib_FOUND``
True, if the system has the MyLib library.
``MyLib_LIBRARY``
The path for founded library.
#]=======================================================================]
find_library(MyLib_LIBRARY MyLib HINTS MyLib_DIR)
# helper for reporting the `find_package(MyLib)`
# resulting status.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MyLib
FOUND_VAR MyLib_FOUND
REQUIRED_VARS
MyLib_LIBRARY
)
if (MyLib_FOUND AND NOT TARGET MyLib::MyLib)
# create the IMPORTED target
add_library(MyLib UNKNOWN IMPORTED)
set_target_properties(MyLib PROPERTIES
IMPORTED_LOCATION "${MyLib_LIBRARY}")
add_library(MyLib::MyLib ALIAS MyLib)
endif()
This is the FindModule file which will be used by CMake for find_package().
It must be in directory with another modules, and this directory must be inside CMAKE_MODULE_PATH
for succesful find.
See the cmake-developer(7) for CMake module example (the previous code was based on that example), also consider the “Using dependencies Guide”, section “Imported Targets” and set_target_properties().
Hope that helps.
Please write if it has helped you or if there were some errors.