diff --git a/CMakeLists.txt b/CMakeLists.txt index b9fd664..e928f74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -206,6 +206,19 @@ target_link_libraries(${target} PRIVATE "${target}_lib") # target_setup_universal_binary(stb) #endif() +macro(cmake_option_to_python_bool cmake_opt python_opt) + if ("${cmake_opt}") + set("python_${python_opt}" "True") + else () + set("python_${python_opt}" "False") + endif () +endmacro() + +get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +cmake_option_to_python_bool(${GENERATOR_IS_MULTI_CONFIG} GENERATOR_IS_MULTI_CONFIG) + +configure_file(${CMAKE_CURRENT_LIST_DIR}/re-edit.py.in "${CMAKE_BINARY_DIR}/re-edit.py" @ONLY) + ####################################################### # Install ####################################################### @@ -265,3 +278,9 @@ target_link_libraries("${target_test}" gtest_main gmock "${target}_lib") target_include_directories("${target_test}" PUBLIC "${re-edit_CPP_SRC_DIR}") gtest_discover_tests("${target_test}") + +add_custom_target("run_tests" + COMMAND ${CMAKE_COMMAND} -E echo "Running tests using $" + COMMAND "$" + DEPENDS "${target_test}" + ) diff --git a/configure.py b/configure.py new file mode 100755 index 0000000..23ad82e --- /dev/null +++ b/configure.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 + +# Copyright (c) 2022 pongasoft +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# @author Yan Pujante + +import argparse +import os +import sys +import platform + +if sys.hexversion < 0x03070000: + print("You must use python version 3.7+") + sys.exit(1) + +parser = argparse.ArgumentParser(allow_abbrev=False, + usage='configure.py [-h] [-n] [-f] [-r] [-G GENERATOR] [-B BUILD_DIR] [-- ]', + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=''' +Notes + -G defaults to "Xcode" on macOS and "Visual Studio 16 2019" for Windows10 + run 'cmake --help' to get the list of generators supported + + For single-config generators, Debug is used by default and can be changed with -r for Release + For multi-config generators, -r is ignored + + To provide extra options to CMake you do it this way + python3 configure.py -- -Wdev + +Examples + # Use default paths and uses another generator + python3 configure.py -G "CodeBlocks - Unix Makefiles" + + # Use defaults + python3 configure.py +''') +parser.add_argument("-n", "--dry-run", help="Dry run (prints what it is going to do)", action="store_true", dest="dry_run") +parser.add_argument("-f", "--force", help="Force a regeneration (delete and recreate build folder)", action="store_true") +parser.add_argument("-r", "--release", help="Use CMake Release build type (for single-config generators)", action="store_true") +parser.add_argument("-G", "--generator", help="CMake generator (optional)") +parser.add_argument("-B", "--build-dir", help="Build folder (defaults to ./build)", dest="build_dir") +parser.add_argument('cmake_options', help="Any options for cmake", nargs=argparse.REMAINDER) + +args = parser.parse_args() + +# The CMakeLists.txt file is a sibling of this script +this_script_root_dir = os.path.dirname(os.path.realpath(sys.argv[0])) + +# CMake generator +cmake_generator = ['-G'] +if args.generator: + cmake_generator.append(args.generator) +else: + if platform.system() == 'Darwin': + cmake_generator.append('Xcode') + else: + cmake_generator.append('Visual Studio 16 2019') + +# CMake options +cmake_options = [] if not args.cmake_options else args.cmake_options[1:] + +# CMake build type (for single config generators) +cmake_build_type = [f'-DCMAKE_BUILD_TYPE={"Release" if args.release else "Debug"}'] + +# CMake build directory +build_dir = args.build_dir if args.build_dir else 'build' +cmake_build_dir = ['-B', build_dir] + +# CMake command +cmake_command = ['cmake', + *cmake_build_dir, + *cmake_build_type, + *cmake_generator, + *cmake_options, + this_script_root_dir] + +if args.dry_run: + escaped_command = ' '.join([f'"{x}"' for x in cmake_command[1:]]) + print(f'cmake {escaped_command}') +else: + if args.force: + import shutil + if os.path.exists(build_dir): + shutil.rmtree(build_dir) + + import subprocess + subprocess.run(cmake_command) + + + + + diff --git a/re-edit.py.in b/re-edit.py.in new file mode 100755 index 0000000..0883267 --- /dev/null +++ b/re-edit.py.in @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 + +# Copyright (c) 2022 pongasoft +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# @author Yan Pujante + +import argparse +import sys + +if sys.hexversion < 0x03070000: + print("You must use python version 3.7+") + sys.exit(1) + +generator_is_multi_config = @python_GENERATOR_IS_MULTI_CONFIG@ +cmake_single_config_build_type = '@CMAKE_BUILD_TYPE@' + +parser = argparse.ArgumentParser(allow_abbrev=False, + usage=f're-edit.py [-hnvbdr] [ ...] [-- [native-options]]', + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=f''' +Commands + ---- Main commands ---- + clean : clean all builds + build : build the tool + test : run the tests for the tool + archive : create an archive containing the tool + + ---- CMake target ---- + : Any unknown is treated as a cmake target + + --- Native options ---- + Pass remaining options to the native tool (ex: -- -j 8 for parallel build) +''') + +parser.add_argument("-n", "--dry-run", help="Dry run (prints what it is going to do)", action="store_true", + dest="dry_run") +parser.add_argument("-v", "--verbose", help="Verbose build", action="store_true") +parser.add_argument("-b", "--banner", help="Display a banner before every command", action="store_true") +parser.add_argument("-d", "--debug", help="use Debug build config", action="store_true") +parser.add_argument("-r", "--release", help="use Release build config", action="store_true") + +parser.add_argument('command', help='See "Commands" section', nargs=argparse.REMAINDER) + +args = parser.parse_args() + +# determines '--' position +commands = args.command +native_tool_options = [] +pos = next((i for i, x in enumerate(commands) if x == '--'), -1) +if pos > -1: + commands = args.command[:pos] + native_tool_options = args.command[pos:] + +if not commands: + parser.print_help() + exit(0) + +available_commands = { + 'clean': 'clean', + 'build': 're-edit', + 'test': 'run_tests', + 'archive': 'create_archive' +} + +cmake_verbose = [] if not args.verbose else ['--verbose'] + +if args.release and args.debug: + print('Conflicting options (-r and -d) used') + exit(1) + +config = 'Debug' +cmake_config = ['--config', config] + +step = 0 + +for command in commands: + step += 1 + if args.banner: + if step > 1: + print("") + print("") + print("=============================================================") + print("==") + print(f"== Step {step} : {command}") + print("==") + print("=============================================================") + if command in available_commands: + cmake_target = available_commands[command] + else: + cmake_target = command + cmake_command = ['cmake', '--build', '.', *cmake_verbose, *cmake_config, '--target', cmake_target, *native_tool_options] + if args.dry_run: + print(' '.join(cmake_command)) + else: + import os + import subprocess + + this_script_root_dir = os.path.dirname(os.path.realpath(sys.argv[0])) + cp = subprocess.run(cmake_command, cwd=this_script_root_dir) + if cp.returncode != 0: + args = ' '.join(cp.args) + print(f'Error: Command "{command}" [{args}] failed with error code {cp.returncode}', file=sys.stderr) + exit(cp.returncode) diff --git a/test/cpp/re/edit/lua/TestDevice2D.cpp b/test/cpp/re/edit/lua/TestDevice2D.cpp index 4be7af7..e7f336f 100644 --- a/test/cpp/re/edit/lua/TestDevice2D.cpp +++ b/test/cpp/re/edit/lua/TestDevice2D.cpp @@ -25,7 +25,7 @@ namespace re::edit::lua::Test { inline std::string getResourceFile(std::string const &iFilename) { - return re::mock::fmt::path(RE_EDIT_PROJECT_DIR, "test", "resources", "re", "edit", "lua", iFilename); + return fs::path(RE_EDIT_PROJECT_DIR) / "test" / "resources" / "re" / "edit" / "lua" / iFilename; } inline ::testing::AssertionResult Eq(ImVec2 const &lhs, ImVec2 const &rhs) { diff --git a/test/cpp/re/edit/lua/TestHDGui2D.cpp b/test/cpp/re/edit/lua/TestHDGui2D.cpp index 2feaaae..f7cc6fb 100644 --- a/test/cpp/re/edit/lua/TestHDGui2D.cpp +++ b/test/cpp/re/edit/lua/TestHDGui2D.cpp @@ -39,7 +39,7 @@ using namespace re::edit::widget::attribute; std::string getResourceFile(std::string const &iFilename) { - return re::mock::fmt::path(RE_EDIT_PROJECT_DIR, "test", "resources", "re", "edit", "lua", iFilename); + return fs::path(RE_EDIT_PROJECT_DIR) / "test" / "resources" / "re" / "edit" / "lua" / iFilename; } //------------------------------------------------------------------------