我正在尝试在同一个 CMakeLists.txt 文件中为 32 位和 64 位编译一些代码。我认为最简单的方法是使用函数。编译中使用的(静态)库也构建在 CMakeLists.txt 文件中。然而,尽管将它们构建在不同的目录中,CMake 抱怨说:
add_library cannot create target "mylib" because another target with
the same name already exists. The existing target is a static library
created in source directory "/home/chris/proj".
问题代码是:
cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
enable_language(Fortran)
project(myproj)
set(libfolder ${PROJECT_SOURCE_DIR}/lib/)
function(build bit)
message("Build library")
set(BUILD_BINARY_DIR ${PROJECT_BINARY_DIR}/rel-${bit})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUILD_BINARY_DIR}/bin)
add_library(mylib STATIC ${libfolder}/mylib.for)
set(CMAKE_Fortran_FLAGS "-m${bit}")
endfunction()
build(32)
build(64)
我确定我遗漏了一些明显的东西,但看不到问题...