Skip to content

Commit 7267d9b

Browse files
committed
Support building with cmake
This should permit unification of the makefile and msbuild projects.
1 parent 5f0786d commit 7267d9b

6 files changed

Lines changed: 113 additions & 41 deletions

File tree

CMakeLists.txt

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
cmake_minimum_required(VERSION 3.7)
2+
project(spasm-ng
3+
HOMEPAGE_URL https://github.com/alberthdev/spasm-ng
4+
)
5+
6+
add_compile_options(-Wall)
7+
8+
add_executable(
9+
spasm
10+
main.cpp opcodes.cpp pass_one.cpp pass_two.cpp utils.cpp
11+
export.cpp preop.cpp directive.cpp console.cpp expand_buf.cpp
12+
hash.cpp list.cpp parser.cpp storage.cpp errors.cpp bitmap.cpp
13+
modp_ascii.cpp opcodes_ez80.cpp
14+
)
15+
target_link_libraries(spasm m)
16+
17+
# https://github.com/alberthdev/spasm-ng/issues/73
18+
set_property(TARGET spasm PROPERTY CXX_STANDARD 11)
19+
20+
set(ENABLE_APP_SIGNING ON CACHE BOOL "Enable support for signing applications")
21+
if (ENABLE_APP_SIGNING)
22+
find_package(PkgConfig REQUIRED)
23+
pkg_check_modules(gmp REQUIRED IMPORTED_TARGET gmp)
24+
find_package(OpenSSL
25+
REQUIRED
26+
COMPONENTS Crypto)
27+
target_link_libraries(spasm OpenSSL::Crypto PkgConfig::gmp)
28+
else()
29+
add_compile_definitions(NO_APPSIGN)
30+
endif()
31+
32+
set(ENABLE_DEBUG_PRINT OFF CACHE BOOL "Enable additional debug messages")
33+
if (ENABLE_DEBUG_PRINT)
34+
add_compile_definitions(DEBUG_PRINT)
35+
endif()
36+
37+
add_compile_definitions(
38+
USE_REUSABLES
39+
USE_BUILTIN_FCREATE
40+
)
41+
if (NOT WIN32)
42+
add_compile_definitions(UNIXVER)
43+
endif()
44+
45+
# Version generation
46+
find_package(Git)
47+
if (Git_FOUND)
48+
execute_process(
49+
COMMAND "${GIT_EXECUTABLE}" describe --always --dirty
50+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
51+
RESULT_VARIABLE res
52+
OUTPUT_VARIABLE GIT_TREE_DESC
53+
ERROR_QUIET
54+
OUTPUT_STRIP_TRAILING_WHITESPACE
55+
)
56+
else()
57+
set(GIT_TREE_DESC "unknown")
58+
endif()
59+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/version.h")
60+
target_include_directories(spasm
61+
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}"
62+
)
63+
# Trick from https://cmake.org/pipermail/cmake/2018-October/068389.html
64+
# to force a reconfigure on git change so the version string is always up to date
65+
set_property(GLOBAL APPEND
66+
PROPERTY CMAKE_CONFIGURE_DEPENDS
67+
"${CMAKE_SOURCE_DIR}/.git/index"
68+
)
69+
70+
# Tests
71+
include(CTest)
72+
add_subdirectory(${PROJECT_SOURCE_DIR}/tests)
73+
74+
# Install target
75+
include(GNUInstallDirs)
76+
install(TARGETS spasm)
77+
install(FILES README.md LICENSE
78+
DESTINATION ${CMAKE_INSTALL_DOCDIR}/spasm
79+
)
80+
file(GLOB include_files "inc/*.inc")
81+
install(FILES ${include_files}
82+
DESTINATION ${CMAKE_INSTALL_DATADIR}/spasm/inc
83+
)
84+
85+
# Distribution packaging
86+
set(CPACK_PACKAGE_VERSION "${GIT_TREE_DESC}")
87+
set(CPACK_PACKAGE_DESCRIPTION "SPASM-ng is a z80 assembler with extra features to support development for TI calculators.")
88+
set(CPACK_PACKAGE_CONTACT "alberthdev@users.noreply.github.com")
89+
set(CPACK_DEBIAN_PACKAGE_DEPENDS "zlib1g, libssl1.0.0, libgmp10")
90+
include(CPack)

tests/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
include(CTest)
2+
3+
# A fixture that compiles the assembler so the test runner can run it
4+
add_test(test_build_assembler
5+
"${CMAKE_COMMAND}"
6+
--build "${CMAKE_BINARY_DIR}"
7+
--config "$<CONFIG>"
8+
--target spasm
9+
)
10+
set_tests_properties(test_build_assembler PROPERTIES FIXTURES_SETUP f_build_assembler)
11+
12+
# Find every .asm file and run it under the test runner
13+
file(GLOB_RECURSE asm_files "*.asm")
14+
foreach(asm_file ${asm_files})
15+
add_test(
16+
NAME autotest_${asm_file}
17+
COMMAND ${CMAKE_SOURCE_DIR}/tests/test-runner.py $<TARGET_FILE:spasm> ${asm_file}
18+
)
19+
SET_TESTS_PROPERTIES(autotest_${asm_file}
20+
PROPERTIES
21+
FIXTURES_REQUIRED f_build_assembler)
22+
endforeach()

version.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

version.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define SPASM_NG_VERSION "@GIT_TREE_DESC@"

version.sh

Lines changed: 0 additions & 39 deletions
This file was deleted.

version_base.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)