diff options
-rw-r--r-- | CMakeLists.txt | 65 | ||||
-rw-r--r-- | Makefile | 20 | ||||
-rw-r--r-- | cmake-test/CMakeLists.txt | 9 | ||||
-rw-r--r-- | src/CMakeLists.txt | 43 | ||||
-rw-r--r-- | src/dlfcn.c (renamed from dlfcn.c) | 0 | ||||
-rw-r--r-- | src/dlfcn.h (renamed from dlfcn.h) | 0 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 12 | ||||
-rw-r--r-- | tests/test.c (renamed from test.c) | 0 | ||||
-rw-r--r-- | tests/testdll.c (renamed from testdll.c) | 0 | ||||
-rw-r--r-- | tests/testdll2.c (renamed from testdll2.c) | 0 | ||||
-rw-r--r-- | tests/testdll3.c (renamed from testdll3.c) | 0 |
11 files changed, 74 insertions, 75 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e44343d..17d3fc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -1,4 +1,4 @@ | |||
1 | cmake_minimum_required(VERSION 2.8) | 1 | cmake_minimum_required(VERSION 2.8.11) |
2 | 2 | ||
3 | if (NOT DEFINED CMAKE_BUILD_TYPE) | 3 | if (NOT DEFINED CMAKE_BUILD_TYPE) |
4 | set (CMAKE_BUILD_TYPE Release CACHE STRING "Build type") | 4 | set (CMAKE_BUILD_TYPE Release CACHE STRING "Build type") |
@@ -9,65 +9,8 @@ project (dlfcn-win32 C) | |||
9 | option(BUILD_SHARED_LIBS "shared/static libs" ON) | 9 | option(BUILD_SHARED_LIBS "shared/static libs" ON) |
10 | option(BUILD_TESTS "tests?" OFF) | 10 | option(BUILD_TESTS "tests?" OFF) |
11 | 11 | ||
12 | set(headers dlfcn.h) | 12 | add_subdirectory(src) |
13 | set(sources dlfcn.c) | ||
14 | |||
15 | if (BUILD_SHARED_LIBS) | ||
16 | add_definitions(-DSHARED) | ||
17 | endif (BUILD_SHARED_LIBS) | ||
18 | |||
19 | add_library(dl ${sources}) | ||
20 | |||
21 | install (TARGETS dl EXPORT dlfcn-win32-targets | ||
22 | RUNTIME DESTINATION bin | ||
23 | LIBRARY DESTINATION lib${LIB_SUFFIX} | ||
24 | ARCHIVE DESTINATION lib${LIB_SUFFIX}) | ||
25 | |||
26 | install (FILES ${headers} DESTINATION include) | ||
27 | |||
28 | # If CMake version is greater than or equal to 2.8.11 | ||
29 | # also install the cmake configuration files to simplify | ||
30 | # the use of dlfcn-win32 in CMake | ||
31 | if(NOT ${CMAKE_VERSION} VERSION_LESS "2.8.11") | ||
32 | # Correctly export the location of installed includes in the target | ||
33 | target_include_directories(dl INTERFACE $<INSTALL_INTERFACE:include>) | ||
34 | |||
35 | # Export the targets (build tree) | ||
36 | export(EXPORT dlfcn-win32-targets | ||
37 | FILE "${CMAKE_CURRENT_BINARY_DIR}/dlfcn-win32-targets.cmake" | ||
38 | NAMESPACE dlfcn-win32:: | ||
39 | ) | ||
40 | |||
41 | # Write the CMake config file | ||
42 | set(CMAKE_CONF_INSTALL_DIR share/dlfcn-win32) | ||
43 | set(INCLUDE_INSTALL_DIR include) | ||
44 | include(CMakePackageConfigHelpers) | ||
45 | configure_package_config_file(dlfcn-win32-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/dlfcn-win32-config.cmake | ||
46 | INSTALL_DESTINATION ${CMAKE_CONF_INSTALL_DIR} | ||
47 | PATH_VARS INCLUDE_INSTALL_DIR | ||
48 | NO_CHECK_REQUIRED_COMPONENTS_MACRO) | ||
49 | |||
50 | # Install the targets (install) | ||
51 | install(EXPORT dlfcn-win32-targets | ||
52 | FILE dlfcn-win32-targets.cmake | ||
53 | NAMESPACE dlfcn-win32:: | ||
54 | DESTINATION ${CMAKE_CONF_INSTALL_DIR}) | ||
55 | |||
56 | # Install the CMake config file | ||
57 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dlfcn-win32-config.cmake | ||
58 | DESTINATION ${CMAKE_CONF_INSTALL_DIR}) | ||
59 | endif() | ||
60 | 13 | ||
61 | if (BUILD_TESTS) | 14 | if (BUILD_TESTS) |
62 | enable_testing() | 15 | add_subdirectory(tests) |
63 | add_library(testdll SHARED testdll.c) | 16 | endif() |
64 | set_target_properties(testdll PROPERTIES PREFIX "") | ||
65 | add_library(testdll2 SHARED testdll2.c) | ||
66 | set_target_properties(testdll2 PROPERTIES PREFIX "") | ||
67 | target_link_libraries(testdll2 dl) | ||
68 | add_library(testdll3 SHARED testdll3.c) | ||
69 | set_target_properties(testdll3 PROPERTIES PREFIX "") | ||
70 | add_executable(t_dlfcn test.c) | ||
71 | target_link_libraries(t_dlfcn dl) | ||
72 | add_test (NAME t_dlfcn COMMAND t_dlfcn) | ||
73 | endif () | ||
@@ -2,7 +2,7 @@ | |||
2 | # dlfcn-win32 Makefile | 2 | # dlfcn-win32 Makefile |
3 | # | 3 | # |
4 | include config.mak | 4 | include config.mak |
5 | CFLAGS = -Wall -O3 -fomit-frame-pointer | 5 | CFLAGS = -Wall -O3 -fomit-frame-pointer -Isrc |
6 | 6 | ||
7 | ifeq ($(BUILD_SHARED),yes) | 7 | ifeq ($(BUILD_SHARED),yes) |
8 | TARGETS += libdl.dll | 8 | TARGETS += libdl.dll |
@@ -21,13 +21,13 @@ ifeq ($(BUILD_MSVC),yes) | |||
21 | INSTALL += lib-install | 21 | INSTALL += lib-install |
22 | endif | 22 | endif |
23 | 23 | ||
24 | SOURCES := dlfcn.c | 24 | SOURCES := src/dlfcn.c |
25 | HEADERS := dlfcn.h | 25 | HEADERS := src/dlfcn.h |
26 | 26 | ||
27 | all: $(TARGETS) | 27 | all: $(TARGETS) |
28 | 28 | ||
29 | libdl.a: $(SOURCES) | 29 | libdl.a: $(SOURCES) |
30 | $(CC) $(CFLAGS) -c $^ | 30 | $(CC) $(CFLAGS) -o $(^:%.c=%.o) -c $^ |
31 | $(AR) cru $@ $(SOURCES:%.c=%.o) | 31 | $(AR) cru $@ $(SOURCES:%.c=%.o) |
32 | $(RANLIB) $@ | 32 | $(RANLIB) $@ |
33 | 33 | ||
@@ -58,19 +58,19 @@ lib-install: | |||
58 | 58 | ||
59 | install: $(INSTALL) | 59 | install: $(INSTALL) |
60 | 60 | ||
61 | test.exe: test.c $(TARGETS) | 61 | test.exe: tests/test.c $(TARGETS) |
62 | $(CC) $(CFLAGS) -o $@ $< libdl.dll.a | 62 | $(CC) $(CFLAGS) -o $@ $< libdl.dll.a |
63 | 63 | ||
64 | test-static.exe: test.c $(TARGETS) | 64 | test-static.exe: tests/test.c $(TARGETS) |
65 | $(CC) $(CFLAGS) -o $@ $< libdl.a | 65 | $(CC) $(CFLAGS) -o $@ $< libdl.a |
66 | 66 | ||
67 | testdll.dll: testdll.c | 67 | testdll.dll: tests/testdll.c |
68 | $(CC) $(CFLAGS) -shared -o $@ $^ | 68 | $(CC) $(CFLAGS) -shared -o $@ $^ |
69 | 69 | ||
70 | testdll2.dll: testdll2.c $(TARGETS) | 70 | testdll2.dll: tests/testdll2.c $(TARGETS) |
71 | $(CC) $(CFLAGS) -shared -o $@ $< -L. -ldl | 71 | $(CC) $(CFLAGS) -shared -o $@ $< -L. -ldl |
72 | 72 | ||
73 | testdll3.dll: testdll3.c | 73 | testdll3.dll: tests/testdll3.c |
74 | $(CC) -shared -o $@ $^ | 74 | $(CC) -shared -o $@ $^ |
75 | 75 | ||
76 | test: $(TARGETS) $(TESTS) testdll.dll testdll2.dll testdll3.dll | 76 | test: $(TARGETS) $(TESTS) testdll.dll testdll2.dll testdll3.dll |
@@ -78,7 +78,7 @@ test: $(TARGETS) $(TESTS) testdll.dll testdll2.dll testdll3.dll | |||
78 | 78 | ||
79 | clean:: | 79 | clean:: |
80 | rm -f \ | 80 | rm -f \ |
81 | dlfcn.o \ | 81 | src/dlfcn.o \ |
82 | libdl.dll libdl.a libdl.def libdl.dll.a libdl.lib libdl.exp \ | 82 | libdl.dll libdl.a libdl.def libdl.dll.a libdl.lib libdl.exp \ |
83 | tmptest.c tmptest.dll \ | 83 | tmptest.c tmptest.dll \ |
84 | test.exe test-static.exe testdll.dll testdll2.dll testdll3.dll | 84 | test.exe test-static.exe testdll.dll testdll2.dll testdll3.dll |
diff --git a/cmake-test/CMakeLists.txt b/cmake-test/CMakeLists.txt index 659a79a..b191317 100644 --- a/cmake-test/CMakeLists.txt +++ b/cmake-test/CMakeLists.txt | |||
@@ -1,19 +1,20 @@ | |||
1 | # Simple CMake project to test the use of dlfcn-win32 | 1 | # Simple CMake project to test the use of dlfcn-win32 |
2 | # imported target. The test compiled is the same compiled | 2 | # imported target. The test compiled is the same compiled |
3 | # as part of the main dlfcn-win32 project | 3 | # as part of the main dlfcn-win32 project |
4 | project(dlfcn-win32-test) | ||
4 | 5 | ||
5 | cmake_minimum_required(VERSION 3.0) | 6 | cmake_minimum_required(VERSION 3.0) |
6 | 7 | ||
7 | find_package(dlfcn-win32 REQUIRED) | 8 | find_package(dlfcn-win32 REQUIRED) |
8 | 9 | ||
9 | add_library(testdll SHARED ../testdll.c) | 10 | add_library(testdll SHARED ../tests/testdll.c) |
10 | set_target_properties(testdll PROPERTIES PREFIX "") | 11 | set_target_properties(testdll PROPERTIES PREFIX "") |
11 | add_library(testdll2 SHARED ../testdll2.c) | 12 | add_library(testdll2 SHARED ../tests/testdll2.c) |
12 | set_target_properties(testdll2 PROPERTIES PREFIX "") | 13 | set_target_properties(testdll2 PROPERTIES PREFIX "") |
13 | target_link_libraries(testdll2 dlfcn-win32::dl) | 14 | target_link_libraries(testdll2 dlfcn-win32::dl) |
14 | add_library(testdll3 SHARED ../testdll3.c) | 15 | add_library(testdll3 SHARED ../tests/testdll3.c) |
15 | set_target_properties(testdll3 PROPERTIES PREFIX "") | 16 | set_target_properties(testdll3 PROPERTIES PREFIX "") |
16 | add_executable(t_dlfcn ../test.c) | 17 | add_executable(t_dlfcn ../tests/test.c) |
17 | target_link_libraries(t_dlfcn dlfcn-win32::dl) | 18 | target_link_libraries(t_dlfcn dlfcn-win32::dl) |
18 | enable_testing() | 19 | enable_testing() |
19 | add_test(NAME t_dlfcn COMMAND t_dlfcn) | 20 | add_test(NAME t_dlfcn COMMAND t_dlfcn) |
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..d5296b1 --- /dev/null +++ b/src/CMakeLists.txt | |||
@@ -0,0 +1,43 @@ | |||
1 | set(headers dlfcn.h) | ||
2 | set(sources dlfcn.c) | ||
3 | |||
4 | if (BUILD_SHARED_LIBS) | ||
5 | add_definitions(-DSHARED) | ||
6 | endif (BUILD_SHARED_LIBS) | ||
7 | |||
8 | add_library(dl ${sources}) | ||
9 | |||
10 | # Correctly export the location of installed includes in the target | ||
11 | target_include_directories(dl INTERFACE $<INSTALL_INTERFACE:include>) | ||
12 | |||
13 | install (TARGETS dl EXPORT dlfcn-win32-targets | ||
14 | RUNTIME DESTINATION bin | ||
15 | LIBRARY DESTINATION lib${LIB_SUFFIX} | ||
16 | ARCHIVE DESTINATION lib${LIB_SUFFIX}) | ||
17 | |||
18 | install (FILES ${headers} DESTINATION include) | ||
19 | |||
20 | # Export the targets (build tree) | ||
21 | export(EXPORT dlfcn-win32-targets | ||
22 | FILE "${CMAKE_BINARY_DIR}/dlfcn-win32-targets.cmake" | ||
23 | NAMESPACE dlfcn-win32:: | ||
24 | ) | ||
25 | |||
26 | # Write the CMake config file | ||
27 | set(CMAKE_CONF_INSTALL_DIR share/dlfcn-win32) | ||
28 | set(INCLUDE_INSTALL_DIR include) | ||
29 | include(CMakePackageConfigHelpers) | ||
30 | configure_package_config_file(../dlfcn-win32-config.cmake.in ${CMAKE_BINARY_DIR}/dlfcn-win32-config.cmake | ||
31 | INSTALL_DESTINATION ${CMAKE_CONF_INSTALL_DIR} | ||
32 | PATH_VARS INCLUDE_INSTALL_DIR | ||
33 | NO_CHECK_REQUIRED_COMPONENTS_MACRO) | ||
34 | |||
35 | # Install the targets (install) | ||
36 | install(EXPORT dlfcn-win32-targets | ||
37 | FILE dlfcn-win32-targets.cmake | ||
38 | NAMESPACE dlfcn-win32:: | ||
39 | DESTINATION ${CMAKE_CONF_INSTALL_DIR}) | ||
40 | |||
41 | # Install the CMake config file | ||
42 | install(FILES ${CMAKE_BINARY_DIR}/dlfcn-win32-config.cmake | ||
43 | DESTINATION ${CMAKE_CONF_INSTALL_DIR}) | ||
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..64f85f7 --- /dev/null +++ b/tests/CMakeLists.txt | |||
@@ -0,0 +1,12 @@ | |||
1 | enable_testing() | ||
2 | include_directories(../src) | ||
3 | add_library(testdll SHARED testdll.c) | ||
4 | set_target_properties(testdll PROPERTIES PREFIX "") | ||
5 | add_library(testdll2 SHARED testdll2.c) | ||
6 | set_target_properties(testdll2 PROPERTIES PREFIX "") | ||
7 | target_link_libraries(testdll2 dl) | ||
8 | add_library(testdll3 SHARED testdll3.c) | ||
9 | set_target_properties(testdll3 PROPERTIES PREFIX "") | ||
10 | add_executable(t_dlfcn test.c) | ||
11 | target_link_libraries(t_dlfcn dl) | ||
12 | add_test (NAME t_dlfcn COMMAND t_dlfcn) | ||
diff --git a/testdll.c b/tests/testdll.c index 5bb0f43..5bb0f43 100644 --- a/testdll.c +++ b/tests/testdll.c | |||
diff --git a/testdll2.c b/tests/testdll2.c index 1560738..1560738 100644 --- a/testdll2.c +++ b/tests/testdll2.c | |||
diff --git a/testdll3.c b/tests/testdll3.c index b6f4f5b..b6f4f5b 100644 --- a/testdll3.c +++ b/tests/testdll3.c | |||