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.

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
tnas
  • 510
  • 5
  • 16
  • This is a Q& A site. What is your question? – Jens Gustedt Jun 19 '17 at 20:23
  • "I must translate a configuration like this into a CMakeList configuration". As can be seen in my post. – tnas Jun 19 '17 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. – too honest for this site Jun 19 '17 at 20:27
  • @tnas, this is an assignment, not a question. Why wouldn't solve assignments for you. – Jens Gustedt Jun 19 '17 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. – tnas Jun 19 '17 at 20:33
  • @tnas: What did your last comment state your question did not already? Repeating the know like a mantra is not really helpful. – too honest for this site Jun 19 '17 at 20:34
  • Let me try again: How to set a prefix compiler command in a CMakeList? – tnas Jun 19 '17 at 20:39

1 Answers1

-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()
tnas
  • 510
  • 5
  • 16