Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import cmake Packages in Windows Platform Will Enmurate All Compile Definitions in Exported CMakeLists.txt #4967

Open
LinkinPony opened this issue Apr 11, 2024 · 3 comments
Labels

Comments

@LinkinPony
Copy link

Xmake Version

xmake v2.8.9+HEAD.cb1b65054

Operating System Version and Architecture

Windows 11 22631.3296

Describe Bug

When using add_requires to import cmake packages and then use add_packages in Windows, generated CMakeLists.txt will enumerate all possible compile definition like this:

target_compile_definitions(xmake-cmakelists-test PRIVATE
    WIN32
    _WINDOWS
    CMAKE_INTDIR="Debug"
    _DEBUG
    CMAKE_INTDIR=\"Debug\"
    NDEBUG
    CMAKE_INTDIR="Release"
    CMAKE_INTDIR=\"Release\"
    CMAKE_INTDIR="MinSizeRel"
    CMAKE_INTDIR=\"MinSizeRel\"
    CMAKE_INTDIR="RelWithDebInfo"
    CMAKE_INTDIR=\"RelWithDebInfo\"
)
Full CMakeLists.txt generated in Windows
# this is the build file for project xmake-cmakelists-test
# it is autogenerated by the xmake build system.
# do not edit by hand.

# project
cmake_minimum_required(VERSION 3.15.0)
cmake_policy(SET CMP0091 NEW)
project(xmake-cmakelists-test VERSION 0.0.1 LANGUAGES CXX)

