Custom project structure - CMAKE Error target_compile_option

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Custom project structure - CMAKE Error target_compile_option

Postby kriskadespe » Wed Mar 21, 2018 4:50 pm

I try to include CEF inside an already existing project, with a specific structure

myproject/
| - CMakeLists.txt <= 1. Top-level CMake configuration. add_subdirectory "externals" and "src" in that order.
| - src/
| - | - CMakeLists.txt <= 2. add_executable for myproject
| - | - ...
| - | - main.cpp
| - externals/
| - | - CMakeLists.txt <= 3. load all externals by calling add_subdirectory for each subdirectories
| - | - cef/
| - | - | - CMakeLists.txt <= 4. add_subdirectory(win32) on win32 archi, win64 on x64 windows archi, etc...
| - | - | - win32/ <= cef_binary_3.3325.1750.gaabe4c4_windows32.tar.bz2 uncompressed here
| - | - | - | - cmake/
| - | - | - | - Debug/
| - | - | - | - include/
| - | - | - | - libcef_dll/
| - | - | - | - ...
| - | - | - | - CMakeLists.txt <= Not used
| - | - | - | - LICENSE.txt
| - | - | - | - README.md

The main CMakeLists.txt (i.e. 1) is in charge of adding externals libraries (in externals folder) and sources (form src folder)
Code: Select all
cmake_minimum_required(VERSION 3.5)

# Add externals libraries
add_subdirectory("externals")

# Add Src
add_subdirectory("src")



The externals/cef/CMakeLists.txt is in charge of adding "libcef_lib" and "libcef_dll_wrapper" libraries:
Code: Select all
# Add CEF
set(CEF_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/win32")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CEF_ROOT}/cmake")

find_package(CEF REQUIRED)

# Logical target used to link the libcef library.
ADD_LOGICAL_TARGET(libcef_lib ${CEF_LIB_DEBUG} ${CEF_LIB_RELEASE})
SET_EXECUTABLE_TARGET_PROPERTIES(libcef_lib)

# Determine the target output directory.
SET_CEF_TARGET_OUT_DIR()

# Include the libcef_dll_wrapper target.
# Comes from the libcef_dll/CMakeLists.txt file in the binary distribution
# directory.
add_subdirectory(${CEF_LIBCEF_DLL_WRAPPER_PATH} libcef_dll_wrapper)

# Display configuration settings.
PRINT_CEF_CONFIG()



The src/CMakeLists.txt (i.e. 2) is in charge of declaring the executable "myproject" and linking against "libcef_lib", "libcef_dll_wrapper" and cef standard libs. (inspired by cefsimple project)
Code: Select all
project(myproject VERSION 1.0 LANGUAGES CXX)

....

# Executable target.
add_executable(myproject ${MYPROJECT_SRCS})
add_dependencies(myproject libcef_dll_wrapper)
SET_EXECUTABLE_TARGET_PROPERTIES(myproject)
target_link_libraries(myproject libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS})



When I try to generate the solution (Visual Studio .sln file) I got this error:
Code: Select all
1> CMake Error at externals/cef/win32/cmake/cef_macros.cmake:290 (target_compile_options):
1>   target_compile_options may only set INTERFACE properties on IMPORTED
1>   targets
1> Call Stack (most recent call first):
1>   externals/cef/win32/cmake/cef_macros.cmake(366): (SET_COMMON_TARGET_PROPERTIES)
1>   externals/cef/CMakeLists.txt(9): (SET_EXECUTABLE_TARGET_PROPERTIES)


So this error seems to come from the "cef_macros.cmake" file but the mistake must come from my specific usage...
If someone could help me on this...

Thanks
kriskadespe
Newbie
 
Posts: 7
Joined: Wed Mar 21, 2018 2:21 pm

Re: Custom project structure - CMAKE Error target_compile_op

Postby magreenblatt » Wed Mar 21, 2018 5:20 pm

What cmake version are you using? Does https://bitbucket.org/chromiumembedded/cef-project generate successfully for you?
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Re: Custom project structure - CMAKE Error target_compile_op

Postby kriskadespe » Thu Mar 22, 2018 1:01 pm

I'm using CMake version 3.11.0-rc4.

I have the following error with the cef-project
Code: Select all
...
-- Extracting D:/Projets/chromiumembedded-cef-project-b8be9fb209c4/third_party/cef/cef_binary_3.3282.1735.g1e5b631_windows32.tar.bz2...
CMake Warning at third_party/cef/cef_binary_3.3282.1735.g1e5b631_windows32/cmake/cef_variables.cmake:345 (message):
  CEF sandbox is not compatible with the current MSVC version (1913)
Call Stack (most recent call first):
  third_party/cef/cef_binary_3.3282.1735.g1e5b631_windows32/cmake/FindCEF.cmake:38 (include)
  CMakeLists.txt:54 (find_package)


-- Found PythonInterp: C:/Python27/python.exe (found version "2.7.10")
-- Downloading clang-format from Google Storage...
0> Failed to fetch file gs://chromium-clang-format/6ddedd571c56b8c184f30a3c1fc36984e8c10ccd for tools/buildtools/win/clang-format.exe, skipping. [Err: Traceback (most recent call last):
  File "D:\Projets\chromiumembedded-cef-project-b8be9fb209c4\tools\buildtools\gsutil.py", line 160, in <module>
    sys.exit(main())
  File "D:\Projets\chromiumembedded-cef-project-b8be9fb209c4\tools\buildtools\gsutil.py", line 157, in main
    clean=args.clean)
  File "D:\Projets\chromiumembedded-cef-project-b8be9fb209c4\tools\buildtools\gsutil.py", line 125, in run_gsutil
    gsutil_bin = ensure_gsutil(force_version, target, clean)
  File "D:\Projets\chromiumembedded-cef-project-b8be9fb209c4\tools\buildtools\gsutil.py", line 119, in ensure_gsutil
    raise InvalidGsutilError()
__main__.InvalidGsutilError
]
Downloading 1 files took 6.128000 second(s)
Failed to fetch file gs://chromium-clang-format/6ddedd571c56b8c184f30a3c1fc36984e8c10ccd for tools/buildtools/win/clang-format.exe. [Err: Traceback (most recent call last):
  File "D:\Projets\chromiumembedded-cef-project-b8be9fb209c4\tools\buildtools\gsutil.py", line 160, in <module>
    sys.exit(main())
  File "D:\Projets\chromiumembedded-cef-project-b8be9fb209c4\tools\buildtools\gsutil.py", line 157, in main
    clean=args.clean)
  File "D:\Projets\chromiumembedded-cef-project-b8be9fb209c4\tools\buildtools\gsutil.py", line 125, in run_gsutil
    gsutil_bin = ensure_gsutil(force_version, target, clean)
  File "D:\Projets\chromiumembedded-cef-project-b8be9fb209c4\tools\buildtools\gsutil.py", line 119, in ensure_gsutil
    raise InvalidGsutilError()
__main__.InvalidGsutilError
]
CMake Error at CMakeLists.txt:108 (message):
  Execution failed with unexpected result: 1


-- Configuring incomplete, errors occurred!
See also "D:/Projets/chromiumembedded-cef-project-b8be9fb209c4/build/CMakeFiles/CMakeOutput.log".

I'm not using a proxy.

but I have no problem with the cefsimple project...
kriskadespe
Newbie
 
Posts: 7
Joined: Wed Mar 21, 2018 2:21 pm

Re: Custom project structure - CMAKE Error target_compile_op

Postby Czarek » Thu Mar 22, 2018 1:53 pm

How about using a stable release of cmake?
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Custom project structure - CMAKE Error target_compile_op

Postby kriskadespe » Fri Mar 23, 2018 2:28 pm

Ok, so I downgrade my cmake version from 3.11 to 3.10.3, and this time the error message is slightly different but lot more explicit:

