cpputest icon indicating copy to clipboard operation
cpputest copied to clipboard

PROJECT_IS_TOP_LEVEL while using externalproject_add

Open KammutierSpule opened this issue 1 year ago • 10 comments

While using externalproject_add, CMakeLists.txt file is forcing some options based on PROJECT_IS_TOP_LEVEL.

While building for a target platform (different toolchain) I don't want to build and run those tests or some of options set by the "top level".

KammutierSpule avatar Sep 30 '24 10:09 KammutierSpule

Please be more specific.

thetic avatar Sep 30 '24 16:09 thetic

If I build cpputest with externalproject_add, this will make that the build is detected as a "top level" project https://github.com/cpputest/cpputest/blob/6f66733f7a1affc05a5ad2126d5c5eecf82f662f/CMakeLists.txt#L12 however, I want to still build it as a lib to be integrated and don't want it builds tests and try to run it.

KammutierSpule avatar Sep 30 '24 17:09 KammutierSpule

If I build cpputest with externalproject_add

I strongly encourage you to use FetchContent instead of ExternalProject. ExternalProject will create a totally separate build for CppUTest that will not inherit any of the settings of the parent project.

this will make that the build is detected as a "top level" project

PROJECT_IS_TOP_LEVEL is evaluating as true because ExternalProject is creating a totally independent build.

I want to still build it as a lib

It will still build as a library

[I] don't want it builds tests and try to run it

You can override any of the options controlling these settings

thetic avatar Sep 30 '24 19:09 thetic

@basvodde This is expected behavior. I think you can close this issue.

thetic avatar Oct 01 '24 01:10 thetic

If I build cpputest with externalproject_add

I strongly encourage you to use FetchContent instead of ExternalProject. ExternalProject will create a totally separate build for CppUTest that will not inherit any of the settings of the parent project.

How can I pass the cross-compiler (and eventually other options) in this case?

KammutierSpule avatar Oct 01 '24 08:10 KammutierSpule

I'll let it open just for the discussion for the next days, then close. Thanks!

basvodde avatar Oct 01 '24 08:10 basvodde

If I build cpputest with externalproject_add

I strongly encourage you to use FetchContent instead of ExternalProject. ExternalProject will create a totally separate build for CppUTest that will not inherit any of the settings of the parent project.

How can I pass the cross-compiler (and eventually other options) in this case?

That is the default behavior of FetchContent.

thetic avatar Oct 01 '24 15:10 thetic

I'm trying to use FetchContent it builds, but I see it sets the CPP_PLATFORM to Gcc and then

/opt/esp/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: _deps/cpputest-build/src/CppUTest/libCppUTest.a(UtestPlatform.cpp.obj): in function `_ZL37PlatformSpecificWaitPidImplementationiPii':
/workspaces/dte_communications/build_unit_tests/_deps/cpputest-src/src/Platforms/Gcc/UtestPlatform.cpp:146:(.text+0x86): undefined reference to `waitpid'

Maybe I should be able to build my own UtestPlatform.cpp but I can't see how to override it using CMake options

KammutierSpule avatar Oct 03 '24 20:10 KammutierSpule

I would try overriding the platform to armcc which tends to be more compatible with bare metal projects.

thetic avatar Oct 03 '24 21:10 thetic

I'm trying to use FetchContent it builds, but I see it sets the CPP_PLATFORM to Gcc and then

/opt/esp/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: _deps/cpputest-build/src/CppUTest/libCppUTest.a(UtestPlatform.cpp.obj): in function `_ZL37PlatformSpecificWaitPidImplementationiPii':
/workspaces/dte_communications/build_unit_tests/_deps/cpputest-src/src/Platforms/Gcc/UtestPlatform.cpp:146:(.text+0x86): undefined reference to `waitpid'

Maybe I should be able to build my own UtestPlatform.cpp but I can't see how to override it using CMake options

Your compiler is finding waitpid but your linker isn't. You can try overriding it before you call FetchContent:

set(CPPUTEST_HAVE_WAITPID OFF CACHE BOOL "" FORCE)

# ...

FetchContent_Declare(cpputest
    # ...
)

thetic avatar Nov 23 '24 04:11 thetic