From e24da7d3dd429cdb54a4d1c363f731ecd76d8d4c Mon Sep 17 00:00:00 2001 From: Colm Vize Date: Mon, 27 Mar 2023 21:53:02 +0100 Subject: [PATCH] bringing yasm CMakeLists.txt to this decade, and hunterizing package --- CMakeLists.txt | 62 ++++++++++++++++++++++++---- Config.cmake.in | 1 + cmake/modules/YasmMacros.cmake | 15 +++---- modules/preprocs/nasm/CMakeLists.txt | 5 +-- 4 files changed, 63 insertions(+), 20 deletions(-) create mode 100644 Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 8df871cf7..63fec0b6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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}") @@ -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 diff --git a/Config.cmake.in b/Config.cmake.in new file mode 100644 index 000000000..6e9256eea --- /dev/null +++ b/Config.cmake.in @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") diff --git a/cmake/modules/YasmMacros.cmake b/cmake/modules/YasmMacros.cmake index ab1be00e9..661ed0576 100644 --- a/cmake/modules/YasmMacros.cmake +++ b/cmake/modules/YasmMacros.cmake @@ -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 $ ${_in_NAME} ${_out_NAME} + DEPENDS $ 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 $ ${ARGN} -o ${_out_NAME} ${_in_NAME} + DEPENDS $ 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 $ ${_out_NAME} ${_var_NAME} ${_in_NAME} + DEPENDS $ MAIN_DEPENDENCY ${_in_NAME} ) endmacro (YASM_GENMACRO) diff --git a/modules/preprocs/nasm/CMakeLists.txt b/modules/preprocs/nasm/CMakeLists.txt index e10a9dd12..f7fc82222 100644 --- a/modules/preprocs/nasm/CMakeLists.txt +++ b/modules/preprocs/nasm/CMakeLists.txt @@ -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 $ ${CMAKE_CURRENT_BINARY_DIR}/version.mac + DEPENDS $ ) YASM_GENMACRO(