I am trying to compile code for 32 and 64 bits in the same CMakeLists.txt file. I thought the easiest way to do this is to use a function. The libraries (static) used in the compilation are also embedded in the CMakeLists.txt file. However, despite creating them in different directories, CMake complains that:
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".
with problem code:
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)
I am sure that I am missing something obvious, but I do not see a problem ...
source share