Build configuration in CLion - clion

How can I create a build configuration for release build (with optimizations, etc.)
The project is imported from existing sources, with a custom CMakeLists.txt file.
In the Edit Configurations window, only "Debug" appears as configuration, with no way to add another configuration.
The CMakeLists.txt file:
cmake_minimum_required(VERSION 3.6)
project(epi CXX)
set(CMAKE_CXX_STANDARD 14)
find_package(OpenCV REQUIRED)
include_directories(SYSTEM external/include)
add_compile_options(-Wall -Wextra -Wno-sign-compare)
file(GLOB_RECURSE EPI_SRC "src/*")
add_executable(epi ${EPI_SRC})
target_link_libraries(epi ${OpenCV_LIBS})

Go to File -> Settings -> Build, Execution, Deployment -> CMake. There you'll be able to more build configurations.

Related

How to Define Output Directory of Coverage Files in CMake

I am trying to make a very simple regression model that (among other things), builds and compiles a GCC target for coverage, executes, and then publishes a standard Cobertura coverage report (all within Jenkins). The Jenkins part is somewhat irrelevant here, I'm only concerned with CMake syntax at the moment. This is my CMake file so far:
cmake_minimum_required( VERSION 3.15 )
# Project's name
project( my_project )
# Set the output folder where your program will be created
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/test/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set( CMAKE_VERBOSE_MAKEFILE on )
# Generate coverage on GCC.
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(LDFLAGS "${LDFLAGS} -lgcov -fprofile-arcs")
endif()
# Includes and Sources
include_directories(${PROJECT_SOURCE_DIR}/inc)
file(GLOB APP_SRC "./src/*.c")
file(GLOB TEST_DEPENDS_SRC "./test/src/*.c")
# Add executable to list.
add_executable( ${PROJECT_NAME}_Test ${APP_SRC} ${TEST_DEPENDS_SRC} )
This generates my *.gcno and *.gcda files in the directory /test/build/gcc/CMakeFiles/my_project.dir/*, but for ease of post-processing, I think I want these files placed alongside their source. Is that possible? If so, how? Is that best practice? I'm still pretty green when it comes to CMake.

How to set up googletest on Windows with CLion

I have to use googletest on Windows with CLion for the first time, I tried to follow some guides, also from the official site of CLion, but I am not able to run googletest on my project.
My files are organised like in this image, the blue underlined CMakeLists.txt contains:
cmake_minimum_required(VERSION 3.6)
project(provaQT)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set (CMAKE_PREFIX_PATH "/Qt/5.7/mingw53_32/lib/cmake/Qt5Widgets")
set(CMAKE_AUTOMOC ON)
add_subdirectory(tests)
find_package(Qt5Widgets REQUIRED)
set(SOURCE_FILES main.cpp Subject.h Observer.h Resource.cpp Resource.h
MainWindow.cpp MainWindow.h tests/ResourceTests.cpp)
add_executable(provaQT main.cpp)
add_library(core ${SOURCE_FILES})
target_link_libraries(core Qt5::Widgets)
target_link_libraries(provaQT core)
The other CMakeLists.txt inside the folder "tests" contains:
cmake_minimum_required(VERSION 3.6)
add_subdirectory(./lib/googletest)
set(gtest_SOURCE_DIR ./lib/googletest/)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
set(TEST_SOURCE_FILES runAllTests.cpp Resourcetests.cpp)
add_executable(runAllTests ${TEST_SOURCE_FILES})
target_link_libraries(runAllTests gtest gtest_main core)
The I wrote a test in the file ResourceTests.cpp and when I build the Google Test configuration, I get these errors.
What is incorrenct?

Changing .ui file wouldn't regenerate ui_xxx.h using cmake 3.6

I have a simple setup with main.cpp, mainwindows.cpp, mainwindow.h, and mainwindow.ui with this cmake file :
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
project(test_qt_with_cmake)
set(CMAKE_CXX_STANDARD 11) # use c++11
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "C:/Qt/5.8/msvc2015_64")
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt5Widgets)
set(PROJECT_INCLUDE_DIR "${PROJECT_SOURCE_DIR}")
######## PROJECT DEPENDENCIES #########
if(WIN32)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${PROJECT_SOURCE_DIR}/windows)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
#=====================================
include_directories(
${PROJECT_INCLUDE_DIR}
)
add_executable(test_qt WIN32 main.cpp mainwindow.cpp mainwindow.h)
target_link_libraries(test_qt Qt5::Widgets)
add_custom_command(TARGET test_qt POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${PROJECT_SOURCE_DIR}/windows/bin"
$<TARGET_FILE_DIR:test_qt>)
The ui_xxx.h is generated the first time i build the project and regenerated if the .ui file and one of source file is changed. What i would like is to get the ui_xxx.h to get regenerated everytime .ui file is changed with or without source change.
I've taken a look at https://github.com/euler0/mini-cmake-qt but the example_automoc project is always out of date and vs always ask to rebuild the project.
Is there something wrong in my cmake file? or is it a bug in cmake?
note: i'm using qt 5.8 with cmake 3.6 on windows 10 using visual studio 14 2015 generator
update : removing set(CMAKE_AUTOUIC ON) and specifying the ui file with :
qt5_wrap_ui(UI_HEADERS mainwindow.ui)
seems to solve the problem. The original question is still valid, which is how to make this work without specifying the .ui file (by calling qt5_wrap_ui) ?

cmake ClanLib i can't compile project

cmake_minimum_required(VERSION 3.1)
project(ClanLib)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
SET(ClanLib_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${ClanLib_INCLUDE_DIRS})
FIND_PACKAGE(ClanLib REQUIRED)
set(SOURCE_FILES main.cpp)
add_executable(ClanLib ${SOURCE_FILES} main.cpp)
TARGET_LINK_LIBRARIES(ClanLib ${ClanLib_LIBRARY})
and cmake give error:
Error:By not providing "FindClanLib.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "ClanLib", but CMake did not find one.
Could not find a package configuration file provided by "ClanLib" with any of the following names:
ClanLibConfig.cmake clanlib-config.cmake
Add the installation prefix of "ClanLib" to CMAKE_PREFIX_PATH or set "ClanLib_DIR" to a directory containing one of the above files. If "ClanLib" provides a separate development package or SDK, be sure it has been installed.
There is no FindClanLib.cmake provided by ClanLib project or CMake, so find_package will not work in your case.
For Linux you can use pkg-config facility from CMake.
Here the example for ClanLib usage on Linux.

How to build package with cmake?

I want to build the package uci for ubuntu.
I download the source package and I found into the C files, header files and CMakeLists.txt
How to build the uci project with cmake?
CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
PROJECT(uci C)
SET(CMAKE_INSTALL_PREFIX /usr)
ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -I. -DUCI_PREFIX="${CMAKE_INSTALL_PREFIX}")
OPTION(UCI_PLUGIN_SUPPORT "plugin support" ON)
OPTION(UCI_DEBUG "debugging support" OFF)
OPTION(UCI_DEBUG_TYPECAST "typecast debugging support" OFF)
OPTION(BUILD_LUA "build Lua plugin" ON)
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/uci_config.h.in ${CMAKE_SOURCE_DIR}/uci_config.h )
SET(LIB_SOURCES libuci.c file.c util.c delta.c parse.c)
ADD_LIBRARY(uci-shared SHARED ${LIB_SOURCES})
SET_TARGET_PROPERTIES(uci-shared PROPERTIES OUTPUT_NAME uci)
TARGET_LINK_LIBRARIES(uci-shared dl)
ADD_LIBRARY(uci-static STATIC ${LIB_SOURCES})
SET_TARGET_PROPERTIES(uci-static PROPERTIES OUTPUT_NAME uci)
ADD_EXECUTABLE(cli cli.c)
SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME uci)
TARGET_LINK_LIBRARIES(cli uci-shared dl)
ADD_EXECUTABLE(cli-static cli.c)
SET_TARGET_PROPERTIES(cli-static PROPERTIES OUTPUT_NAME uci-static)
TARGET_LINK_LIBRARIES(cli-static uci-static dl)
ADD_LIBRARY(ucimap STATIC ucimap.c)
ADD_EXECUTABLE(ucimap-example ucimap-example.c)
TARGET_LINK_LIBRARIES(ucimap-example uci-static ucimap dl)
ADD_SUBDIRECTORY(lua)
INSTALL(FILES uci.h uci_config.h ucimap.h
DESTINATION include
)
INSTALL(TARGETS uci-shared uci-static cli cli-static
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
I don't know about this particular case, but the generic mode of operation with CMake is as follows. Let's assume you unpacked the package sources so that the CMakeList is located at /some/path/to/source/CMakeLists.txt. Then:
> cd /path/where/you/want/to/build
> mkdir package_name
> cd package_name
> cmake /some/path/to/source
Next, an optional step to launch (console) GUI to edit options, if necessary:
> ccmake
After you're happy with the setup:
> make
> make install
CMake also has a non-console GUI, but I've never used it on Unix, so I can't comment there. The basic idea would be the same, though: set up a build directory, point the GUI to the source directory (the one containing CMakeLists.txt), configure, modify uptions and reconfigure as necessary, generate Makefiles, exit GUI and run make.

Resources