aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Traversaro <silvio@traversaro.it>2023-12-23 11:28:18 +0100
committerGitHub <noreply@github.com>2023-12-23 11:28:18 +0100
commit68dbd5e5f589f6f648e917851e901c538c8d314c (patch)
treea807fe43d019252836dedcc2026cf46f70458724
parent048bff80f2bd00bb651bcc3357cb6f76e3d76fd5 (diff)
downloaddlfcn-win32-fix49.tar.gz
dlfcn-win32-fix49.tar.bz2
dlfcn-win32-fix49.zip
Add support to consume library via CMake's FetchContentfix49
-rw-r--r--README.md29
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--tests/CMakeLists.txt6
3 files changed, 32 insertions, 5 deletions
diff --git a/README.md b/README.md
index 35bf550..b0eb182 100644
--- a/README.md
+++ b/README.md
@@ -20,8 +20,11 @@ It follows the standard as described here:
20Using This Library 20Using This Library
21------------------ 21------------------
22 22
23### Using CMake 23### Using CMake
24Once the library has been installed, add to your project `CMakeLists.txt` : 24
25#### Use installed library
26
27Once the library has been installed (for example by compiling from source or installing it via a package manager), add to your project `CMakeLists.txt` :
25~~~cmake 28~~~cmake
26... 29...
27find_package(dlfcn-win32 REQUIRED) 30find_package(dlfcn-win32 REQUIRED)
@@ -45,6 +48,28 @@ target_link_libraries(<target> ${CMAKE_DL_LIBS})
45 48
46When cross-compiling you might want to set [`CMAKE_CROSSCOMPILING_EMULATOR`](https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING_EMULATOR.html) to the path of wine to run tests. 49When cross-compiling you might want to set [`CMAKE_CROSSCOMPILING_EMULATOR`](https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING_EMULATOR.html) to the path of wine to run tests.
47 50
51#### Download and build library as part of CMake build
52
53If you do not have installed and you do not want to install the library, you can also download and build it using [CMake's FetchContent module](https://cmake.org/cmake/help/latest/module/FetchContent.html). Just add in your CMake project:
54~~~cmake
55...
56if (WIN32)
57 include(FetchContent)
58 FetchContent_Declare(
59 dlfcn-win32
60 GIT_REPOSITORY "https://github.com/dlfcn-win32/dlfcn-win32.git"
61 GIT_TAG "v1.5.0"
62 SYSTEM
63 )
64 FetchContent_MakeAvailable(dlfcn-win32)
65 set(CMAKE_DL_LIBS dlfcn-win32::dl)
66endif ()
67...
68target_link_libraries(<target> ${CMAKE_DL_LIBS})
69...
70~~~
71
72
48Authors 73Authors
49------- 74-------
50 75
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9066e65..cdaf2a5 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -3,6 +3,8 @@ set(sources dlfcn.c)
3 3
4 4
5add_library(dl ${sources}) 5add_library(dl ${sources})
6# Support for FetchContent workflow
7add_library(dlfcn-win32::dl ALIAS dl)
6 8
7# Correctly export the location of installed includes in the target 9# Correctly export the location of installed includes in the target
8target_include_directories(dl 10target_include_directories(dl
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index cd321f2..e9b3e85 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -7,19 +7,19 @@ if(WIN32)
7 7
8 add_library(testdll2 SHARED testdll2.c) 8 add_library(testdll2 SHARED testdll2.c)
9 set_target_properties(testdll2 PROPERTIES PREFIX "") 9 set_target_properties(testdll2 PROPERTIES PREFIX "")
10 target_link_libraries(testdll2 dl) 10 target_link_libraries(testdll2 dlfcn-win32::dl)
11 11
12 add_library(testdll3 SHARED testdll3.c) 12 add_library(testdll3 SHARED testdll3.c)
13 set_target_properties(testdll3 PROPERTIES PREFIX "") 13 set_target_properties(testdll3 PROPERTIES PREFIX "")
14 14
15 add_executable(t_dlfcn test.c) 15 add_executable(t_dlfcn test.c)
16 target_link_libraries(t_dlfcn dl) 16 target_link_libraries(t_dlfcn dlfcn-win32::dl)
17 17
18 add_test(NAME t_dlfcn COMMAND t_dlfcn WORKING_DIRECTORY $<TARGET_FILE_DIR:t_dlfcn> ) 18 add_test(NAME t_dlfcn COMMAND t_dlfcn WORKING_DIRECTORY $<TARGET_FILE_DIR:t_dlfcn> )
19endif() 19endif()
20 20
21add_executable(test-dladdr test-dladdr.c) 21add_executable(test-dladdr test-dladdr.c)
22target_link_libraries(test-dladdr dl) 22target_link_libraries(test-dladdr dlfcn-win32::dl)
23if(UNIX) 23if(UNIX)
24 set_target_properties(test-dladdr PROPERTIES COMPILE_FLAGS "-Wl,--export-dynamic -fpie") 24 set_target_properties(test-dladdr PROPERTIES COMPILE_FLAGS "-Wl,--export-dynamic -fpie")
25endif() 25endif()