From b1c473695126a2aef007103138cab89db14f975f Mon Sep 17 00:00:00 2001 From: Peter Marheine Date: Fri, 15 Sep 2023 15:53:43 +1000 Subject: [PATCH] Support building with cmake This should permit unification of the makefile and msbuild projects. --- CMakeLists.txt | 90 ++++++++++++++++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 22 +++++++++++ version.h.in | 1 + 3 files changed, 113 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 tests/CMakeLists.txt create mode 100644 version.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1eae54d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,90 @@ +cmake_minimum_required(VERSION 3.7) +project(spasm-ng + HOMEPAGE_URL https://github.com/alberthdev/spasm-ng +) + +add_compile_options(-Wall) + +add_executable( + spasm + main.cpp opcodes.cpp pass_one.cpp pass_two.cpp utils.cpp + export.cpp preop.cpp directive.cpp console.cpp expand_buf.cpp + hash.cpp list.cpp parser.cpp storage.cpp errors.cpp bitmap.cpp + modp_ascii.cpp opcodes_ez80.cpp +) +target_link_libraries(spasm m) + +# https://github.com/alberthdev/spasm-ng/issues/73 +set_property(TARGET spasm PROPERTY CXX_STANDARD 11) + +set(ENABLE_APP_SIGNING ON CACHE BOOL "Enable support for signing applications") +if (ENABLE_APP_SIGNING) + find_package(PkgConfig REQUIRED) + pkg_check_modules(gmp REQUIRED IMPORTED_TARGET gmp) + find_package(OpenSSL + REQUIRED + COMPONENTS Crypto) + target_link_libraries(spasm OpenSSL::Crypto PkgConfig::gmp) +else() + add_compile_definitions(NO_APPSIGN) +endif() + +set(ENABLE_DEBUG_PRINT OFF CACHE BOOL "Enable additional debug messages") +if (ENABLE_DEBUG_PRINT) + add_compile_definitions(DEBUG_PRINT) +endif() + +add_compile_definitions( + USE_REUSABLES + USE_BUILTIN_FCREATE +) +if (NOT WIN32) + add_compile_definitions(UNIXVER) +endif() + +# Version generation +find_package(Git) +if (Git_FOUND) + execute_process( + COMMAND "${GIT_EXECUTABLE}" describe --always --dirty + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + RESULT_VARIABLE res + OUTPUT_VARIABLE GIT_TREE_DESC + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +else() + set(GIT_TREE_DESC "unknown") +endif() +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/version.h") +target_include_directories(spasm + PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" +) +# Trick from https://cmake.org/pipermail/cmake/2018-October/068389.html +# to force a reconfigure on git change so the version string is always up to date +set_property(GLOBAL APPEND + PROPERTY CMAKE_CONFIGURE_DEPENDS + "${CMAKE_SOURCE_DIR}/.git/index" +) + +# Tests +include(CTest) +add_subdirectory(${PROJECT_SOURCE_DIR}/tests) + +# Install target +include(GNUInstallDirs) +install(TARGETS spasm) +install(FILES README.md LICENSE + DESTINATION ${CMAKE_INSTALL_DOCDIR}/spasm +) +file(GLOB include_files "inc/*.inc") +install(FILES ${include_files} + DESTINATION ${CMAKE_INSTALL_DATADIR}/spasm/inc +) + +# Distribution packaging +set(CPACK_PACKAGE_VERSION "${GIT_TREE_DESC}") +set(CPACK_PACKAGE_DESCRIPTION "SPASM-ng is a z80 assembler with extra features to support development for TI calculators.") +set(CPACK_PACKAGE_CONTACT "alberthdev@users.noreply.github.com") +set(CPACK_DEBIAN_PACKAGE_DEPENDS "zlib1g, libssl1.0.0, libgmp10") +include(CPack) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..c9cb52f --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,22 @@ +include(CTest) + +# A fixture that compiles the assembler so the test runner can run it +add_test(test_build_assembler + "${CMAKE_COMMAND}" + --build "${CMAKE_BINARY_DIR}" + --config "$" + --target spasm +) +set_tests_properties(test_build_assembler PROPERTIES FIXTURES_SETUP f_build_assembler) + +# Find every .asm file and run it under the test runner +file(GLOB_RECURSE asm_files "*.asm") +foreach(asm_file ${asm_files}) + add_test( + NAME autotest_${asm_file} + COMMAND ${CMAKE_SOURCE_DIR}/tests/test-runner.py $ ${asm_file} + ) + SET_TESTS_PROPERTIES(autotest_${asm_file} + PROPERTIES + FIXTURES_REQUIRED f_build_assembler) +endforeach() diff --git a/version.h.in b/version.h.in new file mode 100644 index 0000000..3fa30d4 --- /dev/null +++ b/version.h.in @@ -0,0 +1 @@ +#define SPASM_NG_VERSION "@GIT_TREE_DESC@"