How to set up alternate builds with optional libraries

I have some code which I want to package into two different binaries: one as a command-line tool, and the other using the wxWidgets toolkit. This is a very simple project, all the code is the same except for main(). I would like one build config to use wxmain.cpp and link the wx libs, and the other to use main.cpp and no libs.

Is there an easy way to configure Clion and Cmake to do this?

Thanks.

0
2 comments

Guy,

If I understand your case correctly it's possible to implement specifying one CMake target for wxmain.cpp and link it the wx libs via target_link_libraries() command. Another target will contain only main.cpp. For more information please refer to CMake documantation.

0
Avatar
Permanently deleted user

Thanks, this is what i was looking for.

I came up with this:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES nominate_pal.cpp nominate_pal.h nominate_sdv_lpe.cpp nominate_sdv_lpe.h)

add_executable(EPH ${SOURCE_FILES} main.cpp)

find_package(wxWidgets COMPONENTS net core base adv)

if(wxWidgets_FOUND)
    add_executable(wxEPH MACOSX_BUNDLE ${SOURCE_FILES} wxmain.cpp)

    include(${wxWidgets_USE_FILE})
    target_link_libraries(wxEPH ${wxWidgets_LIBRARIES})
endif()
0

Please sign in to leave a comment.