Skip to content

Commit

Permalink
generating a pkg-config file if pkg-config exists and install it
Browse files Browse the repository at this point in the history
  • Loading branch information
fr0stbyte authored and Radu Brumariu committed Nov 23, 2016
1 parent 095b2c4 commit e83d8c4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ config.bak
*.o
src/.libs
src/.deps
*.in
configure
depcomp
*.lo
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ array_destroy(ar);

- C compiler (gcc, clang, etc...)
- cmake (>= 3.5)
- pkg-config

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

Expand Down Expand Up @@ -173,12 +174,12 @@ Linking dynamically produces a smaller executable, but requires `libcollectc.so`
### Linking problems
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.
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.
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:
```
gcc hello.c -I/path/to/library/include/ -L/path/to/library/lib/ -lcollectc -o hello
gcc hello.c `pkg-config --cflags --libs collectionc` -o hello
```
### Running the program
Expand Down
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ target_link_libraries(${PROJECT_NAME})
set(${PROJECT_NAME}_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include
CACHE INTERNAL "${PROJECT_NAME}: Include directories" FORCE)

include(FindPkgConfig QUIET)
if(PKG_CONFIG_FOUND)
configure_file("collectionc.pc.in" "collectionc.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/collectionc.pc"
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
endif()

install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_static
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
Expand Down
10 changes: 10 additions & 0 deletions src/collectionc.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: @CMAKE_PROJECT_NAME@
Description: C data structures collection
Version: @CMAKE_VERSION@
Libs: -L${libdir} -lcollectc
Cflags: -I${includedir}

0 comments on commit e83d8c4

Please sign in to comment.