Hi Andy,
My build supports several operating systems, including NaCl. The way I solved
this problem, essentially, is every place you would normally call
target_link_libraries, you replace it with a call to
LinkPossiblyPrebuiltLibraries, which is a macro I have defined like this:
macro (LinkPossiblyPrebuiltLibraries artifactName)
foreach (nextLibrary ${ARGN})
if (NACL AND (CMAKE_GENERATOR MATCHES "Visual Studio.*"))
# CMake spits out -l<fully-qualified-path>, which throws off
clang++ and results in
# libraries that can't be found. So instead we explicitly add
-l<libname> and
# -L${LIBS_DIR}
set_property (TARGET ${artifactName} APPEND_STRING PROPERTY
LINK_FLAGS " -l${nextLibrary}")
get_target_property (IsImported ${artifactName} "IMPORTED")
else ()
target_link_libraries (${artifactName} ${nextLibrary})
endif ()
endforeach ()
endmacro ()
Then separately I add in the link directory:
if (CMAKE_GENERATOR MATCHES "Visual Studio.*")
link_directories ("${LIBS_DIR}/$(Configuration)/${CpuArchSubdir}")
else ()
link_directories ("${NACL_SDK_ROOT}/lib/pnacl/${CMAKE_BUILD_TYPE}")
endif ()
There may very well be some mistakes in there, because I’ve simplified some
things that aren’t pertinent to this discussion. I should also point out that I
gave up on the Visual Studio NaCl toolchain somewhere around the pepper_35
days, because it became apparent that Google wasn’t putting much effort into
keeping it a going concern when the equivalent Linux/MacOSX toolchains worked
just fine. I guess things have improved since then?
Parag Chandra
Technical Lead, Mobile Team
Mobile: +1.919.824.1410
Ionic Security Inc.
1170 Peachtree St. NE STE 400, Atlanta, GA 30309
From: CMake <[email protected]> on behalf of Andy Yelland
<[email protected]>
Date: Tuesday, October 18, 2016 at 1:56 PM
To: "[email protected]" <[email protected]>
Subject: [EXTERNAL]: [CMake] Visual Studio generator, cross-compiling
Hi there
I am trying to coax a Cmake generation of a Visual Studio project of our
cross-platform product, that includes the PNaCl platform. The MSBuild setup
for PNaCl is a little bit fussy, and does not like the relative pathnames in
<AdditionalDependencies>, that get produced when the product has
target_link_libraries setup between the static libraries in the product. For
the sake of this mail I'll call the library project 'LibProject', which as it's
based on unix toolchain, will get the static lib created as libLibProject.a.
To be used as a command-line on the PNaCl cross-compiler, then it needs to get
translated to -lLibProject (without the lib prefix, or the .a suffix).
So going into the Visual Studio generator for the EXE project, at present are
the relative paths (will use Debug for this example):
../LibProject/Debug/libLibProject.a which gets added to the
<AdditionalDependencies> tag in the .vcxproj
To make the PNaCl MSBuild extension work, then instead it needs to be:
* <AdditionalDependencies>LibProject</AdditionalDependencies>
*
<AdditionalLibraryDirectories>../LibProject/Debug</AdditionalLibraryDirectories>
I am well aware that these get set by the cmake functions:
target_link_libraries() and link_directories(), so feel this ought to be
possible by Cmake script.
What I'm struggling with, is finding *a place* where I can:
* Query all the libraries that have become dependent on a target (the input
to the Generator). As target_link_libraries cascade, so my EXE project does
not know about all of its leaf libraries, so I'm not really sure if there is a
target property with ALL the dependent static library projects)
* Adjust this list, stripping: path, 'lib' and '.a'
* Inserting link_directories (or the equivalent, presuming it's some target
property now), corresponding to the relative paths that were stripped in the
step above
All of this would need to happen, after we've finished setting up the target,
but before the generator. Ideally this would be something I defined in the
ToolChain folder - but I can't think of any kind of callback in the CMake
system.
I'm open to other suggestions, about how to setup this visual studio
cross-compile. While PNaCl + MSDev may be rare, I feel that cross-compiling
for other unix systems with -l and -L library and path command-lines ought to
have been done before with Visual Studio generators.
Thanks in advance
Andy
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake