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?




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.


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)

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

    target_link_libraries(wxEPH ${wxWidgets_LIBRARIES})