Call shell command after asm file generation in cm

2019-03-01 09:53发布

In android mk files it is possible to call a shell command right after generating assembly files with LOCAL_FILTER_ASM.

I was wondering is there any workaround to have something similar in cmake?

2条回答
我只想做你的唯一
2楼-- · 2019-03-01 10:30

It's very hard to say since you haven't provided any example of what you currently have.

However, you can use the add_custom_command() function to add before and after scripts to any target (see the bottom of the page in the "Build Events" section for the syntax you want).

查看更多
欢心
3楼-- · 2019-03-01 10:49

I admit I had lookup what LOCAL_FILTER_ASM does.

So the following is my piece of code (same functionality just in CMake):

cmake_minimum_required(VERSION 3.0)
project(LocalFilterASM C ASM)

set(LOCAL_FILTER_ASM "cp")

string(
    REPLACE 
        "<ASSEMBLY_SOURCE>" "<OBJECT>.S.original" 
        MY_CREATE_ASSEMBLY "${CMAKE_C_CREATE_ASSEMBLY_SOURCE}"
)
string(
   REPLACE 
        "<SOURCE>" "<OBJECT>.S" 
         MY_COMPILE_OBJECT "${CMAKE_ASM_COMPILE_OBJECT}"
)

set(
    CMAKE_C_COMPILE_OBJECT 
        "${MY_CREATE_ASSEMBLY}"
        "${LOCAL_FILTER_ASM} <OBJECT>.S.original <OBJECT>.S"
        "${MY_COMPILE_OBJECT}"
) 

file(WRITE main.c "int main(void) { return 0; }")
add_executable(${PROJECT_NAME} main.c)

This just takes some of the existing CMake compiler rules and combines it into a new multi-line rule for CMAKE_C_COMPILE_OBJECT. Please note that this will only work with CMake's makefile generators.

查看更多
登录 后发表回答