CMake to build an ActiveX OCX?
I've been playing with CMake today, and so far it has been working great. Our project consists 开发者_如何转开发of +100 Visual Studio 2003 projects; we want to move to VS2008 and eventually VS2010 and also to support makefile build system (and maybe also Eclipse CDT)... so defining our projects with a CMake configuration files and generating project files and makefiles seems like a possible way to go.
However, we have a large number of OCXs, and I have not been able to find any examples of this. Does anyone know of a project building OCXs with CMake?
Thanks! - Josh
So, it took a while, but this is how I manage to create an activex project using cmake. However, I have to say I first had to create the activex project with visual studio in order to generate some files and then I transformed into a cmake project.
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(MyProject)
# Very useful if project has more than one target
SET(BIN_OUTPUT_DIR ${MyProject_BINARY_DIR}/bin)
SET(LIB_OUTPUT_DIR ${MyProject_BINARY_DIR}/lib)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIR})
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIR})
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB_OUTPUT_DIR})
ADD_DEFINITIONS("-DWIN32 -D_WINDOWS -D_USRDLL")
ADD_DEFINITIONS("-D_AFXDLL -D_UNICODE -DUNICODE -D_WINDLL")
# Not sure if all this compiler flags are needed, but they reflect the default
# parameter when creating an activex project
ADD_DEFINITIONS("/Oi /GL /Gy /Z7")
SET(CMAKE_SHARED_LINKER_FLAGS "/OPT:REF /OPT:ICF /MACHINE:X86 /SUBSYSTEM:WINDOWS /LTCG")
# I left this here just as an example it is not needed
FIND_PACKAGE(Boost)
SET(TargetName MyTarget)
FILE(GLOB mytarget_src *.cpp *.idl *.def)
FILE(GLOB mytarget_hdr *.hpp *.h)
FILE(GLOB mytarget_res *.rc *.bmp)
SOURCE_GROUP("Header Files" FILES ${mytarget_hdr})
SOURCE_GROUP("Resource Files" FILES ${mytarget_res})
# I tried to make this work, but I couldn't, so right now my project doesn't use pch's
#ADD_PRECOMPILED_HEADER(${TargetName} stdafx.h stdafx.cpp)
# The last directory is a hack, but it is needed, since the midl compiler outputs the
# tlb file there, which is later needed by the resource compiler
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/${TargetName}.dir/${CMAKE_CFG_INTDIR})
ADD_LIBRARY(${TargetName} SHARED ${mytarget_src} ${mytarget_hdr} ${mytarget_res})
TARGET_LINK_LIBRARIES(${TargetName}) # It is obvious what you put here
SET_TARGET_PROPERTIES(${TargetName} PROPERTIES SUFFIX ".ocx")
I don't know of any public projects with example code you can follow for this.
But OCXs are just DLLs with certain properties, and CMake is quite capable of building DLLs. This should be quite feasible. You should give it a try and post specific questions about any problems you run into along the way.
FireBreath creates ActiveX control DLLs using CMake. It's probably not really any different from how you'd create an OCX. It does use ATL.
Granted, FireBreath does a lot of other things as well, since it's a framework for building Browser Plugins, but you could look at the cmake structure and see what we're doing. The only "tricky" thing I had to solve was that cmake sometimes doesn't deal well with .idl files, so instead of adding the .idl files directly I created custom build steps to handle the midl call.
精彩评论