diff options
| author | Fuwn <[email protected]> | 2022-01-21 16:42:38 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-01-21 16:42:38 -0800 |
| commit | f303c65b2935cc54ef88a87f3e0511b8ff0c07e3 (patch) | |
| tree | a349ebb5de4a98116dd4066e7ebc053370301a32 | |
| parent | fix(.gitignore): ignore all build directories (diff) | |
| download | soyuz-f303c65b2935cc54ef88a87f3e0511b8ff0c07e3.tar.xz soyuz-f303c65b2935cc54ef88a87f3e0511b8ff0c07e3.zip | |
build: move to cmkr
| -rw-r--r-- | CMakeLists.txt | 153 | ||||
| -rw-r--r-- | build_tools/cmake/DownloadProject.CMakeLists.cmake.in | 17 | ||||
| -rw-r--r-- | build_tools/cmake/DownloadProject.cmake | 182 | ||||
| -rw-r--r-- | build_tools/cmake/LICENSE | 21 | ||||
| -rw-r--r-- | cmake.toml | 27 | ||||
| -rw-r--r-- | cmake/cmkr/cmkr.cmake | 222 | ||||
| -rw-r--r-- | include/soyuz/library.hh | 2 | ||||
| -rw-r--r-- | include/soyuz/tray.hh | 2 | ||||
| -rw-r--r-- | soyuz/CMakeLists.txt | 33 | ||||
| -rw-r--r-- | soyuz/library.cc | 2 | ||||
| -rw-r--r-- | soyuz/soyuz.cc | 2 | ||||
| -rw-r--r-- | soyuz/tray.cc | 2 |
12 files changed, 371 insertions, 294 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 606563a..8b48fcc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,36 +1,117 @@ -cmake_minimum_required(VERSION 3.20) -project(soyuz) - -option(DOWNLOAD_EXTERNAL_DEPENDENCIES "Download external dependencies" ON) - -if (DOWNLOAD_EXTERNAL_DEPENDENCIES) - find_package(Git) - if (Git_FOUND) - include(build_tools/cmake/DownloadProject.cmake) - - download_project( - PROJ fmt - GIT_REPOSITORY https://github.com/fmtlib/fmt.git - GIT_TAG master - SOURCE_DIR ${PROJECT_SOURCE_DIR}/deps/fmt - UPDATE_DISCONNECTED 1 - ) - else () - string(CONCAT GIT_NOT_FOUND_WARNING - "Git was not found on your system: skipping downloading external dependencies" - "This will likely lead to Soyuz being unable to compile" - "Consider installing or fixing Git" - ) - message(WARING GIT_NOT_FOUND_WARNING) - endif () -else () - string(CONCAT DOWNLOAD_EXTERNAL_DEPENDENCIES_WARNING - "Skipping downloading external dependencies" - "This will likely lead to Soyuz being unable to compile" - "Consider turning DOWNLOAD_EXTERNAL_DEPENDENCIES ON" - ) - message(WARING DOWNLOAD_EXTERNAL_DEPENDENCIES_WARNING) -endif () - -add_subdirectory(${PROJECT_NAME}) -add_subdirectory(${fmt_SOURCE_DIR}) +# This file is automatically generated from cmake.toml - DO NOT EDIT +# See https://github.com/build-cpp/cmkr for more information + +cmake_minimum_required(VERSION 3.15) + +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) + message(FATAL_ERROR "In-tree builds are not supported. Run CMake from a separate directory: cmake -B build") +endif() + +# Regenerate CMakeLists.txt automatically in the root project +set(CMKR_ROOT_PROJECT OFF) +if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(CMKR_ROOT_PROJECT ON) + + # Bootstrap cmkr + include("build_tools/cmake/cmkr/cmkr.cmake" OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT) + if(CMKR_INCLUDE_RESULT) + cmkr() + endif() + + # Enable folder support + set_property(GLOBAL PROPERTY USE_FOLDERS ON) +endif() + +# Create a configure-time dependency on cmake.toml to improve IDE support +if(CMKR_ROOT_PROJECT) + configure_file(cmake.toml cmake.toml COPYONLY) +endif() + +project(soyuz + LANGUAGES + CXX + C + VERSION + 1.1.1 + DESCRIPTION + "🚀 Discord RPC Blocker for Lunar Client" +) + +include(FetchContent) + +message(STATUS "Fetching fmt (8.1.1)...") +FetchContent_Declare( + fmt + GIT_REPOSITORY + https://github.com/fmtlib/fmt + GIT_TAG + 8.1.1 +) +FetchContent_MakeAvailable(fmt) + +# Target soyuz +set(CMKR_TARGET soyuz) +set(soyuz_SOURCES "") + +if(WIN32) # windows + list(APPEND soyuz_SOURCES + "soyuz/library.cc" + "soyuz/soyuz.cc" + "soyuz/tray.cc" + "soyuz/windows.cc" + "resource/resource.rc" + ) +endif() + +list(APPEND soyuz_SOURCES + cmake.toml +) + +set(CMKR_SOURCES ${soyuz_SOURCES}) +add_executable(soyuz) + +if(soyuz_SOURCES) + target_sources(soyuz PRIVATE ${soyuz_SOURCES}) +endif() + +get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT) +if(NOT CMKR_VS_STARTUP_PROJECT) + set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT soyuz) +endif() + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${soyuz_SOURCES}) + +target_compile_features(soyuz PRIVATE + cxx_std_20 + cxx_return_type_deduction +) + +if(MSVC) # msvc + target_compile_options(soyuz PRIVATE + "/W4" + "/WX" + ) +endif() + +target_include_directories(soyuz PRIVATE + "include/" +) + +target_link_libraries(soyuz PRIVATE + fmt::fmt +) + +set_target_properties(soyuz PROPERTIES + CXX_STANDARD + 20 + CXX_STANDARD_REQUIRED + ON + CMAKE_CXX_EXTENSIONS + OFF + WIN32_EXECUTABLE + ON +) + +unset(CMKR_TARGET) +unset(CMKR_SOURCES) + diff --git a/build_tools/cmake/DownloadProject.CMakeLists.cmake.in b/build_tools/cmake/DownloadProject.CMakeLists.cmake.in deleted file mode 100644 index 89be4fd..0000000 --- a/build_tools/cmake/DownloadProject.CMakeLists.cmake.in +++ /dev/null @@ -1,17 +0,0 @@ -# Distributed under the OSI-approved MIT License. See accompanying -# file LICENSE or https://github.com/Crascit/DownloadProject for details. - -cmake_minimum_required(VERSION 2.8.2) - -project(${DL_ARGS_PROJ}-download NONE) - -include(ExternalProject) -ExternalProject_Add(${DL_ARGS_PROJ}-download - ${DL_ARGS_UNPARSED_ARGUMENTS} - SOURCE_DIR "${DL_ARGS_SOURCE_DIR}" - BINARY_DIR "${DL_ARGS_BINARY_DIR}" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" -) diff --git a/build_tools/cmake/DownloadProject.cmake b/build_tools/cmake/DownloadProject.cmake deleted file mode 100644 index 0523f13..0000000 --- a/build_tools/cmake/DownloadProject.cmake +++ /dev/null @@ -1,182 +0,0 @@ -# Distributed under the OSI-approved MIT License. See accompanying -# file LICENSE or https://github.com/Crascit/DownloadProject for details. -# -# MODULE: DownloadProject -# -# PROVIDES: -# download_project( PROJ projectName -# [PREFIX prefixDir] -# [DOWNLOAD_DIR downloadDir] -# [SOURCE_DIR srcDir] -# [BINARY_DIR binDir] -# [QUIET] -# ... -# ) -# -# Provides the ability to download and unpack a tarball, zip file, git repository, -# etc. at configure time (i.e. when the cmake command is run). How the downloaded -# and unpacked contents are used is up to the caller, but the motivating case is -# to download source code which can then be included directly in the build with -# add_subdirectory() after the call to download_project(). Source and build -# directories are set up with this in mind. -# -# The PROJ argument is required. The projectName value will be used to construct -# the following variables upon exit (obviously replace projectName with its actual -# value): -# -# projectName_SOURCE_DIR -# projectName_BINARY_DIR -# -# The SOURCE_DIR and BINARY_DIR arguments are optional and would not typically -# need to be provided. They can be specified if you want the downloaded source -# and build directories to be located in a specific place. The contents of -# projectName_SOURCE_DIR and projectName_BINARY_DIR will be populated with the -# locations used whether you provide SOURCE_DIR/BINARY_DIR or not. -# -# The DOWNLOAD_DIR argument does not normally need to be set. It controls the -# location of the temporary CMake build used to perform the download. -# -# The PREFIX argument can be provided to change the base location of the default -# values of DOWNLOAD_DIR, SOURCE_DIR and BINARY_DIR. If all of those three arguments -# are provided, then PREFIX will have no effect. The default value for PREFIX is -# CMAKE_BINARY_DIR. -# -# The QUIET option can be given if you do not want to show the output associated -# with downloading the specified project. -# -# In addition to the above, any other options are passed through unmodified to -# ExternalProject_Add() to perform the actual download, patch and update steps. -# The following ExternalProject_Add() options are explicitly prohibited (they -# are reserved for use by the download_project() command): -# -# CONFIGURE_COMMAND -# BUILD_COMMAND -# INSTALL_COMMAND -# TEST_COMMAND -# -# Only those ExternalProject_Add() arguments which relate to downloading, patching -# and updating of the project sources are intended to be used. Also note that at -# least one set of download-related arguments are required. -# -# If using CMake 3.2 or later, the UPDATE_DISCONNECTED option can be used to -# prevent a check at the remote end for changes every time CMake is run -# after the first successful download. See the documentation of the ExternalProject -# module for more information. It is likely you will want to use this option if it -# is available to you. Note, however, that the ExternalProject implementation contains -# bugs which result in incorrect handling of the UPDATE_DISCONNECTED option when -# using the URL download method or when specifying a SOURCE_DIR with no download -# method. Fixes for these have been created, the last of which is scheduled for -# inclusion in CMake 3.8.0. Details can be found here: -# -# https://gitlab.kitware.com/cmake/cmake/commit/bdca68388bd57f8302d3c1d83d691034b7ffa70c -# https://gitlab.kitware.com/cmake/cmake/issues/16428 -# -# If you experience build errors related to the update step, consider avoiding -# the use of UPDATE_DISCONNECTED. -# -# EXAMPLE USAGE: -# -# include(DownloadProject) -# download_project(PROJ googletest -# GIT_REPOSITORY https://github.com/google/googletest.git -# GIT_TAG master -# UPDATE_DISCONNECTED 1 -# QUIET -# ) -# -# add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}) -# -#======================================================================================== - - -set(_DownloadProjectDir "${CMAKE_CURRENT_LIST_DIR}") - -include(CMakeParseArguments) - -function(download_project) - - set(options QUIET) - set(oneValueArgs - PROJ - PREFIX - DOWNLOAD_DIR - SOURCE_DIR - BINARY_DIR - # Prevent the following from being passed through - CONFIGURE_COMMAND - BUILD_COMMAND - INSTALL_COMMAND - TEST_COMMAND - ) - set(multiValueArgs "") - - cmake_parse_arguments(DL_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - # Hide output if requested - if (DL_ARGS_QUIET) - set(OUTPUT_QUIET "OUTPUT_QUIET") - else() - unset(OUTPUT_QUIET) - message(STATUS "Downloading/updating ${DL_ARGS_PROJ}") - endif() - - # Set up where we will put our temporary CMakeLists.txt file and also - # the base point below which the default source and binary dirs will be. - # The prefix must always be an absolute path. - if (NOT DL_ARGS_PREFIX) - set(DL_ARGS_PREFIX "${CMAKE_BINARY_DIR}") - else() - get_filename_component(DL_ARGS_PREFIX "${DL_ARGS_PREFIX}" ABSOLUTE - BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}") - endif() - if (NOT DL_ARGS_DOWNLOAD_DIR) - set(DL_ARGS_DOWNLOAD_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-download") - endif() - - # Ensure the caller can know where to find the source and build directories - if (NOT DL_ARGS_SOURCE_DIR) - set(DL_ARGS_SOURCE_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-src") - endif() - if (NOT DL_ARGS_BINARY_DIR) - set(DL_ARGS_BINARY_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-build") - endif() - set(${DL_ARGS_PROJ}_SOURCE_DIR "${DL_ARGS_SOURCE_DIR}" PARENT_SCOPE) - set(${DL_ARGS_PROJ}_BINARY_DIR "${DL_ARGS_BINARY_DIR}" PARENT_SCOPE) - - # The way that CLion manages multiple configurations, it causes a copy of - # the CMakeCache.txt to be copied across due to it not expecting there to - # be a project within a project. This causes the hard-coded paths in the - # cache to be copied and builds to fail. To mitigate this, we simply - # remove the cache if it exists before we configure the new project. It - # is safe to do so because it will be re-generated. Since this is only - # executed at the configure step, it should not cause additional builds or - # downloads. - file(REMOVE "${DL_ARGS_DOWNLOAD_DIR}/CMakeCache.txt") - - # Create and build a separate CMake project to carry out the download. - # If we've already previously done these steps, they will not cause - # anything to be updated, so extra rebuilds of the project won't occur. - # Make sure to pass through CMAKE_MAKE_PROGRAM in case the main project - # has this set to something not findable on the PATH. - configure_file("${_DownloadProjectDir}/DownloadProject.CMakeLists.cmake.in" - "${DL_ARGS_DOWNLOAD_DIR}/CMakeLists.txt") - execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" - -D "CMAKE_MAKE_PROGRAM:FILE=${CMAKE_MAKE_PROGRAM}" - . - RESULT_VARIABLE result - ${OUTPUT_QUIET} - WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}" - ) - if(result) - message(FATAL_ERROR "CMake step for ${DL_ARGS_PROJ} failed: ${result}") - endif() - execute_process(COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE result - ${OUTPUT_QUIET} - WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}" - ) - if(result) - message(FATAL_ERROR "Build step for ${DL_ARGS_PROJ} failed: ${result}") - endif() - -endfunction() diff --git a/build_tools/cmake/LICENSE b/build_tools/cmake/LICENSE deleted file mode 100644 index db172e3..0000000 --- a/build_tools/cmake/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Crascit - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/cmake.toml b/cmake.toml new file mode 100644 index 0000000..97ce6be --- /dev/null +++ b/cmake.toml @@ -0,0 +1,27 @@ +# Reference: https://build-cpp.github.io/cmkr/cmake-toml + +[cmake] +version = "3.15" +cmkr-include = "cmake/cmkr/cmkr.cmake" + +[project] +name = "soyuz" +version = "1.1.1" +description = "🚀 Discord RPC Blocker for Lunar Client" +languages = ["CXX", "C"] + +[conditions] +windows = "WIN32" +msvc = "MSVC" + +[fetch-content] +fmt = { git = "https://github.com/fmtlib/fmt", tag = "8.1.1" } + +[target.soyuz] +type = "executable" +windows.sources = ["soyuz/*.cc", "resource/*.rc"] +private-include-directories = ["include/"] +properties = { CXX_STANDARD = "20", CXX_STANDARD_REQUIRED = true, CMAKE_CXX_EXTENSIONS = false, WIN32_EXECUTABLE = true } +compile-features = ["cxx_std_20", "cxx_return_type_deduction"] +msvc.compile-options = ["/W4", "/WX"] # /Wall +private-link-libraries = ["fmt::fmt"] diff --git a/cmake/cmkr/cmkr.cmake b/cmake/cmkr/cmkr.cmake new file mode 100644 index 0000000..1ed1435 --- /dev/null +++ b/cmake/cmkr/cmkr.cmake @@ -0,0 +1,222 @@ +include_guard() + +# Change these defaults to point to your infrastructure if desired +set(CMKR_REPO "https://github.com/build-cpp/cmkr" CACHE STRING "cmkr git repository" FORCE) +set(CMKR_TAG "v0.2.7" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE) + +# To bootstrap/generate a cmkr project: cmake -P cmkr.cmake +if(CMAKE_SCRIPT_MODE_FILE) + set(CMAKE_BINARY_DIR "${CMAKE_BINARY_DIR}/build") + set(CMAKE_CURRENT_BINARY_DIR "${CMAKE_BINARY_DIR}") + file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}") +endif() + +# Set these from the command line to customize for development/debugging purposes +set(CMKR_EXECUTABLE "" CACHE FILEPATH "cmkr executable") +set(CMKR_SKIP_GENERATION OFF CACHE BOOL "skip automatic cmkr generation") +set(CMKR_BUILD_TYPE "Debug" CACHE STRING "cmkr build configuration") + +# Disable cmkr if generation is disabled +if(DEFINED ENV{CI} OR CMKR_SKIP_GENERATION OR CMKR_BUILD_SKIP_GENERATION) + message(STATUS "[cmkr] Skipping automatic cmkr generation") + unset(CMKR_BUILD_SKIP_GENERATION CACHE) + macro(cmkr) + endmacro() + return() +endif() + +# Disable cmkr if no cmake.toml file is found +if(NOT CMAKE_SCRIPT_MODE_FILE AND NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake.toml") + message(AUTHOR_WARNING "[cmkr] Not found: ${CMAKE_CURRENT_SOURCE_DIR}/cmake.toml") + macro(cmkr) + endmacro() + return() +endif() + +# Convert a Windows native path to CMake path +if(CMKR_EXECUTABLE MATCHES "\\\\") + string(REPLACE "\\" "/" CMKR_EXECUTABLE_CMAKE "${CMKR_EXECUTABLE}") + set(CMKR_EXECUTABLE "${CMKR_EXECUTABLE_CMAKE}" CACHE FILEPATH "" FORCE) + unset(CMKR_EXECUTABLE_CMAKE) +endif() + +# Helper macro to execute a process (COMMAND_ERROR_IS_FATAL ANY is 3.19 and higher) +function(cmkr_exec) + execute_process(COMMAND ${ARGV} RESULT_VARIABLE CMKR_EXEC_RESULT) + if(NOT CMKR_EXEC_RESULT EQUAL 0) + message(FATAL_ERROR "cmkr_exec(${ARGV}) failed (exit code ${CMKR_EXEC_RESULT})") + endif() +endfunction() + +# Windows-specific hack (CMAKE_EXECUTABLE_PREFIX is not set at the moment) +if(WIN32) + set(CMKR_EXECUTABLE_NAME "cmkr.exe") +else() + set(CMKR_EXECUTABLE_NAME "cmkr") +endif() + +# Use cached cmkr if found +if(DEFINED ENV{CMKR_CACHE} AND EXISTS "$ENV{CMKR_CACHE}") + set(CMKR_DIRECTORY_PREFIX "$ENV{CMKR_CACHE}") + string(REPLACE "\\" "/" CMKR_DIRECTORY_PREFIX "${CMKR_DIRECTORY_PREFIX}") + if(NOT CMKR_DIRECTORY_PREFIX MATCHES "\\/$") + set(CMKR_DIRECTORY_PREFIX "${CMKR_DIRECTORY_PREFIX}/") + endif() +else() + set(CMKR_DIRECTORY_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/_cmkr_") +endif() +set(CMKR_DIRECTORY "${CMKR_DIRECTORY_PREFIX}${CMKR_TAG}") +set(CMKR_CACHED_EXECUTABLE "${CMKR_DIRECTORY}/bin/${CMKR_EXECUTABLE_NAME}") + +# Handle upgrading logic +if(CMKR_EXECUTABLE AND NOT CMKR_CACHED_EXECUTABLE STREQUAL CMKR_EXECUTABLE) + if(CMKR_EXECUTABLE MATCHES "^${CMAKE_CURRENT_BINARY_DIR}/_cmkr") + if(DEFINED ENV{CMKR_CACHE} AND EXISTS "$ENV{CMKR_CACHE}") + message(AUTHOR_WARNING "[cmkr] Switching to cached cmkr: '${CMKR_CACHED_EXECUTABLE}'") + if(EXISTS "${CMKR_CACHED_EXECUTABLE}") + set(CMKR_EXECUTABLE "${CMKR_CACHED_EXECUTABLE}" CACHE FILEPATH "Full path to cmkr executable" FORCE) + else() + unset(CMKR_EXECUTABLE CACHE) + endif() + else() + message(AUTHOR_WARNING "[cmkr] Upgrading '${CMKR_EXECUTABLE}' to '${CMKR_CACHED_EXECUTABLE}'") + unset(CMKR_EXECUTABLE CACHE) + endif() + elseif(DEFINED ENV{CMKR_CACHE} AND EXISTS "$ENV{CMKR_CACHE}" AND CMKR_EXECUTABLE MATCHES "^${CMKR_DIRECTORY_PREFIX}") + message(AUTHOR_WARNING "[cmkr] Upgrading cached '${CMKR_EXECUTABLE}' to '${CMKR_CACHED_EXECUTABLE}'") + unset(CMKR_EXECUTABLE CACHE) + endif() +endif() + +if(CMKR_EXECUTABLE AND EXISTS "${CMKR_EXECUTABLE}") + message(VERBOSE "[cmkr] Found cmkr: '${CMKR_EXECUTABLE}'") +elseif(CMKR_EXECUTABLE AND NOT CMKR_EXECUTABLE STREQUAL CMKR_CACHED_EXECUTABLE) + message(FATAL_ERROR "[cmkr] '${CMKR_EXECUTABLE}' not found") +elseif(NOT CMKR_EXECUTABLE AND EXISTS "${CMKR_CACHED_EXECUTABLE}") + set(CMKR_EXECUTABLE "${CMKR_CACHED_EXECUTABLE}" CACHE FILEPATH "Full path to cmkr executable" FORCE) + message(STATUS "[cmkr] Found cached cmkr: '${CMKR_EXECUTABLE}'") +else() + set(CMKR_EXECUTABLE "${CMKR_CACHED_EXECUTABLE}" CACHE FILEPATH "Full path to cmkr executable" FORCE) + message(VERBOSE "[cmkr] Bootstrapping '${CMKR_EXECUTABLE}'") + + message(STATUS "[cmkr] Fetching cmkr...") + if(EXISTS "${CMKR_DIRECTORY}") + cmkr_exec("${CMAKE_COMMAND}" -E rm -rf "${CMKR_DIRECTORY}") + endif() + find_package(Git QUIET REQUIRED) + cmkr_exec("${GIT_EXECUTABLE}" + clone + --config advice.detachedHead=false + --branch ${CMKR_TAG} + --depth 1 + ${CMKR_REPO} + "${CMKR_DIRECTORY}" + ) + message(STATUS "[cmkr] Building cmkr (using system compiler)...") + cmkr_exec("${CMAKE_COMMAND}" + --no-warn-unused-cli + "${CMKR_DIRECTORY}" + "-B${CMKR_DIRECTORY}/build" + "-DCMAKE_BUILD_TYPE=${CMKR_BUILD_TYPE}" + "-DCMAKE_UNITY_BUILD=ON" + "-DCMAKE_INSTALL_PREFIX=${CMKR_DIRECTORY}" + "-DCMKR_GENERATE_DOCUMENTATION=OFF" + ) + cmkr_exec("${CMAKE_COMMAND}" + --build "${CMKR_DIRECTORY}/build" + --config "${CMKR_BUILD_TYPE}" + --parallel + ) + cmkr_exec("${CMAKE_COMMAND}" + --install "${CMKR_DIRECTORY}/build" + --config "${CMKR_BUILD_TYPE}" + --prefix "${CMKR_DIRECTORY}" + --component cmkr + ) + if(NOT EXISTS ${CMKR_EXECUTABLE}) + message(FATAL_ERROR "[cmkr] Failed to bootstrap '${CMKR_EXECUTABLE}'") + endif() + cmkr_exec("${CMKR_EXECUTABLE}" version) + message(STATUS "[cmkr] Bootstrapped ${CMKR_EXECUTABLE}") +endif() +execute_process(COMMAND "${CMKR_EXECUTABLE}" version + RESULT_VARIABLE CMKR_EXEC_RESULT +) +if(NOT CMKR_EXEC_RESULT EQUAL 0) + message(FATAL_ERROR "[cmkr] Failed to get version, try clearing the cache and rebuilding") +endif() + +# Use cmkr.cmake as a script +if(CMAKE_SCRIPT_MODE_FILE) + if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake.toml") + execute_process(COMMAND "${CMKR_EXECUTABLE}" init + RESULT_VARIABLE CMKR_EXEC_RESULT + ) + if(NOT CMKR_EXEC_RESULT EQUAL 0) + message(FATAL_ERROR "[cmkr] Failed to bootstrap cmkr project. Please report an issue: https://github.com/build-cpp/cmkr/issues/new") + else() + message(STATUS "[cmkr] Modify cmake.toml and then configure using: cmake -B build") + endif() + else() + execute_process(COMMAND "${CMKR_EXECUTABLE}" gen + RESULT_VARIABLE CMKR_EXEC_RESULT + ) + if(NOT CMKR_EXEC_RESULT EQUAL 0) + message(FATAL_ERROR "[cmkr] Failed to generate project.") + else() + message(STATUS "[cmkr] Configure using: cmake -B build") + endif() + endif() +endif() + +# This is the macro that contains black magic +macro(cmkr) + # When this macro is called from the generated file, fake some internal CMake variables + get_source_file_property(CMKR_CURRENT_LIST_FILE "${CMAKE_CURRENT_LIST_FILE}" CMKR_CURRENT_LIST_FILE) + if(CMKR_CURRENT_LIST_FILE) + set(CMAKE_CURRENT_LIST_FILE "${CMKR_CURRENT_LIST_FILE}") + get_filename_component(CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) + endif() + + # File-based include guard (include_guard is not documented to work) + get_source_file_property(CMKR_INCLUDE_GUARD "${CMAKE_CURRENT_LIST_FILE}" CMKR_INCLUDE_GUARD) + if(NOT CMKR_INCLUDE_GUARD) + set_source_files_properties("${CMAKE_CURRENT_LIST_FILE}" PROPERTIES CMKR_INCLUDE_GUARD TRUE) + + file(SHA256 "${CMAKE_CURRENT_LIST_FILE}" CMKR_LIST_FILE_SHA256_PRE) + + # Generate CMakeLists.txt + cmkr_exec("${CMKR_EXECUTABLE}" gen + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + ) + + file(SHA256 "${CMAKE_CURRENT_LIST_FILE}" CMKR_LIST_FILE_SHA256_POST) + + # Delete the temporary file if it was left for some reason + set(CMKR_TEMP_FILE "${CMAKE_CURRENT_SOURCE_DIR}/CMakerLists.txt") + if(EXISTS "${CMKR_TEMP_FILE}") + file(REMOVE "${CMKR_TEMP_FILE}") + endif() + + if(NOT CMKR_LIST_FILE_SHA256_PRE STREQUAL CMKR_LIST_FILE_SHA256_POST) + # Copy the now-generated CMakeLists.txt to CMakerLists.txt + # This is done because you cannot include() a file you are currently in + configure_file(CMakeLists.txt "${CMKR_TEMP_FILE}" COPYONLY) + + # Add the macro required for the hack at the start of the cmkr macro + set_source_files_properties("${CMKR_TEMP_FILE}" PROPERTIES + CMKR_CURRENT_LIST_FILE "${CMAKE_CURRENT_LIST_FILE}" + ) + + # 'Execute' the newly-generated CMakeLists.txt + include("${CMKR_TEMP_FILE}") + + # Delete the generated file + file(REMOVE "${CMKR_TEMP_FILE}") + + # Do not execute the rest of the original CMakeLists.txt + return() + endif() + # Resume executing the unmodified CMakeLists.txt + endif() +endmacro() diff --git a/include/soyuz/library.hh b/include/soyuz/library.hh index db88870..c71fdc4 100644 --- a/include/soyuz/library.hh +++ b/include/soyuz/library.hh @@ -20,7 +20,7 @@ namespace soyuz { // high, // red // }; -static auto enum_windows_proc(HWND hwnd, LPARAM lparam) -> BOOL; +static BOOL CALLBACK enum_windows_proc(HWND hwnd, LPARAM lparam); auto find_lunar() -> DWORD; auto delete_handle(DWORD pid) -> int; auto write_log_file(const std::string &message) -> void; diff --git a/include/soyuz/tray.hh b/include/soyuz/tray.hh index 4dc360c..6cca253 100644 --- a/include/soyuz/tray.hh +++ b/include/soyuz/tray.hh @@ -12,7 +12,7 @@ #define LOG(message) logs.emplace_back(message); -auto WindowProcedure(HWND, UINT, WPARAM, LPARAM) -> LRESULT; // CALLBACK +LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM); auto minimize() -> void; auto restore() -> void; auto InitNotifyIconData() -> void; diff --git a/soyuz/CMakeLists.txt b/soyuz/CMakeLists.txt deleted file mode 100644 index e4cff77..0000000 --- a/soyuz/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -add_executable(${PROJECT_NAME} WIN32 - tray.cc - library.cc - ../resource/resource.rc - soyuz.cc - windows.cc -) - -target_include_directories(${PROJECT_NAME} PRIVATE - ${PROJECT_SOURCE_DIR}/include - ${PROJECT_SOURCE_DIR}/deps/include - ${PROJECT_SOURCE_DIR}/include/soyuz -) - -set_target_properties(${PROJECT_NAME} PROPERTIES - CXX_STANDARD 20 - CXX_STANDARD_REQUIRED ON - CMAKE_CXX_EXTENSIONS OFF -) -target_compile_features(${PROJECT_NAME} PUBLIC - cxx_std_20 - cxx_return_type_deduction -) - -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - target_compile_options(${PROJECT_NAME} PUBLIC /W4 /WX) # /Wall -else() - target_compile_options(${PROJECT_NAME} PUBLIC -Wall -Wextra -pedantic -Werror) -endif() -add_compile_options(-stdlib=libc++) - -find_package(fmt) -target_link_libraries(${PROJECT_NAME} PRIVATE fmt) diff --git a/soyuz/library.cc b/soyuz/library.cc index a169ac5..022bef4 100644 --- a/soyuz/library.cc +++ b/soyuz/library.cc @@ -17,7 +17,7 @@ namespace soyuz { fmt::ostream log_file = fmt::output_file("soyuz.log"); -static auto enum_windows_proc(HWND hwnd, LPARAM lparam) -> BOOL { +static BOOL CALLBACK enum_windows_proc(HWND hwnd, LPARAM lparam) { int length = GetWindowTextLength(hwnd); auto title = new CHAR[length + 1]; GetWindowText(hwnd, title, length); diff --git a/soyuz/soyuz.cc b/soyuz/soyuz.cc index 828e9f6..24fbe4f 100644 --- a/soyuz/soyuz.cc +++ b/soyuz/soyuz.cc @@ -19,7 +19,7 @@ extern TCHAR tip[64]; extern char class_name[]; extern std::vector<std::string> logs; -auto WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int show) -> int { // WINAPI +int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int show) { soyuz::init_log_file(); MSG messages; diff --git a/soyuz/tray.cc b/soyuz/tray.cc index d7742f5..e750973 100644 --- a/soyuz/tray.cc +++ b/soyuz/tray.cc @@ -17,7 +17,7 @@ TCHAR tip[64] = TEXT(WINDOW_TRAY_NAME); char class_name[] = WINDOW_TRAY_NAME; std::vector<std::string> logs; -auto WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) -> LRESULT { // CALLBACK +LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { if (message == WM_TASKBAR && !IsWindowVisible(window)) { minimize(); return 0; } |