Code: Select all
CMake Error at externals/cef/win32/cmake/cef_macros.cmake:290 (target_compile_options):
  Cannot specify compile options for imported target "libcef_lib".


I don't have to call "SET_EXECUTABLE_TARGET_PROPERTIES(libcef_lib)" in my "externals/cef/CMakeLists.txt".
Removing this line fix the CMake problem, and the solution and project's files are generated.

There is two last things I would like to discuss with you:
1 - The include directories of the libcef_lib library seems not to be add when I call:
Code: Select all
target_link_libraries(myproject libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS})

Is that normal ? I thought that CMake includes the include directories of all target libraries ?

Adding those line fix the problem:
Code: Select all
include_directories(${CMAKE_SOURCE_DIR}/externals/cef/win32)
include_directories(${CMAKE_SOURCE_DIR}/externals/cef/win32/include)


2 - I have a link error:
Code: Select all
FAILED: src/myproject.exe
...
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\LINK : fatal error LNK1104: impossible d'ouvrir le fichier 'libcef_lib.lib'
  ninja: build stopped: subcommand failed.

I think the good file is "externals/cef/win32/Debug/libcef.lib"
Why the linker try to found a "_lib" suffixed file ? And how to fix that ?

Thank you for your help.
I hope that all this information will help others.
kriskadespe
Newbie
 
Posts: 7
Joined: Wed Mar 21, 2018 2:21 pm

Re: Custom project structure - CMAKE Error target_compile_op

Postby Czarek » Fri Mar 23, 2018 2:34 pm

This line:

Code: Select all
ADD_LOGICAL_TARGET(libcef_lib ${CEF_LIB_DEBUG} ${CEF_LIB_RELEASE})


Looks like you missed the quotes. Try this:

Code: Select all
ADD_LOGICAL_TARGET("libcef_lib" "${CEF_LIB_DEBUG}" "${CEF_LIB_RELEASE}")


See https://github.com/chromiumembedded/cef ... _lib&type=
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Custom project structure - CMAKE Error target_compile_op

Postby kriskadespe » Tue Mar 27, 2018 1:43 pm

I add the double quote as mention in your answer, but this not fix my problem.
I still have the link error:

Code: Select all
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\LINK : fatal error LNK1104: cannot open file 'libcef_lib.lib'
kriskadespe
Newbie
 
Posts: 7
Joined: Wed Mar 21, 2018 2:21 pm

Re: Custom project structure - CMAKE Error target_compile_op

Postby magreenblatt » Tue Mar 27, 2018 2:13 pm

There is no 'libcef_lib.lib'. It should be using the values of ${CEF_LIB_DEBUG} and ${CEF_LIB_RELEASE}. Are those variables defined at the time you call ADD_LOGICAL_TARGET?
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Re: Custom project structure - CMAKE Error target_compile_op

Postby kriskadespe » Wed Mar 28, 2018 12:04 pm

Both variable are set when I call "ADD_LOGICAL_TARGET("libcef_lib" "${CEF_LIB_DEBUG}" "${CEF_LIB_RELEASE}")"

Code: Select all
1> DEBUG externals/cef/: D:/Projets/myproject/externals/cef/win32/Debug/libcef.lib
1> RELEASE externals/cef/: D:/Projets/myproject/externals/cef/win32/Release/libcef.lib
kriskadespe
Newbie
 
Posts: 7
Joined: Wed Mar 21, 2018 2:21 pm

Re: Custom project structure - CMAKE Error target_compile_op

Postby magreenblatt » Wed Mar 28, 2018 2:05 pm

Do you have "set(CMAKE_CONFIGURATION_TYPES Debug Release)" in your top-level CMakeLists.txt file? Otherwise it will be looking for some other value for IMPORTED_LOCATION_* in the set_target_properties that ADD_LOGICAL_TARGET adds. See https://cmake.org/cmake/help/v3.0/prop_ ... ATION.html
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Next

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 48 guests