From e6e93a08c7fe2731f0c23038a801dd0736ec0a94 Mon Sep 17 00:00:00 2001 From: Andrew Karpow Date: Tue, 11 Nov 2014 21:13:11 +0100 Subject: [PATCH] release build now installs assets to prefix if build with dynamic assets --- CMakeLists.txt | 59 +++++++++++++++++++++---------------- src/config.h.in | 4 +-- src/ympd.c | 4 +-- {htdocs => tools}/mkdata.c | 0 {htdocs => tools}/mkdata.pl | 0 5 files changed, 38 insertions(+), 29 deletions(-) rename {htdocs => tools}/mkdata.c (100%) rename {htdocs => tools}/mkdata.pl (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fb845b..d32f0d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,14 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/") set(CPACK_PACKAGE_VERSION_MAJOR "1") set(CPACK_PACKAGE_VERSION_MINOR "2") set(CPACK_PACKAGE_VERSION_PATCH "3") +if(CMAKE_BUILD_TYPE MATCHES RELEASE) + set(ASSETS_PATH "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/htdocs") +else() + set(ASSETS_PATH "${PROJECT_SOURCE_DIR}/htdocs") +endif() option(WITH_MPD_HOST_CHANGE "Let users of the web frontend change the MPD Host" ON) -option(WITH_DYNAMIC_SERVING "Serve file of ./htdocs dynamically (development)" OFF) +option(WITH_DYNAMIC_ASSETS "Serve assets dynamically (e.g for development/packaging)" OFF) option(WITH_IPV6 "enable IPv6 support" ON) find_package(LibMPDClient REQUIRED) @@ -18,46 +23,50 @@ include_directories(${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}) include(CheckCSourceCompiles) -set(CMAKE_C_FLAGS "-std=gnu99 -Wall") +set(CMAKE_C_FLAGS "-std=gnu99 -Wall") set(CMAKE_C_FLAGS_DEBUG "-ggdb -pedantic") if(WITH_IPV6) - set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS NS_ENABLE_IPV6) + set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS NS_ENABLE_IPV6) endif() file(GLOB RESOURCES - RELATIVE ${PROJECT_SOURCE_DIR} - htdocs/js/* - htdocs/assets/* - htdocs/css/*.min.css - htdocs/fonts/* - htdocs/index.html -) - -if(CMAKE_CROSSCOMPILING) - set(MKDATA_EXE ${PROJECT_SOURCE_DIR}/htdocs/mkdata.pl) -else() - set(MKDATA_EXE $) - set(MKDATA_TARGET mkdata) - add_executable(mkdata htdocs/mkdata.c) -endif() - -add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/assets.c - COMMAND ${MKDATA_EXE} ${RESOURCES} > ${PROJECT_BINARY_DIR}/assets.c - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - DEPENDS ${RESOURCES} ${MKDATA_TARGET} + RELATIVE ${PROJECT_SOURCE_DIR} + htdocs/js/* + htdocs/assets/* + htdocs/css/*.min.css + htdocs/fonts/* + htdocs/index.html ) set(SOURCES src/ympd.c - src/http_server.c src/mpd_client.c src/mongoose.c src/json_encode.c - assets.c ) +if(NOT WITH_DYNAMIC_ASSETS) + if(CMAKE_CROSSCOMPILING) + set(MKDATA_EXE ${PROJECT_SOURCE_DIR}/tools/mkdata.pl) + else() + set(MKDATA_EXE $) + set(MKDATA_TARGET mkdata) + add_executable(mkdata tools/mkdata.c) + endif() + + add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/assets.c + COMMAND ${MKDATA_EXE} ${RESOURCES} > ${PROJECT_BINARY_DIR}/assets.c + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + DEPENDS ${RESOURCES} ${MKDATA_TARGET} + ) + list(APPEND SOURCES src/http_server.c assets.c) +endif() + add_executable(ympd ${SOURCES}) target_link_libraries(ympd ${LIBMPDCLIENT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) install(TARGETS ympd DESTINATION bin) install(FILES ympd.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1) +if(WITH_DYNAMIC_ASSETS) + install(DIRECTORY htdocs DESTINATION share/${PROJECT_NAME}) +endif() diff --git a/src/config.h.in b/src/config.h.in index 202d63a..08a5529 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -22,8 +22,8 @@ #define YMPD_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR} #define YMPD_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR} #define YMPD_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH} -#define SRC_PATH "${PROJECT_SOURCE_DIR}/htdocs" +#define SRC_PATH "${ASSETS_PATH}" #cmakedefine WITH_MPD_HOST_CHANGE -#cmakedefine WITH_DYNAMIC_SERVING +#cmakedefine WITH_DYNAMIC_ASSETS #endif diff --git a/src/ympd.c b/src/ympd.c index 794301b..e974479 100644 --- a/src/ympd.c +++ b/src/ympd.c @@ -51,7 +51,7 @@ static int server_callback(struct mg_connection *c, enum mg_event ev) { else return MG_TRUE; } else -#ifdef WITH_DYNAMIC_SERVING +#ifdef WITH_DYNAMIC_ASSETS return MG_FALSE; #else return callback_http(c); @@ -73,7 +73,7 @@ int main(int argc, char **argv) atexit(bye); error_msg = mg_set_option(server, "listening_port", "8080"); -#ifdef WITH_DYNAMIC_SERVING +#ifdef WITH_DYNAMIC_ASSETS mg_set_option(server, "document_root", SRC_PATH); #endif diff --git a/htdocs/mkdata.c b/tools/mkdata.c similarity index 100% rename from htdocs/mkdata.c rename to tools/mkdata.c diff --git a/htdocs/mkdata.pl b/tools/mkdata.pl similarity index 100% rename from htdocs/mkdata.pl rename to tools/mkdata.pl -- 2.20.1