c++ - CMake: Visual Studio Project Created Using OBJECT Library Feature -
i'm using cmake create have following visual studio solution layout:
solution + project1 (c) + project2 (fortran)
the goal create c wrapper (project1) around fortran routines (project2) combined single shared library. so, need link .obj file produced in fortran project produced in c project. possible using object library feature (introduced in cmake 2.8.8). detailed here
project1
creates shared library , project2
creates .obj file.
in cmakelists.txt of project1 use:
add_library(lib1${lib1_src} $<target_objects:lib2>)
in cmakelists.txt of project2 use:
add_library(lib2 object ${lib2_src})
in cmakelists.txt of solution use:
cmake_minimum_required(version 2.8.8) project (test) enable_language (c) enable_language (fortran) set(cmake_runtime_output_directory ${cmake_binary_dir}/bin) set(cmake_library_output_directory ${cmake_binary_dir}/lib) set(cmake_archive_output_directory ${cmake_binary_dir}/lib) include_directories(project1) include_directories(project2) add_subdirectory(project1) add_subdirectory(project2)`
the issue i'm having has do c project produced cmake. specifically, runtime library setting under properties --> configuration properties --> c/c++ --> code generation defaulted multi-threaded dll regardless of solution configuration current set (debug | release).
the issue seems related use of $<target_objects:objlib>
expression since removing result in creation of c project configures runtime library based on solution configuration.
anyone know why happening , how can modify cmake files correct it?
i able resolve problem adding 3rd project aggregates .obj files shared library.
solution + project1 (c) + project2 (fortran) + project3 (sharedlib)
in cmakelists.txt of project1 use:
add_library(lib1 object ${lib1_src})
in cmakelists.txt of project2 use:
add_library(lib2 object ${lib2_src})
in cmakelists.txt of project3 use:
add_library(libname shared $<target_objects:project1> $<target_objects:project2>)
Comments
Post a Comment