From 31c56d972ce93717d7cb92564c3ebe96e7fbf066 Mon Sep 17 00:00:00 2001 From: Nicole O'Connor Date: Mon, 1 Jan 2024 20:08:41 -0800 Subject: [PATCH] initial commit --- .gitignore | 1 + CMakeLists.txt | 39 ++++++++++++++++++ cmake/Binaries.cmake | 80 +++++++++++++++++++++++++++++++++++++ cmake/Colours.cmake | 24 +++++++++++ cmake/Qt.cmake | 37 +++++++++++++++++ conanfile.txt | 6 +++ src/bootlatch/bootlatch.cpp | 6 +++ 7 files changed, 193 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 cmake/Binaries.cmake create mode 100644 cmake/Colours.cmake create mode 100644 cmake/Qt.cmake create mode 100644 conanfile.txt create mode 100644 src/bootlatch/bootlatch.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e390b12 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/** \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2cdbb65 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 3.16) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) + +include(Colours) +include(Binaries) + +project(bootlatch VERSION 0.1) +string(TIMESTAMP BUILD_TIME) + +execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --output-folder=${CMAKE_BINARY_DIR} --build missing) + +include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake) + +set(CMAKE_CXX_STANDARD 17) + +# nlohmann/json +find_package(nlohmann_json) +include_directories(${nlohmann_json_INCLUDE_DIR}) + +include_directories(include) +include_directories(ext_include) +include_directories(${CMAKE_BINARY_DIR}/include) + +# docs +find_package(Doxygen) +if (DOXYGEN_FOUND) + configure_file(${CMAKE_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) + + add_custom_target(doc + COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Generating documentation with doxygen" + VERBATIM) +endif() + +build_executable(TARGET bootlatch + SUBDIRS bootlatch) + +install(TARGETS bootlatch RUNTIME) \ No newline at end of file diff --git a/cmake/Binaries.cmake b/cmake/Binaries.cmake new file mode 100644 index 0000000..fe3ad00 --- /dev/null +++ b/cmake/Binaries.cmake @@ -0,0 +1,80 @@ +include(GenerateExportHeader) + +link_directories(${CMAKE_CURRENT_BINARY_DIR}) +set(BUILD_SHARED_LIBS ON) +if (MSVC) + add_compile_options("/utf-8") +endif() + +function(build_library) + set(multiValueArgs SUBDIRS DEPENDS LIBRARIES) + set(oneValueArgs TARGET) + cmake_parse_arguments(build_library "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + set(target ${build_library_TARGET}) + set(targetsources) + foreach(subdir ${build_library_SUBDIRS}) + set(found_files) + file(GLOB_RECURSE found_files RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/src/${subdir}/*.cpp") + set(targetsources ${targetsources} ${found_files}) + endforeach() + + if (MSVC AND EXISTS "${CMAKE_SOURCE_DIR}/res/${target}.rc") + set(targetsources ${targetsources} "res/${target}.rc") + endif() + + add_library(${target} SHARED ${targetsources}) + if (MSVC) + set_target_properties(${target} PROPERTIES PREFIX "") + set_target_properties(${target} PROPERTIES LINK_FLAGS "/MAP") + GENERATE_EXPORT_HEADER(${target} + BASE_NAME ${target} + EXPORT_MACRO_NAME ${target}_EXPORT + EXPORT_FILE_NAME include/${target}_Export.h + STATIC_DEFINE ${target}_BUILT_AS_STATIC) + endif() + + if (build_library_LIBRARIES) + foreach (library ${build_library_LIBRARIES}) + target_link_libraries(${target} ${library}) + endforeach() + endif() + + if (build_library_DEPENDS) + add_dependencies(${target} ${build_library_DEPENDS}) + endif() +endfunction() + +function(build_executable) + set(multiValueArgs SUBDIRS DEPENDS LIBRARIES) + set(oneValueArgs TARGET) + cmake_parse_arguments(build_executable "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + set(target ${build_executable_TARGET}) + set(targetsources) + foreach(subdir ${build_executable_SUBDIRS}) + set(found_files) + file(GLOB_RECURSE found_files RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/src/${subdir}/*.cpp") + set(targetsources ${targetsources} ${found_files}) + endforeach() + + if (MSVC AND EXISTS "${CMAKE_SOURCE_DIR}/res/${target}.rc") + set(targetsources ${targetsources} "res/${target}.rc") + endif() + + add_executable(${target} ${targetsources}) + if (MSVC) + # tells MSVC to use int main() but still hide the console window + set_target_properties(${target} PROPERTIES LINK_FLAGS "/SUBSYSTEM:windows /ENTRY:mainCRTStartup") + endif() + + if (build_executable_LIBRARIES) + foreach (library ${build_executable_LIBRARIES}) + target_link_libraries(${target} ${library}) + endforeach() + endif() + + if (build_executable_DEPENDS) + add_dependencies(${target} ${build_executable_DEPENDS}) + endif() +endfunction() \ No newline at end of file diff --git a/cmake/Colours.cmake b/cmake/Colours.cmake new file mode 100644 index 0000000..3b65485 --- /dev/null +++ b/cmake/Colours.cmake @@ -0,0 +1,24 @@ +# basically an assembled version of https://stackoverflow.com/questions/18968979/how-to-get-colorized-output-with-cmake +# spelled with a u because the guy in the answer seemed to insist on it + +if(NOT MSVC) + string(ASCII 27 Esc) + set(ColourReset "${Esc}[0m") + set(ColourBold "${Esc}[1m") + set(Red "${Esc}[0;31m") + set(Green "${Esc}[0;32m") + set(Yellow "${Esc}[0;33m") + set(Blue "${Esc}[0;34m") + set(Magenta "${Esc}[0;35m") + set(Cyan "${Esc}[0;36m") + set(White "${Esc}[0;37m") + set(BoldRed "${Esc}[1;31m") + set(BoldGreen "${Esc}[1;32m") + set(BoldYellow "${Esc}[1;33m") + set(BoldBlue "${Esc}[1;34m") + set(BoldMagenta "${Esc}[1;35m") + set(BoldCyan "${Esc}[1;36m") + set(BoldWhite "${Esc}[1;37m") +endif() + + diff --git a/cmake/Qt.cmake b/cmake/Qt.cmake new file mode 100644 index 0000000..02ee0d7 --- /dev/null +++ b/cmake/Qt.cmake @@ -0,0 +1,37 @@ +set(QT_VERSION_STR "5.15.2") +set(CMAKE_PREFIX_PATH "C:\\Qt\\${QT_VERSION_STR}\\msvc2019_64") +find_package(Qt5 COMPONENTS Core Widgets REQUIRED) +set(QT_UIC_EXECUTABLE "C:\\Qt\\${QT_VERSION_STR}\\msvc2019_64\\bin\\uic.exe") + +file(STRINGS "${CMAKE_SOURCE_DIR}/res/moc.txt" mocfiles) + +set(mocdeps) + +foreach(moctgt ${mocfiles}) + string(REPLACE "include/" "include/moc/" outfile ${moctgt}) + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${outfile}" + COMMAND moc ${CMAKE_SOURCE_DIR}/${moctgt} -o ${CMAKE_CURRENT_BINARY_DIR}/${outfile} + COMMENT "Running moc for ${outfile}..." + DEPENDS "${CMAKE_SOURCE_DIR}/${moctgt}") + set (mocdeps ${mocdeps} ${outfile}) +endforeach() + +file(GLOB_RECURSE uilist RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/res/ui/*.ui") +set(uicsources) +foreach(uifile ${uilist}) + string(REGEX REPLACE "res/ui/" "" uiname ${uifile}) + string(REGEX REPLACE ".ui\$" "" uiname ${uiname}) + string(REGEX REPLACE "/" "_" uiname ${uiname}) + # res/ui/dlg/license.ui should result in ${uiname} being "dlg_license" at this point + + set(headerfile "${CMAKE_CURRENT_BINARY_DIR}/include/ui_${uiname}.h") + + add_custom_command(OUTPUT "${headerfile}" PRE_BUILD + COMMAND ${QT_UIC_EXECUTABLE} -o "${headerfile}" "${CMAKE_SOURCE_DIR}/${uifile}" + DEPENDS "${CMAKE_SOURCE_DIR}/${uifile}" + COMMENT "Qt UIC: ${BoldCyan}${uifile}${ColourReset}") + + set(uicsources ${uicsources} "${headerfile}") +endforeach() + +add_custom_target(qtgenerated DEPENDS ${mocdeps} ${uicsources}) \ No newline at end of file diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 0000000..0de1509 --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,6 @@ +[requires] +nlohmann_json/3.11.2 + +[generators] +CMakeDeps +CMakeToolchain \ No newline at end of file diff --git a/src/bootlatch/bootlatch.cpp b/src/bootlatch/bootlatch.cpp new file mode 100644 index 0000000..a0cb285 --- /dev/null +++ b/src/bootlatch/bootlatch.cpp @@ -0,0 +1,6 @@ +#include + +int main(int argc, char* argv[]) { + std::cout << "It works!" << std::endl; + return 0; +} \ No newline at end of file