0

I need to profile a C/C++ program. I'm using cmake, and all my compile configurations are set up in a CMakeList. In this post, there is an ugly way to do this. There is another solution here, but it did not work in my case. So, as explained here, I must translate a configuration like this

export CC="skin icc"
export CXX="skin icpc"
....
make

or

make CC="skin icc" CXX="skin icpc"....

into a CMakeList configuration. In my current CMakeList, I have not set up the compilers. Only flags are defined

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fopenmp -o3")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fopenmp -o3")

Any help would be very welcome. Thanks.

7
  • This is a Q& A site. What is your question? Commented Jun 19, 2017 at 20:23
  • "I must translate a configuration like this <code> into a CMakeList configuration". As can be seen in my post. Commented Jun 19, 2017 at 20:24
  • 1) There is no language C/C++ 2) This is not about any of the two different languages C or C++. CMake is not related to any of them. 3) What is your specific question? We are not a "do my job/hjomework/assignment/…" site. Commented Jun 19, 2017 at 20:27
  • @tnas, this is an assignment, not a question. Why wouldn't solve assignments for you. Commented Jun 19, 2017 at 20:27
  • Ok. I'm going to correct the post. But, my problem is: I have a C/C++ project and I'm using CMake for compile it. But I need to profile this code. I don't know how to add the profile command in the CMakeList. Commented Jun 19, 2017 at 20:33

1 Answer 1

-1

This is what has solved in this case. After setting the project name, I've added this snippet of script:

set(PROFILER_ENABLED ON)

set(SCOREP_PROFILER "scorep")
set(COMPILER_FLAGS "-Wall -fopenmp -o3")
set(CXX_COMPILER_FLAGS "g++ ${COMPILER_FLAGS}")
set(C_COMPILER_FLAGS "gcc ${COMPILER_FLAGS}")

if(PROFILER_ENABLED)
    foreach(LANG C CXX)
        message(STATUS "Enabling scorep for ${LANG}")
        set(CMAKE_${LANG}_COMPILER "${SCOREP_PROFILER}")
        set(CMAKE_${LANG}_FLAGS "${${LANG}_COMPILER_FLAGS}")
    endforeach()
else()
    message(STATUS "Default compilers")
    foreach(LANG C CXX)
        set(CMAKE_${LANG}_FLAGS "${COMPILER_FLAGS}")
    endforeach()
endif()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.