Skip to content

Commit e83d8c4

Browse files
fr0stbyteRadu Brumariu
authored and
Radu Brumariu
committed
generating a pkg-config file if pkg-config exists and install it
1 parent 095b2c4 commit e83d8c4

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ config.bak
1313
*.o
1414
src/.libs
1515
src/.deps
16-
*.in
1716
configure
1817
depcomp
1918
*.lo

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ array_destroy(ar);
7070

7171
- C compiler (gcc, clang, etc...)
7272
- cmake (>= 3.5)
73+
- pkg-config
7374

7475
These packages can usually be installed through your distributions package manager.
7576

@@ -173,12 +174,12 @@ Linking dynamically produces a smaller executable, but requires `libcollectc.so`
173174
174175
### Linking problems
175176
176-
Sometimes the compiler may have trouble finding the library or the headers. This is usually because the it's looking for them in the wrong directory, which may happen if the library or the headers or both are installed in a non-standard directory or not installed at all.
177+
Sometimes the compiler may have trouble finding the library or the headers. This is usually because the it's looking for them in the wrong directory, which may happen if the library or the headers or both are installed in a non-standard directory or not installed at all.
177178
178179
If this is the case, we can explicitly tell the compiler where to look for them by passing the `-I[path to headers]` and `-L[path to libraries]` options:
179180
180181
```
181-
gcc hello.c -I/path/to/library/include/ -L/path/to/library/lib/ -lcollectc -o hello
182+
gcc hello.c `pkg-config --cflags --libs collectionc` -o hello
182183
```
183184
184185
### Running the program

src/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ target_link_libraries(${PROJECT_NAME})
1717
set(${PROJECT_NAME}_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include
1818
CACHE INTERNAL "${PROJECT_NAME}: Include directories" FORCE)
1919

20+
include(FindPkgConfig QUIET)
21+
if(PKG_CONFIG_FOUND)
22+
configure_file("collectionc.pc.in" "collectionc.pc" @ONLY)
23+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/collectionc.pc"
24+
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
25+
endif()
26+
2027
install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_static
2128
ARCHIVE DESTINATION lib
2229
LIBRARY DESTINATION lib

src/collectionc.pc.in

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
prefix=@CMAKE_INSTALL_PREFIX@
2+
exec_prefix=${prefix}
3+
libdir=${exec_prefix}/lib
4+
includedir=${prefix}/include
5+
6+
Name: @CMAKE_PROJECT_NAME@
7+
Description: C data structures collection
8+
Version: @CMAKE_VERSION@
9+
Libs: -L${libdir} -lcollectc
10+
Cflags: -I${includedir}

0 commit comments

Comments
 (0)