Skip to content

Commit

Permalink
bringing yasm CMakeLists.txt to this decade, and hunterizing package
Browse files Browse the repository at this point in the history
  • Loading branch information
Colm Vize committed Mar 27, 2023
1 parent 101bca9 commit e24da7d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 20 deletions.
62 changes: 54 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
PROJECT(yasm)
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
if (COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif (COMMAND cmake_policy)
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)


set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
INCLUDE(VersionGen)

set(version_file "${CMAKE_BINARY_DIR}/YASM-VERSION-FILE")
VERSION_GEN(PACKAGE_VERSION ${version_file} "1.3.0")

string (REGEX MATCH "([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)" _ ${PACKAGE_VERSION})

PROJECT(yasm VERSION 1.3.0)

OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON)

# Where to look first for cmake modules
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")

INCLUDE(YasmMacros)
INCLUDE(VersionGen)

OPTION(ENABLE_NLS "Enable message translations" OFF)

Expand All @@ -27,7 +32,6 @@ IF(NOT CMAKE_BUILD_TYPE)
FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)

VERSION_GEN(PACKAGE_VERSION "${CMAKE_BINARY_DIR}/YASM-VERSION-FILE" "1.3.0")

set (PACKAGE_STRING "yasm ${PACKAGE_VERSION}")

Expand All @@ -40,6 +44,48 @@ ADD_SUBDIRECTORY(libyasm)
ADD_SUBDIRECTORY(modules)
ADD_SUBDIRECTORY(frontends)


set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
set(include_install_dir "include")

set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(targets_export_name "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")

set (TOOLS
ytasm
vsyasm
yasm)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)

configure_file("Config.cmake.in" "${project_config}" @ONLY)

install(
TARGETS ${TOOLS}
EXPORT "${targets_export_name}"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "${include_install_dir}"
)

install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)

install(
EXPORT "${targets_export_name}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)

INSTALL(FILES
libyasm.h
${CMAKE_BINARY_DIR}/libyasm-stdint.h
Expand Down
1 change: 1 addition & 0 deletions Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
15 changes: 6 additions & 9 deletions cmake/modules/YasmMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,28 @@ macro (YASM_ADD_MODULE _module_NAME)
endmacro (YASM_ADD_MODULE)

macro (YASM_GENPERF _in_NAME _out_NAME)
get_target_property(_tmp_GENPERF_EXE genperf LOCATION)
add_custom_command(
OUTPUT ${_out_NAME}
COMMAND ${_tmp_GENPERF_EXE} ${_in_NAME} ${_out_NAME}
DEPENDS ${_tmp_GENPERF_EXE}
COMMAND $<TARGET_FILE:genperf> ${_in_NAME} ${_out_NAME}
DEPENDS $<TARGET_FILE:genperf>
MAIN_DEPENDENCY ${_in_NAME}
)
endmacro (YASM_GENPERF)

macro (YASM_RE2C _in_NAME _out_NAME)
get_target_property(_tmp_RE2C_EXE re2c LOCATION)
add_custom_command(
OUTPUT ${_out_NAME}
COMMAND ${_tmp_RE2C_EXE} ${ARGN} -o ${_out_NAME} ${_in_NAME}
DEPENDS ${_tmp_RE2C_EXE}
COMMAND $<TARGET_FILE:re2c> ${ARGN} -o ${_out_NAME} ${_in_NAME}
DEPENDS $<TARGET_FILE:re2c>
MAIN_DEPENDENCY ${_in_NAME}
)
endmacro (YASM_RE2C)

macro (YASM_GENMACRO _in_NAME _out_NAME _var_NAME)
get_target_property(_tmp_GENMACRO_EXE genmacro LOCATION)
add_custom_command(
OUTPUT ${_out_NAME}
COMMAND ${_tmp_GENMACRO_EXE} ${_out_NAME} ${_var_NAME} ${_in_NAME}
DEPENDS ${_tmp_GENMACRO_EXE}
COMMAND $<TARGET_FILE:genmacro> ${_out_NAME} ${_var_NAME} ${_in_NAME}
DEPENDS $<TARGET_FILE:genmacro>
MAIN_DEPENDENCY ${_in_NAME}
)
endmacro (YASM_GENMACRO)
Expand Down
5 changes: 2 additions & 3 deletions modules/preprocs/nasm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
add_executable(genversion preprocs/nasm/genversion.c)
get_target_property(_tmp_GENVERSION_EXE genversion LOCATION)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.mac
COMMAND ${_tmp_GENVERSION_EXE} ${CMAKE_CURRENT_BINARY_DIR}/version.mac
DEPENDS ${_tmp_GENVERSION_EXE}
COMMAND $<TARGET_FILE:genversion> ${CMAKE_CURRENT_BINARY_DIR}/version.mac
DEPENDS $<TARGET_FILE:genversion>
)

YASM_GENMACRO(
Expand Down

0 comments on commit e24da7d

Please sign in to comment.