I want to build a static library name xcrt
that use CMake,
SET(CMAKE_AR "i386-elf-ar")
set(CMAKE_STATIC_LINKER_FLAGS rc CACHE STRING "" FORCE)
add_library(xcrt STATIC
xcrt_SRC}
)
when build, it executes the command:
i386-elf-ar cr libxcrt.a rc CMakeFiles/xcrt.dir/x86/crt1.asm.o CMakeFiles/xcrt.dir/x86/crti.asm.o CMakeFiles/xcrt.dir/x86/crtn.asm.o
I don’t want the cr
option to follow after the i386-elf-ar
command, I just want to use rc
option to replace cr
option, I had tried to set follow statement in CMakeList.txt.
set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> rc <TARGET> <LINK_FLAGS> <OBJECTS> ")
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> rc <TARGET> <LINK_FLAGS> <OBJECTS>")
but it does not work at all, what I should do when I need to use rc
option to replace cr
option? thanks a lot!
here is files and subdirectory in the xcrt
directory:
├── CMakeLists.txt
├── Makefile
└── x86
├── CMakeLists.txt
├── Makefile
├── crt1.asm
├── crti.asm
└── crtn.asm
I had tried to add following statement in CMakeList.txt.
set(CMAKE_C_ARCHIVE_CREATE " Scr ")
set(CMAKE_CXX_ARCHIVE_CREATE " Scr ")
set(CMAKE_C_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ")
set(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ")
set(CMAKE_ASM_ARCHIVE_CREATE " Scr ")
set(CMAKE_ASM_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ")
set(CMAKE_ASM_NASM_ARCHIVE_CREATE " Scr ")
set(CMAKE_ASM_NASM_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ")
but It still does not change anything about the ar process, when execute make
command, it still executes the command:
i386-elf-ar cr libxcrt.a rc CMakeFiles/xcrt.dir/x86/crt1.asm.o CMakeFiles/xcrt.dir/x86/crti.asm.o CMakeFiles/xcrt.dir/x86/crtn.asm.o
I don’t know why, could anyone helps me, thanks a lot!
You want to look into CMAKE_TOOLCHAIN_FILES. What you are currently doing isn’t correct at all.
after multiple tries, I found the reason, because my source files are all .asm files, I must use CMAKE_ASM_NASM_CREATE_STATIC_LIBRARY, not CMAKE_C_CREATE_STATIC_LIBRARY, you can find CMAKE_DEPENDS_LANGUAGES
from the file which in /CMakeFiles/*.dir/DependInfo.cmake
,the worked ar process is:
set(CMAKE_AR "i386-elf-ar")
set(CMAKE_ASM_NASM_CREATE_STATIC_LIBRARY "<CMAKE_AR> rc <TARGET> <OBJECTS> ")
hope it can help someone!