# target
add_executable(xmake-cmakelists-test "")
set_target_properties(xmake-cmakelists-test PROPERTIES OUTPUT_NAME "xmake-cmakelists-test")
set_target_properties(xmake-cmakelists-test PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/mingw/x86_64/release")
target_include_directories(xmake-cmakelists-test SYSTEM PRIVATE
    D:/Lib/install/release/opencv/4.5.5/include
)
target_compile_definitions(xmake-cmakelists-test PRIVATE
    WIN32
    _WINDOWS
    CMAKE_INTDIR="Debug"
    _DEBUG
    CMAKE_INTDIR=\"Debug\"
    NDEBUG
    CMAKE_INTDIR="Release"
    CMAKE_INTDIR=\"Release\"
    CMAKE_INTDIR="MinSizeRel"
    CMAKE_INTDIR=\"MinSizeRel\"
    CMAKE_INTDIR="RelWithDebInfo"
    CMAKE_INTDIR=\"RelWithDebInfo\"
)
target_compile_options(xmake-cmakelists-test PRIVATE
    $<$<COMPILE_LANGUAGE:C>:-m64>
    $<$<COMPILE_LANGUAGE:CXX>:-m64>
    $<$<COMPILE_LANGUAGE:C>:-DNDEBUG>
    $<$<COMPILE_LANGUAGE:CXX>:-DNDEBUG>
)
set_target_properties(xmake-cmakelists-test PROPERTIES CXX_EXTENSIONS OFF)
target_compile_features(xmake-cmakelists-test PRIVATE cxx_std_20)
if(MSVC)
    target_compile_options(xmake-cmakelists-test PRIVATE $<$<CONFIG:Release>:-Ox -fp:fast>)
else()
    target_compile_options(xmake-cmakelists-test PRIVATE -O3)
endif()
if(MSVC)
else()
    target_compile_options(xmake-cmakelists-test PRIVATE -fvisibility=hidden)
endif()
if(MSVC)
    set_property(TARGET xmake-cmakelists-test PROPERTY
        MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
target_link_directories(xmake-cmakelists-test PRIVATE
    D:/Lib/install/release/opencv/4.5.5/x64/vc17/lib
)
target_link_options(xmake-cmakelists-test PRIVATE
    -m64
)
target_sources(xmake-cmakelists-test PRIVATE
    src/test.cpp
)

Change platform into linux, generated CMakeLists.txt won't have these weird compile definitions.

Full CMakeLists.txt generated in Linux
# this is the build file for project xmake-cmakelists-test
# it is autogenerated by the xmake build system.
# do not edit by hand.

# project
cmake_minimum_required(VERSION 3.15.0)
cmake_policy(SET CMP0091 NEW)
project(xmake-cmakelists-test VERSION 0.0.1 LANGUAGES CXX)

# target
add_executable(xmake-cmakelists-test "")
set_target_properties(xmake-cmakelists-test PROPERTIES OUTPUT_NAME "xmake-cmakelists-test")
set_target_properties(xmake-cmakelists-test PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/linux/x86_64/release")
target_include_directories(xmake-cmakelists-test SYSTEM PRIVATE
    /usr/local/include/opencv4
)
target_compile_options(xmake-cmakelists-test PRIVATE
    $<$<COMPILE_LANGUAGE:C>:-m64>
    $<$<COMPILE_LANGUAGE:CXX>:-m64>
    $<$<COMPILE_LANGUAGE:C>:-DNDEBUG>
    $<$<COMPILE_LANGUAGE:CXX>:-DNDEBUG>
)
set_target_properties(xmake-cmakelists-test PROPERTIES CXX_EXTENSIONS OFF)
target_compile_features(xmake-cmakelists-test PRIVATE cxx_std_20)
if(MSVC)
    target_compile_options(xmake-cmakelists-test PRIVATE $<$<CONFIG:Release>:-Ox -fp:fast>)
else()
    target_compile_options(xmake-cmakelists-test PRIVATE -O3)
endif()
if(MSVC)
else()
    target_compile_options(xmake-cmakelists-test PRIVATE -fvisibility=hidden)
endif()
if(MSVC)
    set_property(TARGET xmake-cmakelists-test PROPERTY
        MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
target_link_libraries(xmake-cmakelists-test PRIVATE
    opencv_gapi
    opencv_highgui
    opencv_ml
    opencv_objdetect
    opencv_photo
    opencv_stitching
    opencv_video
    opencv_videoio
    opencv_imgcodecs
    opencv_dnn
    opencv_calib3d
    opencv_features2d
    opencv_flann
    opencv_imgproc
    opencv_core
)
target_link_directories(xmake-cmakelists-test PRIVATE
    /usr/local/lib
)
target_link_options(xmake-cmakelists-test PRIVATE
    -m64
    -Wl,-rpath,/usr/local/lib
)
target_sources(xmake-cmakelists-test PRIVATE
    src/main.cpp
)

Expected Behavior

In Windows, generated CMakeLists.txt with cmake "Local Package" should not have all possible definitions in target_compile_definitions

Project Configuration

set_project("xmake-cmakelists-test")
set_version("0.0.1")

add_rules("mode.release","mode.debug")
set_languages("cxx20")

add_requires("cmake::OpenCV", {system = true})
add_rules("mode.release","mode.debug")

target("xmake-cmakelists-test")
    add_packages("cmake::OpenCV")
    set_kind("binary")
    add_files("src/**.cpp")
target_end()

Additional Information and Error Logs

Use below commands to reproduce:

xmake f -m release  
xmake project -k cmakelists

Info of Windows:

  • Windows 11 22631.3296
  • CMake 3.29.1 (also tested in CMake 3.22.6)
  • MSVC 19.39.33522 (also tested in MinGW g++ 13.2.0)

Info of Linux:

  • Ububtu 22.04 LTS
  • CMake 3.29.1
  • g++ 12.3.0
@LinkinPony LinkinPony added the bug label Apr 11, 2024
@waruqi
Copy link
Member

waruqi commented Apr 18, 2024

Please use add_requires("opencv") instead of cmake::OpenCV whenever possible. Getting link information from cmake::OpenCV is unreliable.

@LinkinPony
Copy link
Author

Please use add_requires("opencv") instead of cmake::OpenCV whenever possible. Getting link information from cmake::OpenCV is unreliable.

Thanks for your reply. I have to use OpenCV with specific versions and options , so I can't simply use add_requires. Can I pass these options by using something like add_requires("libname", {configs = {option_1 = val_1}}), or I should create a local xrepo to do this?
I found Open3D hits the same issue too, but I didn't test more libs. For more convenience, is there a list of libs that should or shouldn't be located by cmake?

@LinkinPony LinkinPony closed this as not planned Won't fix, can't repro, duplicate, stale Apr 18, 2024
@LinkinPony LinkinPony reopened this Apr 18, 2024
@waruqi
Copy link
Member

waruqi commented May 10, 2024

Only xmake-repo packages support config options.

But you can set some cmake configuarion. https://xmake.io/#/package/local_package?id=default-switch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants