当代码过多时我们通过cmake 中的CMakeLists.txt的正确编写 cmake . 生成makefile文件 然后通过make 生成我们需要的可执行文件或者库
CMakeLists.txt 说明 cmakecmakeblog 关于cmake的详细资料可下载文档 cmake文档
//main.c
#include <stdio.h>
int main()
{
printf("hello cmake \n");
return 0;
}
#CMakeLists.txt
PROJECT (HELLO) # 定义工程名称
CMAKE_MINIMUM_REQUIRED(VERSION 2.8) # CMake 最低版本要求,低于2.6 构建过程会被终止。
SET(SRC_LIST main.c) # 使用set命令显式定义及赋值
SET(CMAKE_BUILE_TYPE DEBUG) # 指定编译类型,debug 或者为 release
# debug 版会生成相关调试信息,可以使用 GDB 进行
# release不会生成调试信息。当无法进行调试时查看此处是否设置为 debug.
MESSAGE(STATUS "This is BINARY dir " ${HELLO_BINARY_DIR}) # 打印相关消息消息
MESSAGE(STATUS "This is SOURCE dir "${HELLO_SOURCE_DIR})
ADD_EXECUTABLE(hello ${SRC_LIST}) #生成可执行文件 ADD_EXECUTABLE(hello main.c)
在含有CMakeLists.txt 跟main.c 的文件中运行cmake . make 两个命令会自动生成可执行文件
[d5000@D5000Client t2]$ cmake .
CMake Warning (dev) in CMakeLists.txt:
Syntax Warning in cmake code at
/home/d5000/work/Ptest/t2/CMakeLists.txt:11:37
Argument not separated from preceding token by whitespace.
This warning is for project developers. Use -Wno-dev to suppress it.
-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- This is BINARY dir /home/d5000/work/Ptest/t2
-- This is SOURCE dir /home/d5000/work/Ptest/t2
-- Configuring done
-- Generating done
-- Build files have been written to: /home/d5000/work/Ptest/t2
[d5000@D5000Client t2]$ make
Scanning dependencies of target hello
[100%] Building C object CMakeFiles/hello.dir/main.c.o
Linking C executable hello
[100%] Built target hello
[d5000@D5000Client t2]$ ./hello
hello cmake
下面是自己工作中用到的CMakeLists.txt 仅供参考
project(CacheEngine) #定义工程名称
cmake_minimum_required(VERSION 2.8) # CMake 最低版本要求,低于2.8 构建过程会被终止。
# 使用set命令显式定义及赋值 SET(SRC_LIST main.c),如果有多个源文件,也可以定义成:SET(SRC_LIST main.c t1.c t2.c)
#MESSAGE(STATUS|SEND_ERROR|FATAL_ERROR "AAAA")
#STATUS 输出信息类似printf
#SEND_ERROR 产生错误 生成过程终止
#FATAL_ERROR 立即终止所有cmake过程
set(CMAKE_C_COMPILER "/usr/bin/cc") # 指定 C 编译器
set(CMAKE_CXX_COMPILER "/usr/bin/c++") # 指定C++编译器
set(CMAKE_C_FLAGS "-fPIC") # 编译C文件时的选项 -fPIC动态库
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") # DEBUG版选项
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall") # RELEASE版选项
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) #支持IF(A) ELSE()的写法
if(CMAKE_BUILD_TYPE STREQUAL "Debug") #str equal
set(CMAKE_VERBOSE_MAKEFILE ON) #显示执行构建过程中详细的信息(比如为了得到更详细的出错信息)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()
execute_process( COMMAND pwd OUTPUT_VARIABLE CHKPATH
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../..)
string(STRIP ${CHKPATH} CHKPATH) #?
SET(CMAKE_INSTALL_PREFIX ${CHKPATH}) # 设置工作目录
add_definitions(-D_WORKPATH="${CMAKE_INSTALL_PREFIX}") #预定义宏,-D选项 _WORKPATH = /home/d5000/work/OnlineCheck
INCLUDE_DIRECTORIES(../CacheLibForNew ./) # 设置头文件的引用路径
LINK_DIRECTORIES(${CMAKE_INSTALL_PREFIX}/lib /usr/local/lib) #设置引用库路径 有标准库 有自己生成库
SET(CACHE_SRC cache/cachefactory.cpp
cache/branchgathertopomanager.cpp
cache/topomanager.cpp
cache/findbranchdata.cpp
cache/FindBranchTopoData.cpp
cache/GlobalVariable.cpp
cache/SaveCheckResult.cpp
cache/DataFunc.cpp
cache/CalculationResult.cpp
cache/cache_to_equipment.cpp
cache/cache_to_difference_check.cpp
cache/db_interaction.cpp
)
SET(CIMHELPER_SRC
CimHelper/UploadCimHelper.cpp
CimHelper/standardizationzoneequipment.cpp
CimHelper/physical_topology_renumbering.cpp
CimHelper/CimOperator/controlareaup.cpp
CimHelper/CimOperator/basevoltageup.cpp
CimHelper/CimOperator/substationup.cpp
CimHelper/CimOperator/busbarsectionup.cpp
CimHelper/CimOperator/breakerup.cpp
CimHelper/CimOperator/disconnectorup.cpp
CimHelper/CimOperator/synchronousmachineup.cpp
CimHelper/CimOperator/aclinesegmentup.cpp
CimHelper/CimOperator/dclinesegmentup.cpp
CimHelper/CimOperator/loadup.cpp
CimHelper/CimOperator/powertransformerup.cpp
CimHelper/CimOperator/seriescompensatorup.cpp
CimHelper/getonetimeequipmentfromxml.cpp
CimHelper/analyseonetimeequipment.cpp
CimHelper/protectioncheckparse.cpp
CimHelper/union_equi_value_table.cpp
CimHelper/tnodetopology.cpp
CimHelper/readupfile.cpp
CimHelper/getcorrespondencedata.cpp
CimHelper/createtnodelinedata.cpp
CimHelper/parameterdiffdatainfo.cpp
CimHelper/getlmxsdata.cpp
CimHelper/get_data_from_cime_gd.cpp
)
SET(ANALYSE_SRC
Analyse/smallest_unit_of_analysis.cpp
Analyse/init_equipment_count_of_station.cpp
Analyse/init_equipment_item_count.cpp
Analyse/global_static_variables.cpp
Analyse/init_equipment_setting_count_of_station.cpp
Analyse/analysis_result_in_range.cpp
Analyse/outputtofile.cpp
Analyse/analysemain.cpp
Analyse/get_lst_from_cache.cpp
Analyse/write_to_file_or_xml.cpp
Analyse/controlarea_substation_cime.cpp
Analyse/analyse_rule_check_value_curve.cpp
Analyse/DataClass.cpp
Analyse/monthreport_config.cpp
)
SET(CASE_SRC
Case/stationabutmentmanager.cpp
Case/getequipmentinputdbfrome.cpp
Case/RemoteData.cpp
Case/model_E.cpp
Case/CaseManage.cpp
Case/mispoint_datamanager.cpp
)
SET(DB_SRC DB/odbcdb.cpp
DB/odbcpool.cpp
DB/autoconndb.cpp
DB/dbentity.cpp
DB/batentity.cpp
DB/autostmt.cpp
DB/sqlparameter.cpp
DB/odsingleentity.cpp
)
SET(MODEL_SRC
DBModel/odbcbreak.cpp
DBModel/odbcbranningfactorbat.cpp
DBModel/odbcbus.cpp
DBModel/odbccapacitor.cpp
DBModel/odbcequalline.cpp
DBModel/odbcequalsource.cpp
DBModel/odbcline.cpp
DBModel/odbcmutualinductance.cpp
DBModel/odbcpowertransformer.cpp
DBModel/odbcreactance.cpp
DBModel/odbcsynchronousmachine.cpp
DBModel/odbctopologicalphysics.cpp
DBModel/odbcsubstation.cpp
DBModel/odbcstationrunway.cpp
DBModel/odbcrunway.cpp
DBModel/odbcbranchcollectiontopo.cpp
DBModel/odbcbasevoltage.cpp
DBModel/odbctnode.cpp
DBModel/odbcompanysinglepointequivalence.cpp
DBModel/odbcrunwaydes.cpp
)
SET(CONFIG_SRC
Config/CommonProperty.cpp
Config/system_config.cpp
Config/SystemSetting.cpp
)
SET(DBMIRROR_SRC DBMirror/dbmirror.cpp
DBMirror/dbequimentbase.cpp
DBMirror/dbbus.cpp
DBMirror/dbline.cpp
DBMirror/dbbreaker.cpp
DBMirror/dbcapacitor.cpp
DBMirror/dbequalline.cpp
DBMirror/dbequalsource.cpp
DBMirror/dbmutualinductance.cpp
DBMirror/dbpowertransformer.cpp
DBMirror/dbreactance.cpp
DBMirror/dbsynchronousmachine.cpp
DBMirror/dbboundarybus.cpp
DBMirror/dbsubstation.cpp
DBMirror/dbstationrunway.cpp
DBMirror/dbrunway.cpp
DBMirror/dbdevidedbranch.cpp
DBMirror/dbequivalentlinenew.cpp
DBMirror/dbcompanysinglepointequivalence.cpp
DBMirror/dbbranningfactor.cpp
DBMirror/dbbranchcollection.cpp
DBMirror/dbloopcalcmode.cpp
DBMirror/dbbranchcurrent.cpp
DBMirror/dbbreakermode.cpp
DBMirror/dbbranchcurrentextremum.cpp
DBMirror/dbload.cpp
DBMirror/dbarea.cpp
DBMirror/dbtopologicalphysics.cpp
DBMirror/Topo/breakerbusquery.cpp
DBMirror/Topo/branchbreakerbusquery.cpp
DBMirror/Topo/branchbreakerbusnewquery.cpp
DBMirror/Topo/topoquery.cpp
DBMirror/Topo/boundarybusbreakerquery.cpp
DBMirror/dbdcline.cpp
DBMirror/calcelementfilter.cpp
)
SET(MODEL_SRC
model/runwaydescription.cpp
model/breakermode.cpp
model/substation.cpp
model/equivalentline.cpp
model/basevoltage.cpp
model/line.cpp
model/powertransformer.cpp
model/synchronousmachine.cpp
model/tranequipmentsetting.cpp
model/onlinecheckresult.cpp
model/onlinecheckcalculationbook.cpp
model/lineequipmentsettings.cpp
model/busequipmentsettings.cpp
model/equivaluesource.cpp
model/protectioncheck.cpp
model/protectionitemcheck.cpp
model/protectionrulecheck.cpp
model/protectionvariablecheck.cpp
model/protectioncooperation.cpp
model/remoteacline.cpp
model/breaker.cpp
model/runway.cpp
model/topologicalphysics.cpp
model/bus.cpp
model/area.cpp
model/remoteunit.cpp
model/dzitem.cpp
model/user.cpp
model/onlinecheckparameter.cpp
model/roccountpercent.cpp
model/rocwholenetcurve.cpp
model/singleresult.cpp
model/equipmentsettingdz.cpp
model/load.cpp
model/reactance.cpp
model/capacitor.cpp
model/dcline.cpp
model/mutualinductance.cpp
model/remotesubstation.cpp
model/levelpercent.cpp
model/devidedbranch.cpp
model/rocwholenetcurveforstation.cpp
model/rocmaxwarninglevel.cpp
model/onlinechecksensitivity.cpp
model/curveview.cpp
model/resultpercent.cpp
model/stationalarmnum.cpp
model/percentofpass.cpp
model/stationpoint.cpp
model/roccheckmark.cpp
model/protectanalysestat.cpp
model/checkdissatisfy.cpp
model/parallelonlinechkpara.cpp
model/linemount.cpp
model/breakerstate.cpp
model/mispoint.cpp
model/devicecastback.cpp
model/remotebreaker.cpp
model/remotebus.cpp
model/remotetransformer.cpp
model/differencecheck.cpp
model/boundarybus.cpp
model/equivalentlinenew.cpp
model/role.cpp
model/differencecheckgroup.cpp
model/dclinedot.cpp
model/aclinedot.cpp
model/grounddisconnector.cpp
model/transformerwinding.cpp
model/seriescompensator.cpp
model/correspondence.cpp
model/protectionscope.cpp
model/tableparameter.cpp
model/devicebase.cpp
model/partpercent.cpp
model/percent.cpp
model/warningmessage.cpp
model/checkresultmessage.cpp
model/equipinfo.cpp
model/equiplistinfo.cpp
model/e8003warninginfo.cpp
model/tnode.cpp
model/branchgathertopo.cpp
model/equsetting.cpp
model/equipmentsettingitems.cpp
model/stationabutment.cpp
model/checkrecord.cpp
model/rocdis3curve.cpp
model/valueplan.cpp
model/valueplandescription.cpp
model/borderdata.cpp
)
SET(CIMUNIT_SRC
cimunit/basevoltagecimunit.cpp
cimunit/controlareacimunit.cpp
cimunit/substationcimunit.cpp
cimunit/busbarsectioncimunit.cpp
cimunit/breakercimunit.cpp
cimunit/disconnectorcimunit.cpp
cimunit/synchronousmachinecimunit.cpp
cimunit/dclinedotcimunit.cpp
cimunit/aclinedotcimunit.cpp
cimunit/dclinesegmentcimunit.cpp
cimunit/aclinesegmentcimunit.cpp
cimunit/loadcimunit.cpp
cimunit/grounddisconnectorcimunit.cpp
cimunit/transformerwindingcimunit.cpp
cimunit/powertransformercimunit.cpp
cimunit/seriescompensatorcimunit.cpp
cimunit/onlyonecimunit.cpp
cimunit/correspondencecimunit.cpp
cimunit/equipmentsettingdzcimunit.cpp
cimunit/cachebreakercimunit.cpp
cimunit/cachepowertransformercimunit.cpp
cimunit/equivalentlinecimunit.cpp
cimunit/equivalentsourcecimunit.cpp
cimunit/mutualinductancecimunit.cpp
cimunit/runwaycimunit.cpp
cimunit/topologicalphysicscimunit.cpp
cimunit/differencecheckcimunit.cpp
cimunit/breakermodecimunit.cpp
cimunit/protectioncheckcimunit.cpp
cimunit/protectionitemcheckcimunit.cpp
cimunit/protectionrulecheckcimunit.cpp
cimunit/protectionvariablecheckcimunit.cpp
cimunit/cimaddlinecimunit.cpp
cimunit/cimaddpowertransformercimunit.cpp
cimunit/cimaddsynchronousmachinecimunit.cpp
cimunit/equsettingcimunit.cpp
cimunit/equipmentsettingitemscimunit.cpp
cimunit/stationabutmentcimunit.cpp
cimunit/subcontrolareacimunit.cpp
cimunit/mispointcimunit.cpp
cimunit/zdsubstationcimunit.cpp
cimunit/calculationbookcimunit.cpp
cimunit/equipinputcimunit.cpp
cimunit/borderdatacimunit.cpp
)
SET(ADJUST_SRC
Adjust/getEquipmentSettingXMLInfo.cpp
Adjust/equipmentsettinginfo.cpp
)
SET(COMM_SRC Common/calcexception.cpp
Common/zini.cpp
Common/commfunc.cpp
Common/debugfile.cpp
Common/codeconvert.cpp
Common/zini.cpp
Common/Formula.cpp
Common/stack.cpp
Common/opera.cpp
Common/dirfunc.cpp
Common/valueplandata.cpp
Common/complexoperator.cpp
Common/EReadTool.cpp
Common/CacheValue.cpp
)
SET(BASIC_SRC
Basic/eleimpedance.cpp
Basic/elebus.cpp
Basic/branchcollection.cpp
Basic/branchcurrentextremum.cpp
Basic/busimpedance.cpp
Basic/branningfactor.cpp
Basic/tempequipment.cpp
Basic/calcconfig.cpp
Basic/branchcollectiontopo.cpp
Basic/calcres.cpp
Basic/EquipmentCheck.cpp
Basic/branchcurrent.cpp
Basic/faultplaceinformation.cpp
Basic/nodevoltage.cpp
Basic/NeighbourBranchTypeArray.cpp
Basic/element.cpp
Basic/EleImpeArray.cpp
Basic/CStruct.cpp
Basic/NodeImpedance.cpp
Basic/neighbourbranch.cpp
Basic/equivalentlinenew.cpp
Basic/dz_info.cpp
Basic/cele_impedance.cpp
Basic/BusInfoConsiderFlow.cpp
Basic/branchcollectiontopo.cpp
Basic/branchcollection.cpp
Basic/boundarybus.cpp
Basic/equipment_setting.cpp
Basic/complexangle.cpp
Basic/Ele_BusArray.cpp
Basic/TranEquipmentSettingItems.cpp
Basic/TranEquipmentSetting.cpp
Basic/LineEquipmentSettingItems.cpp
Basic/LineEquipmentSetting.cpp
Basic/BusEquipmentSettingItems.cpp
Basic/BusEquipmentSetting.cpp
Basic/online_check_result_struct.cpp
Basic/rulecheckvalue_curve_io.cpp#外面用
Basic/datedistance3_line_remotetelemetry.cpp#外面用
)
SET(WEBSERVICE
WebService/ClientMain.cpp
WebService/stub/soapC.cpp
WebService/stub/soapClient.cpp
WebService/stub/stdsoap2.cpp
)
if(_DATA_ODBC)
ADD_LIBRARY(CacheEngine SHARED
${DB_SRC}
${MODEL_SRC}
${CIMUNIT_SRC}
${CACHE_SRC}
${ANALYSE_SRC}
${DBMIRROR_SRC}
${CASE_SRC}
${CIMHELPER_SRC}
${ANALYSE_SRC}
${CONFIG_SRC}
${COMM_SRC}
${WEBSERVICE}
)
else()
ADD_LIBRARY(CacheEngine SHARED
${ADJUST_SRC}
${MODEL_SRC}
${BASIC_SRC}
${CIMUNIT_SRC}
${CACHE_SRC}
${ANALYSE_SRC}
${DBMIRROR_SRC}
${CASE_SRC}
${CIMHELPER_SRC}
${ANALYS_SRC}
${CONFIG_SRC}
${COMM_SRC}
${WEBSERVICE}
)
endif()
SET_TARGET_PROPERTIES(CacheEngine PROPERTIES VERSION 1.0 SOVERSION 1)
TARGET_LINK_LIBRARIES(CacheEngine DatAccess boost_thread boost_system log4cpp boost_regex) # 生成目标所需要的库
SET_TARGET_PROPERTIES(CacheEngine PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../../lib) # 指定 lib 文件目录
#通过 SET 来定义变量 一般情况下通过 ${CIMMAIN_SRC} 来引用变量 但是在IF()中是直接用变量CIMMAIN_SRC
SET(CIMMAIN_SRC CimHelper/cimhelpermain.cpp)
ADD_EXECUTABLE(cime_helper ${CIMMAIN_SRC}) # 生成可执行文件 ADD_EXECUTABLE(cime_helper ${CIMMAIN_SRC})
#定义了这个工程会生成一个文件名为 cime_helper 的可执行文件,相关的源文件是 CIMMAIN_SRC 中
#定义的源文件列表, 本例中你也可以直接写成ADD_EXECUTABLE(hello main.c)。
TARGET_LINK_LIBRARIES(cime_helper CacheEngine DatAccess boost_thread log4cpp ${PROJECT_NAME} boost_timer) # 设置目标要连接库文件的名称
SET_TARGET_PROPERTIES(cime_helper PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../bin) # 指定目标文件目录
SET(CHECKRESULT_SRC Analyse/checkresultmain.cpp)
ADD_EXECUTABLE(result_analysing ${CHECKRESULT_SRC}) # 生成可执行文件
TARGET_LINK_LIBRARIES(result_analysing CacheEngine DatAccess boost_thread log4cpp ${PROJECT_NAME} boost_timer) # 设置目标要连接库文件的名称
SET_TARGET_PROPERTIES(result_analysing PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../bin) # 指定目标文件目录
SET(REMOTEDATA_SRC Case/remotedatamain.cpp)
ADD_EXECUTABLE(RemoteData ${REMOTEDATA_SRC}) # 生成可执行文件
TARGET_LINK_LIBRARIES(RemoteData CacheEngine DatAccess boost_thread log4cpp boost_timer)# 设置目标要连接库文件的名称
SET_TARGET_PROPERTIES(RemoteData PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../bin) # 指定目标文件目录
SET(PARADIFF_SRC CimHelper/paradiff.cpp)
ADD_EXECUTABLE(paraup ${PARADIFF_SRC}) # 生成可执行文件
TARGET_LINK_LIBRARIES(paraup CacheEngine DatAccess boost_thread log4cpp boost_timer)# 设置目标要连接库文件的名称
SET_TARGET_PROPERTIES(paraup PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../bin) # 指定目标文件目录
#清理緩存
SET(CLEANNODE_SRC CimHelper/cleannodemain.cpp)
ADD_EXECUTABLE(cleanNode ${CLEANNODE_SRC})
TARGET_LINK_LIBRARIES(cleanNode CacheEngine DatAccess boost_thread log4cpp boost_timer)
SET_TARGET_PROPERTIES(cleanNode PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../bin)
project(CacheLib)
cmake_minimum_required(VERSION 2.8)
#set(CMAKE_VERBOSE_MAKEFILE ON)
#set(CMAKE_CXX_COMPILER "g++")
#set(CMAKE_C_COMPILER gcc)
set(CMAKE_C_COMPILER "/usr/bin/cc")
set(CMAKE_CXX_COMPILER "/usr/bin/c++")
set(CMAKE_C_FLAGS "-fPIC")
#SET(CMAKE_BUILD_TYPE "Release")
#SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -pg -g -ggdb")
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
#set(CMAKE_LD_FLAGS "-pg")
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
#add_definitions(-D_DEBUG)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()
execute_process( COMMAND pwd
OUTPUT_VARIABLE CHKPATH
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../..)
string(STRIP ${CHKPATH} CHKPATH)
SET(CMAKE_INSTALL_PREFIX ${CHKPATH})
add_definitions(-D_LL="${CMAKE_INSTALL_PREFIX}")
INCLUDE_DIRECTORIES(./redis ./model ./serial ./rapidjson ./)
LINK_DIRECTORIES(/usr/local/lib)
SET(DATAACCESS_SRC redis/sds.c
redis/redis.c
redis/net.c
redis/dict.c
redis/async.c
Json/json_writer.cpp
Json/json_value.cpp
Json/json_reader.cpp
DataAccess/jsonstandardcache.cpp
DataAccess/cachebase.cpp
DataAccess/stringbunch.cpp
)
SET(BK_SRC backup/cachebackup.cpp
backup/cachemapnormal.cpp
backup/cache2mapnormal.cpp
backup/cache3mapnormal.cpp
)
SET(CIM_SRC cim/cimmanager.cpp
cim/cimunit.cpp
cim/cimunitlist.cpp
cim/normalcimunit.cpp
cim/onlyonecimunit.cpp
)
SET(CACHE_SRC
cache/cacheserver.cpp
cache/cachemanager.cpp
cache/cachemanagerobj.cpp
cache/cachemanager3map.cpp
cache/cachemanager2map.cpp
cache/autoconncache.cpp
cache/cachemanagervector2d.cpp
cache/maptree.cpp
cache/cachepulish.cpp
)
SET(COMM_SRC comm/norexception.cpp
comm/cachequeue.cpp
comm/define.cpp
comm/paratwo.cpp
comm/datetime.cpp
comm/vector2d.h
comm/reflexclass.h
comm/zini.cpp
)
SET(SERIAL_SRC serial/jsoniarchive.cpp
serial/jsonoarchive.cpp
serial/jsonserial.cpp
serial/jsoncontext.cpp
serial/jsonobj.cpp
serial/typeforjsonconvertor.cpp
)
SET(TESTCACHE_SRC cachemain.cpp
)
SET(TESTCIM_SRC cimmain.cpp
)
SET(TESTJSON_SRC jsonmain.cpp
)
SET(TESTODBC_SRC odbcmain.cpp
)
FIND_PATH(ODBC_INCLUDE_DIR NAMES sql.h PATHS
/usr/include
/usr/local/include
/usr/local/unixODBC/include
)
FIND_LIBRARY(ODBC_LIBRARY NAMES odbc PATHS
/usr/lib
/usr/local/lib
/usr/local/unixODBC/lib
)
if(ODBC_INCLUDE_DIR AND ODBC_LIBRARY)
SET(ODBC_FOUND TRUE)
endif(ODBC_INCLUDE_DIR AND ODBC_LIBRARY)
SET(DATAACCESS_SRC ${DATAACCESS_SRC} ${COMM_SRC} ${SERIAL_SRC} ${CIM_SRC} ${BK_SRC} ${CACHE_SRC})
SET(DATAACCESS_LIB boost_regex)
if(ODBC_FOUND)
INCLUDE_DIRECTORIES(${ODBC_INCLUDE_DIR})
#MESSAGE("db include:${ODBC_INCLUDE_DIR},db lib:${ODBC_LIBRARY_DIR}")
SET(DATAACCESS_SRC ${DATAACCESS_SRC} DB/odbcdb.cpp
DB/odbcpool.cpp
DB/autoconndb.cpp
DB/dbentity.cpp
DB/batentity.cpp
DB/autostmt.cpp
DB/sqlparameter.cpp
DB/odsingleentity.cpp
)
SET(DATAACCESS_LIB ${DATAACCESS_LIB} ${ODBC_LIBRARY})
endif(ODBC_FOUND)
ADD_LIBRARY(DatAccess SHARED ${DATAACCESS_SRC})
TARGET_LINK_LIBRARIES(DatAccess ${DATAACCESS_LIB})
SET_TARGET_PROPERTIES(DatAccess PROPERTIES VERSION 2.0 SOVERSION 2)
SET_TARGET_PROPERTIES(DatAccess PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../../lib)
ADD_EXECUTABLE(CimTest ${TESTCIM_SRC})
TARGET_LINK_LIBRARIES(CimTest DatAccess boost_thread boost_system log4cpp)
SET_TARGET_PROPERTIES(CimTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../bin)
ADD_EXECUTABLE(CacheTest ${TESTCACHE_SRC})
TARGET_LINK_LIBRARIES(CacheTest DatAccess boost_thread boost_system log4cpp)
SET_TARGET_PROPERTIES(CacheTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../bin)
if(ODBC_FOUND)
ADD_EXECUTABLE(OdbcTest ${TESTODBC_SRC})
TARGET_LINK_LIBRARIES(OdbcTest DatAccess boost_thread boost_system log4cpp)
SET_TARGET_PROPERTIES(OdbcTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../bin)
endif(ODBC_FOUND)
ADD_EXECUTABLE(JsonTest ${TESTJSON_SRC})
TARGET_LINK_LIBRARIES(JsonTest DatAccess boost_thread boost_system log4cpp)
SET_TARGET_PROPERTIES(JsonTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../bin)
INSTALL(TARGETS DatAccess LIBRARY DESTINATION lib)