Skip to content

Commit

Permalink
Use CMAKE_INSTALL_* variables when installing in CMake.
Browse files Browse the repository at this point in the history
Closes #1049. Thanks to Greg Troxel.
  • Loading branch information
ralight committed Apr 26, 2019
1 parent efa649f commit 4395754
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 45 deletions.
33 changes: 5 additions & 28 deletions CMakeLists.txt
Expand Up @@ -16,35 +16,12 @@ set (VERSION 1.6.0)
add_definitions (-DCMAKE -DVERSION=\"${VERSION}\")

if (WIN32)
set (BINDIR .)
set (SBINDIR .)
set (SYSCONFDIR .)
set (LIBDIR .)
set (INCLUDEDIR include)
set (DATAROOTDIR share)
set (MANDIR man)
set (SHAREDEST .)
set (PKGCONFIGDIR "${LIBDIR}/pkgconfig")
add_definitions("-D_CRT_SECURE_NO_WARNINGS")
add_definitions("-D_CRT_NONSTDC_NO_DEPRECATE")
else (WIN32)
set (BINDIR bin)
set (SBINDIR sbin)
if ("${CMAKE_INSTALL_PREFIX}" STREQUAL /usr)
set (SYSCONFDIR /etc/mosquitto)
else ("${CMAKE_INSTALL_PREFIX}" STREQUAL /usr)
set (SYSCONFDIR etc/mosquitto)
endif ("${CMAKE_INSTALL_PREFIX}" STREQUAL /usr)

set (LIBDIR lib${LIB_SUFFIX})
set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBDIR}")
set (INCLUDEDIR include)
set (DATAROOTDIR share)
set (MANDIR "${DATAROOTDIR}/man")
set (SHAREDIR "${DATAROOTDIR}/mosquitto")
set (PKGCONFIGDIR "${LIBDIR}/pkgconfig")
endif (WIN32)

include(GNUInstallDirs)

