Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more info in pc template & cmake compatibility #132

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ coverage/
.project
.settings
.idea/
.vscode
cmake-build-debug/

# CMake out-of-source build directories
Expand Down
17 changes: 14 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ target_link_libraries(prime_proxyd prime_server ${CMAKE_THREAD_LIBS_INIT})
add_executable(prime_workerd ${CMAKE_SOURCE_DIR}/src/prime_workerd.cpp)
target_link_libraries(prime_workerd prime_server ${CMAKE_THREAD_LIBS_INIT})

# TODO(nils): AFAIU the project version shouldn't be the SO version
set_target_properties(prime_server PROPERTIES
PUBLIC_HEADER "${PRIME_LIBRARY_HEADERS}"
SOVERSION ${PROJECT_VERSION_MAJOR}
Expand All @@ -128,12 +129,22 @@ install(TARGETS prime_echod
prime_proxyd
prime_workerd DESTINATION ${CMAKE_INSTALL_BINDIR})

CONFIGURE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/libprime_server.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libprime_server.pc"
# pkg-config stuff, also make it compatible with autotools
set(prefix ${CMAKE_INSTALL_PREFIX})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the paths weren't set up in a cmake installation

set(exec_prefix ${prefix})
set(libdir ${prefix}/${CMAKE_INSTALL_LIBDIR})
set(includedir ${prefix}/${CMAKE_INSTALL_INCLUDEDIR})

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/libprime_server.pc.in
${CMAKE_CURRENT_BINARY_DIR}/libprime_server.pc
@ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libprime_server.pc" DESTINATION ${pkgconfigdir})

# uninstall target
configure_file(cmake/uninstall.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/prime_server_uninstall.cmake @ONLY)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/prime_server_uninstall.cmake)
Comment on lines +145 to +146
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as in the valhalla PR valhalla/valhalla#4516


# Add tests - Requires CTest
enable_testing()

Expand Down
65 changes: 65 additions & 0 deletions cmake/uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# from https://github.com/OSGeo/PROJ/blob/5920e2998318189970c0fe1e2db60f643515b9ea/cmake/uninstall.cmake.in

# install_manifest.txt is created in the top build tree, not the project one
if (NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_BINARY_DIR@/install_manifest.txt\"")
endif()

set(uninstall_file_list "@CMAKE_BINARY_DIR@/install_manifest.txt")
if(EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest_extra.txt")
list(APPEND uninstall_file_list "@CMAKE_CURRENT_BINARY_DIR@/install_manifest_extra.txt")
endif()

set(dir_list)
foreach (manifest_file IN ITEMS ${uninstall_file_list})
file(READ "${manifest_file}" files)
string(REGEX REPLACE "\n$" "" files "${files}")
string(REGEX REPLACE "\n" ";" files "${files}")
list(REVERSE files)
foreach (file ${files})
message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
if (IS_DIRECTORY "$ENV{DESTDIR}${file}")
list(APPEND dir_list "${file}")
elseif (EXISTS "$ENV{DESTDIR}${file}")
get_filename_component(dir "${file}" DIRECTORY)
list(APPEND dir_list "${dir}")
execute_process(
COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}"
OUTPUT_VARIABLE rm_out
RESULT_VARIABLE rm_retval
)
if(NOT ${rm_retval} EQUAL 0)
message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
endif (NOT ${rm_retval} EQUAL 0)
else ()
message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
endif ()
endforeach(file)
endforeach()

while(NOT "${dir_list}" STREQUAL "")
list(REMOVE_DUPLICATES dir_list)
set(new_dir_list)
foreach (file IN ITEMS ${dir_list})
if (IS_DIRECTORY "$ENV{DESTDIR}${file}" AND "${file}" MATCHES "@CMAKE_INSTALL_PREFIX@[/\\].+")
file(GLOB file_list "$ENV{DESTDIR}${file}/*")
list(LENGTH file_list file_list_len)
# Only remove empty directories
if(file_list_len EQUAL 0)
message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
execute_process(
COMMAND @CMAKE_COMMAND@ -E remove_directory "$ENV{DESTDIR}${file}"
OUTPUT_VARIABLE rm_out
RESULT_VARIABLE rm_retval
)
if(${rm_retval} EQUAL 0)
get_filename_component(upper_dir "${file}" DIRECTORY)
list(APPEND new_dir_list "${upper_dir}")
else()
message(STATUS "Problem when removing directory \"$ENV{DESTDIR}${file}\"")
endif()
endif()
endif()
endforeach()
set(dir_list "${new_dir_list}")
endwhile()
2 changes: 2 additions & 0 deletions libprime_server.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ Name: libprime_server
Description: prime_server c++ library
Version: @VERSION@
Libs: -L${libdir} -lprime_server
Requires: libzmq
Requires.private: libczmq
kevinkreiser marked this conversation as resolved.
Show resolved Hide resolved
nilsnolde marked this conversation as resolved.
Show resolved Hide resolved
Cflags: -I${includedir}
Loading