diff options
| -rw-r--r-- | README.md | 29 | ||||
| -rw-r--r-- | src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | tests/CMakeLists.txt | 6 |
3 files changed, 32 insertions, 5 deletions
| @@ -20,8 +20,11 @@ It follows the standard as described here: | |||
| 20 | Using This Library | 20 | Using This Library |
| 21 | ------------------ | 21 | ------------------ |
| 22 | 22 | ||
| 23 | ### Using CMake | 23 | ### Using CMake |
| 24 | Once the library has been installed, add to your project `CMakeLists.txt` : | 24 | |
| 25 | #### Use installed library | ||
| 26 | |||
| 27 | Once 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 | ... |
| 27 | find_package(dlfcn-win32 REQUIRED) | 30 | find_package(dlfcn-win32 REQUIRED) |
| @@ -45,6 +48,28 @@ target_link_libraries(<target> ${CMAKE_DL_LIBS}) | |||
| 45 | 48 | ||
| 46 | When 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. | 49 | When 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 | |||
| 53 | If 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 | ... | ||
| 56 | if (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) | ||
| 66 | endif () | ||
| 67 | ... | ||
| 68 | target_link_libraries(<target> ${CMAKE_DL_LIBS}) | ||
| 69 | ... | ||
| 70 | ~~~ | ||
| 71 | |||
| 72 | |||
| 48 | Authors | 73 | Authors |
| 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 | ||
| 5 | add_library(dl ${sources}) | 5 | add_library(dl ${sources}) |
| 6 | # Support for FetchContent workflow | ||
| 7 | add_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 |
| 8 | target_include_directories(dl | 10 | target_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> ) |
| 19 | endif() | 19 | endif() |
| 20 | 20 | ||
| 21 | add_executable(test-dladdr test-dladdr.c) | 21 | add_executable(test-dladdr test-dladdr.c) |
| 22 | target_link_libraries(test-dladdr dl) | 22 | target_link_libraries(test-dladdr dlfcn-win32::dl) |
| 23 | if(UNIX) | 23 | if(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") |
| 25 | endif() | 25 | endif() |