option(WITH_TLS
"Include SSL/TLS support?" ON)
option(WITH_TLS_PSK
Expand Down Expand Up @@ -123,17 +100,17 @@ endif (DOCUMENTATION)
# Install config file
# ========================================

install(FILES mosquitto.conf aclfile.example pskfile.example pwfile.example DESTINATION "${SYSCONFDIR}")
install(FILES mosquitto.conf aclfile.example pskfile.example pwfile.example DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/mosquitto")


# ========================================
# Install pkg-config files
# ========================================

configure_file(libmosquitto.pc.in libmosquitto.pc @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmosquitto.pc" DESTINATION "${PKGCONFIGDIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmosquitto.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/pkgconfig")
configure_file(libmosquittopp.pc.in libmosquittopp.pc @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmosquittopp.pc" DESTINATION "${PKGCONFIGDIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmosquittopp.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/pkgconfig")

# ========================================
# Testing
Expand Down
1 change: 1 addition & 0 deletions ChangeLog.txt
Expand Up @@ -13,6 +13,7 @@ Build:
- Split CFLAGS and CPPFLAGS, and LDFLAGS and LDADD/LIBADD.
- test/unit now respects CPPFLAGS and LDFLAGS. Closes #1232.
- Don't call ldconfig in CMake scripts. Closes #1048.
- Use CMAKE_INSTALL_* variables when installing in CMake. Closes #1049.


1.6 - 20190417
Expand Down
6 changes: 3 additions & 3 deletions client/CMakeLists.txt
Expand Up @@ -24,6 +24,6 @@ if (QNX)
target_link_libraries(mosquitto_rr socket)
endif()

install(TARGETS mosquitto_pub RUNTIME DESTINATION "${BINDIR}" LIBRARY DESTINATION "${LIBDIR}")
install(TARGETS mosquitto_sub RUNTIME DESTINATION "${BINDIR}" LIBRARY DESTINATION "${LIBDIR}")
install(TARGETS mosquitto_rr RUNTIME DESTINATION "${BINDIR}" LIBRARY DESTINATION "${LIBDIR}")
install(TARGETS mosquitto_pub RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(TARGETS mosquitto_sub RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(TARGETS mosquitto_rr RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
6 changes: 3 additions & 3 deletions lib/CMakeLists.txt
Expand Up @@ -89,7 +89,7 @@ set_target_properties(libmosquitto PROPERTIES
SOVERSION 1
)

install(TARGETS libmosquitto RUNTIME DESTINATION "${BINDIR}" LIBRARY DESTINATION "${LIBDIR}")
install(TARGETS libmosquitto LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")

if (WITH_STATIC_LIBRARIES)
add_library(libmosquitto_static STATIC ${C_SRC})
Expand All @@ -107,7 +107,7 @@ if (WITH_STATIC_LIBRARIES)
)

target_compile_definitions(libmosquitto_static PUBLIC "LIBMOSQUITTO_STATIC")
install(TARGETS libmosquitto_static RUNTIME DESTINATION "${BINDIR}" ARCHIVE DESTINATION "${LIBDIR}")
install(TARGETS libmosquitto_static ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endif (WITH_STATIC_LIBRARIES)

install(FILES mosquitto.h DESTINATION "${INCLUDEDIR}")
install(FILES mosquitto.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
6 changes: 3 additions & 3 deletions lib/cpp/CMakeLists.txt
Expand Up @@ -13,7 +13,7 @@ set_target_properties(mosquittopp PROPERTIES
VERSION ${VERSION}
SOVERSION 1
)
install(TARGETS mosquittopp RUNTIME DESTINATION "${BINDIR}" LIBRARY DESTINATION "${LIBDIR}")
install(TARGETS mosquittopp LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")

if (WITH_STATIC_LIBRARIES)
add_library(mosquittopp_static STATIC
Expand All @@ -34,7 +34,7 @@ if (WITH_STATIC_LIBRARIES)
)

target_compile_definitions(mosquittopp_static PUBLIC "LIBMOSQUITTO_STATIC")
install(TARGETS mosquittopp_static RUNTIME DESTINATION "${BINDIR}" ARCHIVE DESTINATION "${LIBDIR}")
install(TARGETS mosquittopp_static ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endif (WITH_STATIC_LIBRARIES)

install(FILES mosquittopp.h DESTINATION "${INCLUDEDIR}")
install(FILES mosquittopp.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
10 changes: 5 additions & 5 deletions man/CMakeLists.txt
@@ -1,5 +1,5 @@
install(FILES mosquitto_passwd.1 mosquitto_pub.1 mosquitto_sub.1 mosquitto_rr.1 DESTINATION ${MANDIR}/man1)
install(FILES libmosquitto.3 DESTINATION ${MANDIR}/man3)
install(FILES mosquitto.conf.5 DESTINATION ${MANDIR}/man5)
install(FILES mosquitto-tls.7 mqtt.7 DESTINATION ${MANDIR}/man7)
install(FILES mosquitto.8 DESTINATION ${MANDIR}/man8)
install(FILES mosquitto_passwd.1 mosquitto_pub.1 mosquitto_sub.1 mosquitto_rr.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
install(FILES libmosquitto.3 DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
install(FILES mosquitto.conf.5 DESTINATION ${CMAKE_INSTALL_MANDIR}/man5)
install(FILES mosquitto-tls.7 mqtt.7 DESTINATION ${CMAKE_INSTALL_MANDIR}/man7)
install(FILES mosquitto.8 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8)
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Expand Up @@ -184,11 +184,11 @@ if (UNIX)
endif (APPLE)
endif (UNIX)

install(TARGETS mosquitto RUNTIME DESTINATION "${SBINDIR}" LIBRARY DESTINATION "${LIBDIR}")
install(FILES mosquitto_broker.h mosquitto_plugin.h DESTINATION "${INCLUDEDIR}")
install(TARGETS mosquitto RUNTIME DESTINATION "${CMAKE_INSTALL_SBINDIR}")
install(FILES mosquitto_broker.h mosquitto_plugin.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

if (WITH_TLS)
add_executable(mosquitto_passwd mosquitto_passwd.c)
target_link_libraries(mosquitto_passwd ${OPENSSL_LIBRARIES})
install(TARGETS mosquitto_passwd RUNTIME DESTINATION "${BINDIR}" LIBRARY DESTINATION "${LIBDIR}")
install(TARGETS mosquitto_passwd RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif (WITH_TLS)

0 comments on commit 4395754

Please sign in to comment.