Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build with CMake #74

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 22 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 "$<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 $<TARGET_FILE:spasm> ${asm_file}
)
SET_TESTS_PROPERTIES(autotest_${asm_file}
PROPERTIES
FIXTURES_REQUIRED f_build_assembler)
endforeach()
1 change: 1 addition & 0 deletions version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define SPASM_NG_VERSION "@GIT_TREE_DESC@"