diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d7bcdaf..a5d62289 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ endif() string(REGEX REPLACE "^v" "" RAILCONTROL_VERSION "${RAILCONTROL_VERSION}") project(railcontrol VERSION ${RAILCONTROL_VERSION}) +include(GNUInstallDirs) STRING(TIMESTAMP COMPILE_TIMESTAMP "%s" UTC) @@ -393,14 +394,28 @@ add_custom_target(rebuild_version ALL COMMAND ${CMAKE_COMMAND} -E touch "${STAMP set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/Version.cpp" PROPERTIES OBJECT_DEPENDS "${STAMP_FILE}") add_dependencies(${PROJECT_NAME} rebuild_version) +# Option to install right into the source tree for development purposes +# Usage: +# $ cmake -B -DINSTALL_IN_PLACE=1 +# $ cmake --build ... +# $ cmake --install +# +# Default: Install to directories as defined by the GNUInstallDir module +option(INSTALL_IN_PLACE "Install into the source tree (For testing and development)" OFF) + +if(INSTALL_IN_PLACE) + set(CMAKE_INSTALL_PREFIX .) + set(CMAKE_INSTALL_BINDIR .) + set(CMAKE_INSTALL_SYSCONFDIR .) + set(CMAKE_INSTALL_DOCDIR doc) + target_compile_definitions(railcontrol PRIVATE HTML_DATA_PATH=\"./html\") +else() + target_compile_definitions(railcontrol PRIVATE HTML_DATA_PATH=\"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/railcontrol/html\") + install(DIRECTORY html DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/railcontrol) +endif() -set(CMAKE_INSTALL_BINDIR ".") -set(CMAKE_INSTALL_DOCDIR "doc") -set(DATADIR ".") - -install(TARGETS ${PROJECT_NAME}) -install(FILES railcontrol.conf.dist DESTINATION ${DATADIR}) -install(DIRECTORY html DESTINATION ${DATADIR}) +install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(FILES railcontrol.conf.dist TYPE SYSCONF RENAME railcontrol.conf) include(CPack) diff --git a/COMPILING-de.md b/COMPILING-de.md index b9962cd5..c1735f9d 100644 --- a/COMPILING-de.md +++ b/COMPILING-de.md @@ -93,6 +93,39 @@ Ein Update kann folgendermassen durchgeführt werden: git pull make ``` +## Kompilieren mit cmake + +cmake Unterstützung befindet sich noch in Entwicklung. Falls das Bauen mit cmake +nicht klappt, benutze GNU Make. + +Konfiguriere das Bauen außerhalb der Quelltextverzeichnisse + +``` +cmake -B build +``` + +Kompilieren RailControl mittels + +``` +cmake --build build +``` + +Installiere RailControl (als root) mittels + +``` +cmake --install build +``` + +### cmake Entwickler-Modus + +Um RailControl zu entwickeln, "installiere" RailControl in die Git Arbeitskopie. +Das Ergebnis ist ähnlich zum Bauen mit GNU Make. + +``` +cmake -B build -DINSTALL_IN_PLACE=1 +cmake --build build +cmake --install build +``` # Kompilieren unter Mac OS X diff --git a/COMPILING-en.md b/COMPILING-en.md index 256827b5..14b42005 100644 --- a/COMPILING-en.md +++ b/COMPILING-en.md @@ -98,6 +98,40 @@ git pull make ``` +## Compile with cmake + +cmake support is work in progress. In case the cmake build fails on your system, +please build with GNU Make. + +Configure the out-of-tree build directory + +``` +cmake -B build +``` + +Compile RailControl with + +``` +cmake --build build +``` + +Install RailControl (as root) with + +``` +cmake --install build +``` + +### cmake develper mode + +To develop RailControl, "install" RailControl in the checked out working copy. +This is similar to building RailControl with GNU Make. + +``` +cmake -B build -DINSTALL_IN_PLACE=1 +cmake --build build +cmake --install build +``` + # Compile under Mac OS X The required developer tools can be installed in a terminal with: diff --git a/COMPILING-es.md b/COMPILING-es.md index e0adaa12..a3439361 100644 --- a/COMPILING-es.md +++ b/COMPILING-es.md @@ -94,6 +94,40 @@ git pull make ``` +## TODO TRANSLATE Compile with cmake + +cmake support is work in progress. In case the cmake build fails on your system, +please build with GNU Make. + +Configure the out-of-tree build directory + +``` +cmake -B build +``` + +Compile RailControl with + +``` +cmake --build build +``` + +Install RailControl (as root) with + +``` +cmake --install build +``` + +### cmake develper mode + +To develop RailControl, "install" RailControl in the checked out working copy. +This is similar to building RailControl with GNU Make. + +``` +cmake -B build -DINSTALL_IN_PLACE=1 +cmake --build build +cmake --install build +``` + # Compilar sobre Mac OS X Se puede instalar las heremientas requerido con: diff --git a/Makefile b/Makefile index f4a8164d..3f0a0ffb 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ endif CFLAGSSQLITE=-g -O2 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DHAVE_USLEEP CFLAGSZLIB=-g -O2 -Wno-implicit-function-declaration -CXXFLAGS=-I. -g -O2 -Wall -Wextra -pedantic -Werror -Wno-missing-braces -std=c++11 -D_GNU_SOURCE +CXXFLAGS=-I. -g -O2 -Wall -Wextra -pedantic -Werror -Wno-missing-braces -std=c++11 -D_GNU_SOURCE -DHTML_DATA_PATH=\"./html\" CXXFLAGSAMALGAMATION=-I. -g -O2 -Wall -Wextra -pedantic -Werror -Wno-missing-braces -std=c++11 LDFLAGS=-g LIBS=-lpthread -ldl diff --git a/Server/Web/WebClient.cpp b/Server/Web/WebClient.cpp index 20a3e380..b99622f6 100644 --- a/Server/Web/WebClient.cpp +++ b/Server/Web/WebClient.cpp @@ -784,7 +784,7 @@ namespace Server { namespace Web char workingDir[128]; if (getcwd(workingDir, sizeof(workingDir))) { - ss << workingDir << "/html" << virtualFile; + ss << HTML_DATA_PATH << virtualFile; } string sFile = ss.str(); const char* realFile = sFile.c_str();